* Renamed property according with docs

* Moved types to other file
This commit is contained in:
Santiago Aguilar Hernández
2018-11-12 03:36:03 -05:00
parent 7e0a27458d
commit e714e43f06
4 changed files with 86 additions and 81 deletions

View File

@@ -1,7 +1,9 @@
import Database = require('better-sqlite3');
import { RunResult } from 'better-sqlite3/types';
const integer = Database.Integer(1);
const err = new Database.SqliteError('ok', 'ok');
const result: RunResult = { changes: 1, lastInsertRowid: 1 };
let db = Database('.');
db = new Database('.', {memory: true});

View File

@@ -1,89 +1,11 @@
// 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;
}
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;
fileMustExist?: boolean;
}
interface RegistrationOptions {
name?: string;
varargs?: boolean;
deterministic?: boolean;
safeIntegers?: 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;
}
import { DatabaseConstructor } from "./types";
declare const Database: DatabaseConstructor;
export = Database;

View File

@@ -18,6 +18,7 @@
},
"files": [
"index.d.ts",
"types.d.ts",
"better-sqlite3-tests.ts"
]
}

80
types/better-sqlite3/types.d.ts vendored Normal file
View File

@@ -0,0 +1,80 @@
import Integer = require("integer");
export interface RunResult {
changes: number;
lastInsertRowid: Integer.IntLike;
}
export 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;
}
export class Transaction {
database: Database;
source: string;
constructor(db: Database, sources: string[]);
run(...params: any[]): RunResult;
bind(...params: any[]): this;
safeIntegers(toggleState?: boolean): this;
}
export interface DatabaseOptions {
memory?: boolean;
readonly?: boolean;
fileMustExist?: boolean;
}
export interface RegistrationOptions {
name?: string;
varargs?: boolean;
deterministic?: boolean;
safeIntegers?: boolean;
}
export 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;
}
export class SqliteError implements Error {
name: string;
message: string;
code: string;
constructor(message: string, code: string);
}
export interface DatabaseConstructor {
new (filename: string, options?: DatabaseOptions): Database;
(filename: string, options?: DatabaseOptions): Database;
prototype: Database;
Integer: typeof Integer;
SqliteError: typeof SqliteError;
}