2

I'm trying to migrate my js code into typescript. One of the libs I use is sql.js. Successfully installed corresponding typing for it, but am blocked with creation of the database.

How it was in JS:

  var db = new SQL.Database();
  db.run('CREATE TABLE snapshots (dateTime LONGINT, snapshot BLOB)');

There is no parameterless constructor in sql.js/index.d.ts file:

class Database {
    constructor(data: Buffer);
    constructor(data: Uint8Array);
    constructor(data: number[]);

    run(sql: string): Database;
    ...
}

How to instanciate empty db object? What are these parameters in constructor overrides used for?

Ulad Melekh
  • 924
  • 3
  • 17
  • 33
  • 1
    Fixed. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8c6386ebf41ab6f7f6ce40f1456325ee036b55b9/sql.js/sql.js.d.ts – zakki Sep 07 '16 at 02:27
  • also played with it here: https://github.com/projectje/sqljs-wrapper-cogmios – edelwater Aug 07 '20 at 17:29

1 Answers1

1

No sure, why there is no constructor() in Database class of sql.js typing, but this way works fine for me:

    var buffer: Buffer;
    var db = new sql.Database(buffer);
    db.run("CREATE TABLE snapshots (dateTime LONGINT, snapshot BLOB)");

Although buffer variable is not defined, db object is instanciated.

Ulad Melekh
  • 924
  • 3
  • 17
  • 33