mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #30951 from Loghorn/better-sqlite3
Update better-sqlite3 to match version 5.0
This commit is contained in:
@@ -6,7 +6,6 @@ const result: Database.RunResult = { changes: 1, lastInsertRowid: 1 };
|
||||
const options: Database.Options = { fileMustExist: true, memory: true, readonly: true };
|
||||
const registrationOptions: Database.RegistrationOptions = {
|
||||
deterministic: true,
|
||||
name: '',
|
||||
safeIntegers: true,
|
||||
varargs: true
|
||||
};
|
||||
@@ -15,26 +14,49 @@ let db = Database('.');
|
||||
db = new Database('.', { memory: true });
|
||||
db.exec('CREATE TABLE test (id INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL);');
|
||||
db.exec('INSERT INTO test(name) VALUES("name");');
|
||||
db.pragma('data_version', true);
|
||||
db.pragma('data_version', { simple: true });
|
||||
db.checkpoint();
|
||||
db.checkpoint('main');
|
||||
db.register(() => { });
|
||||
db.register({ name: 'noop', deterministic: true, varargs: true }, () => { });
|
||||
db.function('noop', () => { });
|
||||
db.function('noop', { deterministic: true, varargs: true }, () => { });
|
||||
db.aggregate('add', {
|
||||
start: 0,
|
||||
step: (t, n) => t + n,
|
||||
deterministic: true,
|
||||
varargs: true
|
||||
});
|
||||
db.aggregate('getAverage', {
|
||||
start: () => [],
|
||||
step: (array, nextValue) => {
|
||||
array.push(nextValue);
|
||||
},
|
||||
result: array => array.reduce((t: any, v: any) => t + v) / array.length,
|
||||
});
|
||||
db.aggregate('addAll', {
|
||||
start: 0,
|
||||
step: (total, nextValue) => total + nextValue,
|
||||
inverse: (total, droppedValue) => total - droppedValue,
|
||||
result: total => Math.round(total),
|
||||
});
|
||||
db.defaultSafeIntegers();
|
||||
db.defaultSafeIntegers(true);
|
||||
|
||||
const stmt = db.prepare('SELECT * FROM test WHERE name == ?;');
|
||||
stmt.get(['name']);
|
||||
stmt.all({ name: 'name' });
|
||||
stmt.each('name', (row: { name: string }) => { });
|
||||
stmt.each((row: { name: string }) => { });
|
||||
for (const row of stmt.iterate('name')) {
|
||||
}
|
||||
stmt.pluck();
|
||||
stmt.pluck(true);
|
||||
stmt.expand();
|
||||
stmt.expand(true);
|
||||
stmt.bind('name');
|
||||
stmt.safeIntegers();
|
||||
stmt.safeIntegers(true);
|
||||
|
||||
const trans = db.transaction(['INSERT INTO test(name) VALUES(?);']);
|
||||
trans.run('name');
|
||||
trans.bind('name');
|
||||
trans.run();
|
||||
const trans = db.transaction((param) => stmt.all(param));
|
||||
trans('name');
|
||||
trans.default('name');
|
||||
trans.deferred('name');
|
||||
trans.immediate('name');
|
||||
trans.exclusive('name');
|
||||
|
||||
Vendored
+29
-22
@@ -3,35 +3,32 @@
|
||||
// Definitions by: Ben Davies <https://github.com/Morfent>
|
||||
// Mathew Rumsey <https://github.com/matrumz>
|
||||
// Santiago Aguilar <https://github.com/sant123>
|
||||
// Alessandro Vergani <https://github.com/loghorn>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import Integer = require("integer");
|
||||
|
||||
declare class Statement {
|
||||
interface Statement {
|
||||
database: Database;
|
||||
source: string;
|
||||
returnsData: boolean;
|
||||
constructor(db: Database, sources: string[]);
|
||||
reader: boolean;
|
||||
|
||||
run(...params: any[]): Database.RunResult;
|
||||
get(...params: any[]): any;
|
||||
all(...params: any[]): any[];
|
||||
each(params: any, cb: (row: any) => void): void;
|
||||
each(cb: (row: any) => void): void;
|
||||
each(...params: any[]): void;
|
||||
iterate(...params: any[]): IterableIterator<any>;
|
||||
pluck(toggleState?: boolean): this;
|
||||
expand(toggleState?: boolean): this;
|
||||
bind(...params: any[]): this;
|
||||
safeIntegers(toggleState?: boolean): this;
|
||||
}
|
||||
|
||||
declare class Transaction {
|
||||
database: Database;
|
||||
source: string;
|
||||
constructor(db: Database, sources: string[]);
|
||||
|
||||
run(...params: any[]): Database.RunResult;
|
||||
bind(...params: any[]): this;
|
||||
safeIntegers(toggleState?: boolean): this;
|
||||
interface Transaction {
|
||||
(...params: any[]): any;
|
||||
default(...params: any[]): any;
|
||||
deferred(...params: any[]): any;
|
||||
immediate(...params: any[]): any;
|
||||
exclusive(...params: any[]): any;
|
||||
}
|
||||
|
||||
interface Database {
|
||||
@@ -42,15 +39,14 @@ interface Database {
|
||||
inTransaction: boolean;
|
||||
|
||||
prepare(source: string): Statement;
|
||||
transaction(sources: string[]): Transaction;
|
||||
transaction(fn: (...params: any[]) => any): Transaction;
|
||||
exec(source: string): this;
|
||||
pragma(source: string, simplify?: boolean): any;
|
||||
pragma(source: string, options?: Database.PragmaOptions): any;
|
||||
checkpoint(databaseName?: string): this;
|
||||
register(cb: (...params: any[]) => any): this;
|
||||
register(
|
||||
options: Database.RegistrationOptions,
|
||||
cb: (...params: any[]) => any
|
||||
): this;
|
||||
function(name: string, cb: (...params: any[]) => any): this;
|
||||
function(name: string, options: Database.RegistrationOptions, cb: (...params: any[]) => any): this;
|
||||
aggregate(name: string, options: Database.AggregateOptions): this;
|
||||
loadExtension(path: string): this;
|
||||
close(): this;
|
||||
defaultSafeIntegers(toggleState?: boolean): this;
|
||||
}
|
||||
@@ -81,14 +77,25 @@ declare namespace Database {
|
||||
memory?: boolean;
|
||||
readonly?: boolean;
|
||||
fileMustExist?: boolean;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface PragmaOptions {
|
||||
simple?: boolean;
|
||||
}
|
||||
|
||||
interface RegistrationOptions {
|
||||
name?: string;
|
||||
varargs?: boolean;
|
||||
deterministic?: boolean;
|
||||
safeIntegers?: boolean;
|
||||
}
|
||||
|
||||
interface AggregateOptions extends RegistrationOptions {
|
||||
start?: any;
|
||||
step: (total: any, next: any) => any;
|
||||
inverse?: (total: any, dropped: any) => any;
|
||||
result?: (total: any) => any;
|
||||
}
|
||||
}
|
||||
|
||||
declare const Database: DatabaseConstructor;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
@@ -20,4 +21,4 @@
|
||||
"index.d.ts",
|
||||
"better-sqlite3-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user