mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[better-sqlite3] Add type declarations
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import * as Database from 'better-sqlite3';
|
||||
|
||||
let integer = Database.Integer(1);
|
||||
let err = new Database.SqliteError('ok', 'ok');
|
||||
|
||||
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.checkpoint();
|
||||
db.checkpoint('main');
|
||||
db.register(() => {});
|
||||
db.register({name: 'noop', deterministic: true, varargs: true}, () => {});
|
||||
db.defaultSafeIntegers();
|
||||
db.defaultSafeIntegers(true);
|
||||
|
||||
let 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.pluck();
|
||||
stmt.pluck(true);
|
||||
stmt.bind('name');
|
||||
stmt.safeIntegers();
|
||||
stmt.safeIntegers(true);
|
||||
|
||||
let trans = db.transaction(['INSERT INTO test(name) VALUES(?);']);
|
||||
trans.run('name');
|
||||
trans.bind('name');
|
||||
trans.run();
|
||||
Vendored
+88
@@ -0,0 +1,88 @@
|
||||
// Type definitions for better-sqlite3 3.1
|
||||
// Project: http://github.com/JoshuaWise/better-sqlite3
|
||||
// Definitions by: Ben Davies <https://github.com/Morfent/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as Integer from 'integer';
|
||||
|
||||
interface RunResult {
|
||||
changes: number;
|
||||
lastInsertRowID: number;
|
||||
}
|
||||
|
||||
declare class Statement {
|
||||
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;
|
||||
}
|
||||
|
||||
declare class Transaction {
|
||||
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;
|
||||
}
|
||||
|
||||
interface RegistrationOptions {
|
||||
name?: string;
|
||||
varargs?: boolean;
|
||||
deterministic?: boolean;
|
||||
}
|
||||
|
||||
interface Database {
|
||||
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;
|
||||
}
|
||||
|
||||
declare class SqliteError implements Error {
|
||||
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;
|
||||
|
||||
Integer: typeof Integer;
|
||||
SqliteError: typeof SqliteError;
|
||||
}
|
||||
|
||||
declare const Database: DatabaseConstructor;
|
||||
export = Database;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"better-sqlite3-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user