Add missing exported better-sqlite3 types

Fixes #20166
This commit is contained in:
Alessandro Vergani
2018-12-19 09:21:44 +01:00
parent bc43dc9295
commit 89baaf0fe8
2 changed files with 77 additions and 67 deletions
+12 -11
View File
@@ -1,17 +1,17 @@
import Database = require('better-sqlite3');
import Sqlite = 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 = {
const integer = Sqlite.Integer(1);
const err = new Sqlite.SqliteError('ok', 'ok');
const result: Sqlite.RunResult = { changes: 1, lastInsertRowid: 1 };
const options: Sqlite.Options = { fileMustExist: true, memory: true, readonly: true };
const registrationOptions: Sqlite.RegistrationOptions = {
deterministic: true,
safeIntegers: true,
varargs: true
};
let db = Database('.');
db = new Database('.', { memory: true });
let db: Sqlite.Database = Sqlite('.');
db = new Sqlite('.', { 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', { simple: true });
@@ -41,7 +41,7 @@ db.aggregate('addAll', {
db.defaultSafeIntegers();
db.defaultSafeIntegers(true);
const stmt = db.prepare('SELECT * FROM test WHERE name == ?;');
const stmt: Sqlite.Statement = db.prepare('SELECT * FROM test WHERE name == ?;');
stmt.get(['name']);
stmt.all({ name: 'name' });
for (const row of stmt.iterate('name')) {
@@ -56,13 +56,14 @@ stmt.safeIntegers(true);
stmt.raw();
stmt.raw(true);
stmt.raw(false);
for (const col of stmt.columns()) {
let col: Sqlite.ColumnDefinition;
for (col of stmt.columns()) {
col.name;
col.column;
col.type;
}
const trans = db.transaction((param) => stmt.all(param));
const trans: Sqlite.Transaction = db.transaction((param) => stmt.all(param));
trans('name');
trans.default('name');
trans.deferred('name');
+65 -56
View File
@@ -8,57 +8,68 @@
import Integer = require("integer");
interface Statement {
database: Database;
source: string;
reader: boolean;
declare namespace BetterSqlite3 {
interface Statement {
database: Database;
source: string;
reader: boolean;
run(...params: any[]): Database.RunResult;
get(...params: any[]): any;
all(...params: any[]): any[];
iterate(...params: any[]): IterableIterator<any>;
pluck(toggleState?: boolean): this;
expand(toggleState?: boolean): this;
raw(toggleState?: boolean): this;
bind(...params: any[]): this;
columns(): ColumnDefinition[];
safeIntegers(toggleState?: boolean): this;
}
run(...params: any[]): Database.RunResult;
get(...params: any[]): any;
all(...params: any[]): any[];
iterate(...params: any[]): IterableIterator<any>;
pluck(toggleState?: boolean): this;
expand(toggleState?: boolean): this;
raw(toggleState?: boolean): this;
bind(...params: any[]): this;
columns(): ColumnDefinition[];
safeIntegers(toggleState?: boolean): this;
}
interface ColumnDefinition {
name: string;
column: string | null;
table: string | null;
database: string | null;
type: string | null;
}
interface ColumnDefinition {
name: string;
column: string | null;
table: string | null;
database: string | null;
type: string | null;
}
interface Transaction {
(...params: any[]): any;
default(...params: any[]): any;
deferred(...params: any[]): any;
immediate(...params: any[]): any;
exclusive(...params: any[]): any;
}
interface Transaction {
(...params: any[]): any;
default(...params: any[]): any;
deferred(...params: any[]): any;
immediate(...params: any[]): any;
exclusive(...params: any[]): any;
}
interface Database {
memory: boolean;
readonly: boolean;
name: string;
open: boolean;
inTransaction: boolean;
interface Database {
memory: boolean;
readonly: boolean;
name: string;
open: boolean;
inTransaction: boolean;
prepare(source: string): Statement;
transaction(fn: (...params: any[]) => any): Transaction;
exec(source: string): this;
pragma(source: string, options?: Database.PragmaOptions): any;
checkpoint(databaseName?: string): 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;
prepare(source: string): Statement;
transaction(fn: (...params: any[]) => any): Transaction;
exec(source: string): this;
pragma(source: string, options?: Database.PragmaOptions): any;
checkpoint(databaseName?: string): 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;
}
interface DatabaseConstructor {
new(filename: string, options?: Database.Options): Database;
(filename: string, options?: Database.Options): Database;
prototype: Database;
Integer: typeof Integer;
SqliteError: typeof SqliteError;
}
}
declare class SqliteError implements Error {
@@ -68,15 +79,6 @@ declare class SqliteError implements Error {
constructor(message: string, code: string);
}
interface DatabaseConstructor {
new (filename: string, options?: Database.Options): Database;
(filename: string, options?: Database.Options): Database;
prototype: Database;
Integer: typeof Integer;
SqliteError: typeof SqliteError;
}
declare namespace Database {
interface RunResult {
changes: number;
@@ -106,7 +108,14 @@ declare namespace Database {
inverse?: (total: any, dropped: any) => any;
result?: (total: any) => any;
}
type Integer = typeof Integer;
type SqliteError = typeof SqliteError;
type Statement = BetterSqlite3.Statement;
type ColumnDefinition = BetterSqlite3.ColumnDefinition;
type Transaction = BetterSqlite3.Transaction;
type Database = BetterSqlite3.Database;
}
declare const Database: DatabaseConstructor;
declare const Database: BetterSqlite3.DatabaseConstructor;
export = Database;