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

feat: add database and table types for TypeScript #1855

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions types/alasql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,62 @@ declare module 'alasql' {
[x: string]: userFromFunction;
}

/**
* AlaSQL database object. This is a lightweight implimentation
*
* @interface database
*/
interface database {
/**
* The database ID.
*
* @type {string}
* @memberof database
*/
databaseid: string;

/**
* The collection of tables in the database.
*
* @type {tableLookUp}
* @memberof database
*/
tables: tableLookUp;
}

/**
* AlaSQL table object. This is a lightweight implimentation
*
* @interface table
*/
interface table {
/**
* The array of data stored in the table which can be queried
*
* @type {any[]}
* @memberof table
*/
data: any[];
}

/**
* AlaSQL database dictionary
*
* @interface databaseLookUp
*/
interface databaseLookUp {
[databaseName: string]: database;
}

/**
* AlaSQL table dictionary
*
* @interface tableLookUp
*/
interface tableLookUp {
[tableName: string]: table;
}

interface AlaSQL {
options: AlaSQLOptions;
error: Error;
Expand All @@ -94,6 +150,43 @@ declare module 'alasql' {
autoval(tablename: string, colname: string, getNext?: boolean): number;
yy: {};
setXLSX(xlsxlib: typeof xlsx): void;

/**
* Array of databases in the AlaSQL object.
*
* @type {databaseLookUp}
* @memberof AlaSQL
*/
databases: databaseLookUp;

/**
* Equivalent to alasql('USE '+databaseid). This will change the current
* database to the one specified. This will update the useid property and
* the tables property.
*
* @param {string} databaseid
* @memberof AlaSQL
*/
use (databaseid: string): void;

/**
* The current database ID. If no database is selected, this is the
* default database ID (called alasql).
*
* @type {string}
* @memberof AlaSQL
*/
useid: string;

/**
* Array of the tables in the default database (called alasql). If
* the database is changes via a USE statement or the use method, this
* becomes the tables in the new database.
*
* @type {tableLookUp}
* @memberof AlaSQL
*/
tables: tableLookUp;
}

const alasql: AlaSQL;
Expand Down
Loading