@nymphjs/driver-sqlite3
Version:
Nymph.js - SQLite3 DB Driver
110 lines (109 loc) • 4.22 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;
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;
/**
* 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>;
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({ guid, cdate, mdate, tags, sdata, etype, }: {
guid: string;
cdate: number;
mdate: number;
tags: string[];
sdata: SerializedEntityData;
etype: string;
}): Promise<void>;
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>;
needsMigration(): Promise<boolean>;
}
export {};