Search code examples
javascripttypescripttypeormuint8array

What is a possible value for a Uint8Array typed variable in TypeScript?


What are possible values if a variable inside an interface is typed as Uint8Array?

typeorm/src/driver/sqljs/SqljsConnectionOptions.ts https://github.com/typeorm/typeorm/blob/master/src/driver/sqljs/SqljsConnectionOptions.ts

/**
 * Sql.js-specific connection options.
 */
export interface SqljsConnectionOptions extends BaseConnectionOptions {

    /**
     * A Uint8Array that gets imported when the connection is opened.
     */
    readonly database?: Uint8Array;
}

If already read MDN's article on Uint8Array, but it did not help.

EDIT: As you can see, there is a database name required. Intuitivly I would past in the name of my database, but this is a string. So how does a database in Uint8Array format look like?


Solution

  • It is not a database name. It is a database. Reading up on what sql.js is will show you it is SQLite compiled into JavaScript through Emscripten, with an in-memory store. By default, it gives you a blank database, which will get forgotten when you stop using it; but you have an option of importing it from, or exporting it to, an Uint8Array, which is literally the byte-by-byte contents of your SQLite database file. Look at sql.js readme to see many examples of how to get the database array (from upload, from XHR, from Node.js reading of a file...).