only-cliches / Nano-SQL

Universal database layer for the client, server & mobile devices. It's like Lego for databases.
https://nanosql.io
MIT License
781 stars 49 forks source link

Can't query tables after restart, log parsing error #216

Open csuwildcat opened 3 years ago

csuwildcat commented 3 years ago

Which version are you using? version 2.3.7

Describe the bug When using a freshly created DB, everything seems to work, but as soon as I kill node with Ctrl + C and restart the server, all queries for fetching data from tables results in the following error:

C:\repos\identity-hub\packages\implementation\node_modules\snap-db\bin\database.js:699

    throw new Error("Error parsing log file!");
    ^

Error: Error parsing log file!
    at processLog_1 (C:\repos\identity-hub\packages\implementation\node_modules\snap-db\bin\database.js:699:31)
    at ReadStream.<anonymous> (C:\repos\identity-hub\packages\implementation\node_modules\snap-db\bin\database.js:755:21)

Expected behavior Queries against established tables with data that previously was present and queriable should remain so.

Example I can get a copy of the repo up soon, but here are the relevant code sections: export default class Storage {


export default class Storage {

  constructor(did, options = {}){
    this.did = did;
    this.dbName = did.split(':').slice(0, 3).join('-');
    this.ready = nano().createDatabase({
      id: this.dbName,
      mode: 'PERM',
      tables: this.tables = [
        {
          name: 'stack',
          model: {
            "id:string": { pk: true, immutable: true },
            "file:string": { immutable: true }
          }
        },
        {
          name: 'profile',
          model: {
            "id:string": { pk: true, immutable: true },
            "data:object": {},
            "signature:object": {}
          }
        },
        {
          name: 'permissions',
          model: {
            "id:string": { pk: true, immutable: true },
            "schema:string": { immutable: true, notNull: true },
            "data:object": { immutable: true },
            "signature:object": {}
          },
          indexes: {
            "schema:string": { ignore_case: true }
          }
        },
        {
          name: 'collections',
          model: {
            "id:string": { pk: true, immutable: true },
            "type:string": { immutable: true },
            "nonce:string": { immutable: true },
            "schema:string": { immutable: true, notNull: true },
            "root:string": { immutable: true },
            "parent:string": { immutable: true },
            "tags:array": {},
            "data:object": { immutable: true },
            "signature:object": {}
          },
          indexes: {
            "schema:string": { ignore_case: true }
          }
        },
        {
          name: 'actions',
          model: {
            "id:string": { pk: true, immutable: true },
            "nonce:string": { immutable: true },
            "schema:string": { immutable: true, notNull: true },
            "root:string": { immutable: true },
            "parent:string": { immutable: true },
            "data:object": { immutable: true },
            "signature:object": { immutable: true }
          },
          indexes: {
            "schema:string": {ignore_case: true}
          }
        }
      ]
    })  
  }

  async txn(fn){
    return this.ready.then(async () => {
      await nano().useDatabase(this.dbName);
      return fn(nano);
    });
  }

}

ClassInstance.txn(db => db('collections').query('select').exec()).catch(e => console.log(e));

//  ^ this call fails
csuwildcat commented 3 years ago

Interestingly, when I remove the indexes the DB seems to function normally. I don't understand why that is, perhaps I am using the indexes feature incorrectly?