dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

After 2.0.0 i get a lot of async tick Problems and can't really connect to a file. #59

Closed sayore closed 4 years ago

sayore commented 4 years ago
    createTable(name: string, fields: Array<IField>): Promise<void> {
        return new Promise((resolve, reject) => {
            this.dbcon = new DB(Deno.cwd() + this.path);
...
            var result = this.dbcon.query("CREATE TABLE IF NOT EXISTS " + name + "(" + tblstrings.join(",") + ")", []);

            result.done();
            this.dbcon.close();
            resolve();
        });
    }

This should create a file and table but it seems like it does nothing at all. It also seems that after i resolve this it gives me these kind of errors:

AssertionError: Test case is leaking async ops.

So if i do any work after calling this query to the database which seems to fail and not generate a file, there seems to be some async call in the background that stops the further execution one Promise layer above. Path and Query are the same as i used in 1.0.0.

There is also a code for checking if the table exists too to not create the table twice right before too but i think it's pretty much the same error source; an async leak:

checkTableExists(tablename: string): Promise<void> {
        return new Promise((resolve, reject) => {
            this.dbcon = new DB(Deno.cwd() + this.path);

            var sql =/*sql*/`SELECT name FROM sqlite_master WHERE type='table' AND name='${tablename}';`

            var rows = this.dbcon?.query(sql, []);
            var resolved = false;

            if (!!rows)
                for (const values of rows) { if (values && tablename == values[0]) { resolve(); resolved=true; } }

            rows.done();
            this.dbcon.close();

            if(!resolved)
                reject();
        });
    }

Using Deno 1.0.3, MacOS 10.15.4

sayore commented 4 years ago

Seems to be a problem with fetch and not this libary.