Merge pull request #30457 from sant123/better-sqlite3-fix

Better-sqlite3 - Renamed property according with docs
This commit is contained in:
Benjamin Lichtman
2018-11-26 18:52:12 -08:00
committed by GitHub
2 changed files with 82 additions and 68 deletions
+14 -6
View File
@@ -2,24 +2,32 @@ import Database = require('better-sqlite3');
const integer = Database.Integer(1);
const err = new Database.SqliteError('ok', 'ok');
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
};
let db = Database('.');
db = new Database('.', {memory: true});
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.checkpoint();
db.checkpoint('main');
db.register(() => {});
db.register({name: 'noop', deterministic: true, varargs: true}, () => {});
db.register(() => { });
db.register({ name: 'noop', deterministic: true, varargs: true }, () => { });
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}) => {});
stmt.all({ name: 'name' });
stmt.each('name', (row: { name: string }) => { });
stmt.each((row: { name: string }) => { });
stmt.pluck();
stmt.pluck(true);
stmt.bind('name');
+68 -62
View File
@@ -1,88 +1,94 @@
// Type definitions for better-sqlite3 3.1
// Type definitions for better-sqlite3 5.0
// Project: http://github.com/JoshuaWise/better-sqlite3
// Definitions by: Ben Davies <https://github.com/Morfent>
// Mathew Rumsey <https://github.com/matrumz>
// Santiago Aguilar <https://github.com/sant123>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Integer = require('integer');
interface RunResult {
changes: number;
lastInsertROWID: Integer.IntLike;
}
import Integer = require("integer");
declare class Statement {
database: Database;
source: string;
returnsData: boolean;
constructor(db: Database, sources: string[]);
database: Database;
source: string;
returnsData: boolean;
constructor(db: Database, sources: string[]);
run(...params: any[]): 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;
pluck(toggleState?: boolean): this;
bind(...params: any[]): this;
safeIntegers(toggleState?: boolean): this;
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;
pluck(toggleState?: boolean): this;
bind(...params: any[]): this;
safeIntegers(toggleState?: boolean): this;
}
declare class Transaction {
database: Database;
source: string;
constructor(db: Database, sources: string[]);
database: Database;
source: string;
constructor(db: Database, sources: string[]);
run(...params: any[]): RunResult;
bind(...params: any[]): this;
safeIntegers(toggleState?: boolean): this;
}
interface DatabaseOptions {
memory?: boolean;
readonly?: boolean;
fileMustExist?: boolean;
}
interface RegistrationOptions {
name?: string;
varargs?: boolean;
deterministic?: boolean;
safeIntegers?: boolean;
run(...params: any[]): Database.RunResult;
bind(...params: any[]): this;
safeIntegers(toggleState?: boolean): this;
}
interface Database {
memory: boolean;
readonly: boolean;
name: string;
open: boolean;
inTransaction: boolean;
memory: boolean;
readonly: boolean;
name: string;
open: boolean;
inTransaction: boolean;
prepare(source: string): Statement;
transaction(sources: string[]): Transaction;
exec(source: string): this;
pragma(source: string, simplify?: boolean): any;
checkpoint(databaseName?: string): this;
register(cb: (...params: any[]) => any): this;
register(options: RegistrationOptions, cb: (...params: any[]) => any): this;
close(): this;
defaultSafeIntegers(toggleState?: boolean): this;
prepare(source: string): Statement;
transaction(sources: string[]): Transaction;
exec(source: string): this;
pragma(source: string, simplify?: boolean): any;
checkpoint(databaseName?: string): this;
register(cb: (...params: any[]) => any): this;
register(
options: Database.RegistrationOptions,
cb: (...params: any[]) => any
): this;
close(): this;
defaultSafeIntegers(toggleState?: boolean): this;
}
declare class SqliteError implements Error {
name: string;
message: string;
code: string;
constructor(message: string, code: string);
name: string;
message: string;
code: string;
constructor(message: string, code: string);
}
interface DatabaseConstructor {
new(filename: string, options?: DatabaseOptions): Database;
(filename: string, options?: DatabaseOptions): Database;
prototype: Database;
new (filename: string, options?: Database.Options): Database;
(filename: string, options?: Database.Options): Database;
prototype: Database;
Integer: typeof Integer;
SqliteError: typeof SqliteError;
Integer: typeof Integer;
SqliteError: typeof SqliteError;
}
declare namespace Database {
interface RunResult {
changes: number;
lastInsertRowid: Integer.IntLike;
}
interface Options {
memory?: boolean;
readonly?: boolean;
fileMustExist?: boolean;
}
interface RegistrationOptions {
name?: string;
varargs?: boolean;
deterministic?: boolean;
safeIntegers?: boolean;
}
}
declare const Database: DatabaseConstructor;