Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggers not working with IndexedDB #1409

Closed
jiron12 opened this issue Dec 14, 2021 · 3 comments
Closed

Triggers not working with IndexedDB #1409

jiron12 opened this issue Dec 14, 2021 · 3 comments

Comments

@jiron12
Copy link

jiron12 commented Dec 14, 2021

On an IndexDB table triggers are not firing.

Code example:

    alasql.fn.onInsert = function (r) {
        console.log('this never happens!');
    };

    await alasql.promise(`CREATE INDEXEDDB DATABASE IF NOT EXISTS test_db`);
    await alasql.promise(`ATTACH INDEXEDDB DATABASE test_db; USE test_db;`);

    await alasql.promise(`DROP TABLE IF EXISTS asset7`);
    await alasql.promise(`CREATE TABLE asset7([id] varchar(36) NOT NULL,  [name] varchar(45) NOT NULL, PRIMARY KEY ([id]) );`)

    var data = [
        { id: crypto.randomUUID(), name: "test1", amount: 7 },
        { id: crypto.randomUUID(), name: "test2", amount: 8 },
        { id: crypto.randomUUID(), name: "test3", amount: 9 }
    ];
    await alasql.promise(`INSERT INTO asset7 SELECT * FROM ?`, [data])

    await alasql.promise(`CREATE TRIGGER mytrigger after INSERT ON asset7 onInsert`)

    var data2 = [
        { id: crypto.randomUUID(), name: "test17", amount: 17 }
    ];
    await alasql.promise(`INSERT INTO asset7 SELECT * FROM ?`, [data2]);
@Julias0
Copy link
Contributor

Julias0 commented Jun 20, 2023

@mathiasrw can you assign this to me

@Julias0
Copy link
Contributor

Julias0 commented Jun 29, 2023

This is part of a more widescale issue, because inside 60createtable.js,

if (db.engineid) {
		return alasql.engines[db.engineid].createTable(
			this.table.databaseid || databaseid,
			tableid,
			this.ifnotexists,
			cb
		);
	}

Is present which means the rest of the parts for table.insert, table.delete etc never get executed.
I tried moving this block below the declarations but it led to a large number of unit tests breaking.

My current assumption is that it would be safe to say that triggers is not working for extensions like indexdb, sqlite etc rn.

I have added support to fix the issue mentioned above. Let me know if I am going in the right direction

mathiasrw pushed a commit that referenced this issue Jul 2, 2023
@mathiasrw
Copy link
Member

Fix released as part of v4.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants