Michael W. Czechowski
Michael W. Czechowski

Reputation: 3457

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?

Upvotes: 0

Views: 916

Answers (2)

LuizAsFight
LuizAsFight

Reputation: 242

Type of data is gonna be an array of 8-bit unsigned integer.

If you're not familiar with it, this link explains well http://ctp.mkprog.com/en/ctp/unsigned_8bit_integer/

"8-bit unsigned integer type is used to store only pozitiv whole number. 8-bit unsigned integer and his value range: from 0 to 255."

Upvotes: 1

Amadan
Amadan

Reputation: 198314

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...).

Upvotes: 2

Related Questions