Skip to content

Give every storage engine one storage interface that saves the whole table definition and writes through the pipeline #2681

Open

Description

@mathiasrw

What happens today

After #2716 to #2662 memory tables check their rules in one write pipeline. Tables in a storage engine still take their own path. With autocommit on, yy.Insert.compile (src/statements/insert.js) hands the rows to alasql.engines[engineid].intoTable, which appends them (LS.intoTable in src/storage/localstorage.js, FS.intoTable in src/storage/filestorage.js, IDB.intoTable in src/storage/indexeddb.js). Only identity and DEFAULT are applied.

Each engine saves its own list of table fields (LS.storeTable, FS.createTable, FS.commit), so keys, checks and foreign keys are lost when a table is saved and read again.

On FILESTORAGE, after CREATE TABLE t (id INT PRIMARY KEY, n INT DEFAULT 7, CHECK (id > 0)), inserting 1, 1 and -5 stores all three rows.

What to change

  1. One storage interface. The memory table and each engine implement it.

    interface Storage {
      load(table);                 // rows and definition
      insert(table, rows);
      update(table, changes);
      delete(table, rows);
      truncate(table);
      saveSchema(table, schema);   // the whole definition from #3169
    }
  2. The write pipeline of Pass the rows of INSERT, UPDATE and DELETE through one write pipeline #2650 ends in storage.insert, storage.update or storage.delete for every table. Remove the engine branches in src/statements/insert.js, src/statements/update.js and src/statements/delete.js.

  3. saveSchema stores the definition object as it is, and load restores it. Remove the field lists in LS.storeTable, FS.createTable and FS.commit.

  4. A table saved by 4.x has no stored definition beyond its old fields. load reads it as before and fills in the rest as empty.

The interface with localStorage can be one pull request, then FILESTORAGE, then IndexedDB.

What stays the same

  • Memory tables.
  • An engine table without keys, checks or foreign keys stores the same rows.
  • An engine table with them now rejects the rows a memory table rejects, with the same error texts.

Done when

  • A new test file named after this issue runs the same script against a memory table, localStorage (with the DOMStorage shim that test150.js uses) and FILESTORAGE. A duplicate primary key, a duplicate UNIQUE value, a failing CHECK and a missing foreign key parent each give the same error on all three, and a table saved and loaded again keeps its keys and checks.
  • A table file written by 4.x loads.
  • The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.

Fixes

Fixes #566, #1148, #1846, #323.

Depends on

#2716, #3169, #2650, #2662

Activity

  1. added this to the v5.0.0 milestone on Nov 9, 2026
  2. changed the title [-]Review #2340 for code improvements: storage engine inserts skip the table's rules[/-] [+]Give every storage engine one storage interface that saves the whole table definition and writes through the pipeline[/+] on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions