@nymphjs/driver-sqlite3
Version:
Nymph.js - SQLite3 DB Driver
149 lines (148 loc) • 5.56 kB
TypeScript
import SQLite3 from 'better-sqlite3';
import { NymphDriver, type EntityConstructor, type EntityObjectType, type EntityInterface, type EntityInstanceType, type SerializedEntityData, type FormattedSelector, type Options, type Selector } from '@nymphjs/nymph';
import { SQLite3DriverConfig } from './conf/index.js';
declare class InternalStore {
link: SQLite3.Database;
linkWrite?: SQLite3.Database;
connected: boolean;
transactionsStarted: number;
constructor(link: SQLite3.Database);
}
/**
* The SQLite3 Nymph database driver.
*/
export default class SQLite3Driver extends NymphDriver {
config: SQLite3DriverConfig;
protected prefix: string;
protected store: InternalStore;
static escape(input: string): string;
static escapeValue(input: string): string;
constructor(config: Partial<SQLite3DriverConfig>, store?: InternalStore);
/**
* This is used internally by Nymph. Don't call it yourself.
*
* @returns A clone of this instance.
*/
clone(): SQLite3Driver;
/**
* Connect to the SQLite3 database.
*
* @returns Whether this instance is connected to a SQLite3 database.
*/
connect(): Promise<boolean>;
private _connect;
/**
* Disconnect from the SQLite3 database.
*
* @returns Whether this instance is connected to a SQLite3 database.
*/
disconnect(): Promise<false>;
inTransaction(): Promise<boolean>;
/**
* Check connection status.
*
* @returns Whether this instance is connected to a SQLite3 database.
*/
isConnected(): boolean;
private createEntitiesTable;
private addTilmeldColumnsAndIndexes;
private createEntitiesTilmeldIndexes;
private createDataTable;
private createReferencesTable;
private createTokensTable;
private createUniquesTable;
/**
* Create entity tables in the database.
*
* @param etype The entity type to create a table for. If this is blank, the default tables are created.
*/
private createTables;
private query;
private queryArray;
private queryGet;
private queryRun;
commit(name: string): Promise<boolean>;
deleteEntityByID(guid: string, className?: EntityConstructor | string | null): Promise<boolean>;
deleteUID(name: string): Promise<boolean>;
getIndexes(etype: string): Promise<{
scope: "data" | "references" | "tokens";
name: string;
property: string;
}[]>;
addIndex(etype: string, definition: {
scope: 'data' | 'references' | 'tokens';
name: string;
property: string;
}): Promise<boolean>;
deleteIndex(etype: string, scope: 'data' | 'references' | 'tokens', name: string): Promise<boolean>;
getEtypes(): Promise<string[]>;
exportDataIterator(): AsyncGenerator<{
type: 'comment' | 'uid' | 'entity';
content: string;
}, void, false | undefined>;
/**
* Generate the SQLite3 query.
* @param options The options array.
* @param formattedSelectors The formatted selector array.
* @param etype
* @param count Used to track internal params.
* @param params Used to store internal params.
* @param subquery Whether only a subquery should be returned.
* @returns The SQL query.
*/
private makeEntityQuery;
protected performQuery(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
result: any;
};
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
return: 'count';
}, ...selectors: Selector[]): Promise<number>;
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
return: 'guid';
}, ...selectors: Selector[]): Promise<string[]>;
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
return: 'object';
}, ...selectors: Selector[]): Promise<EntityObjectType<T>[]>;
getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
getUID(name: string): Promise<number | null>;
importEntity(entity: {
guid: string;
cdate: number;
mdate: number;
tags: string[];
sdata: SerializedEntityData;
etype: string;
}): Promise<void>;
importEntityTokens(entity: {
guid: string;
cdate: number;
mdate: number;
tags: string[];
sdata: SerializedEntityData;
etype: string;
}): Promise<void>;
importEntityTilmeldAC(entity: {
guid: string;
cdate: number;
mdate: number;
tags: string[];
sdata: SerializedEntityData;
etype: string;
}): Promise<void>;
private importEntityInternal;
importUID({ name, value }: {
name: string;
value: number;
}): Promise<void>;
newUID(name: string): Promise<number>;
renameUID(oldName: string, newName: string): Promise<boolean>;
rollback(name: string): Promise<boolean>;
saveEntity(entity: EntityInterface): Promise<boolean>;
setUID(name: string, curUid: number): Promise<boolean>;
internalTransaction(name: string): Promise<void>;
startTransaction(name: string): Promise<import("@nymphjs/nymph").Nymph>;
private removeTilmeldOldRows;
needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns' | 'tilmeldRemoveOldRows'): Promise<void>;
}
export {};