UNPKG

@resin/pinejs

Version:

Pine.js is a sophisticated rules-driven API engine that enables you to define rules in a structured subset of English. Those rules are used in order for Pine.js to generate a database schema and the associated [OData](http://www.odata.org/) API. This make

65 lines (64 loc) 2.29 kB
/// <reference types="websql" /> import * as Promise from 'bluebird'; import TypedError = require('typed-error'); export interface CodedError extends Error { code: number | string; constructor: Function; } export interface Row { [fieldName: string]: any; } export interface Result { rows: Array<Row>; rowsAffected: number; insertId?: number; } export declare type Sql = string; export declare type Bindings = any[]; export declare class DatabaseError extends TypedError { code: number | string; constructor(message?: string | CodedError | SQLError); } export declare class ConstraintError extends DatabaseError { } export declare class UniqueConstraintError extends ConstraintError { } export declare class ForeignKeyConstraintError extends ConstraintError { } export declare type Database = { DatabaseError: typeof DatabaseError; ConstraintError: typeof ConstraintError; UniqueConstraintError: typeof UniqueConstraintError; ForeignKeyConstraintError: typeof ForeignKeyConstraintError; engine: string; executeSql: (this: Database, sql: Sql, bindings?: Bindings) => Promise<Tx>; transaction: (callback?: ((tx: Tx) => void)) => Promise<Tx>; }; export declare const engines: { [engine: string]: (connectString: string | object) => Database; }; export declare abstract class Tx { private automaticCloseTimeout; private automaticClose; constructor(stackTraceErr?: Error); private pending; private incrementPending; private decrementPending; cancelPending(): void; private closeTransaction; executeSql(sql: Sql, bindings?: Bindings, ...args: any[]): Promise<Result>; rollback(): Promise<void>; end(): Promise<void>; private listeners; on(name: 'end', fn: () => void): void; on(name: 'rollback', fn: () => void): void; protected abstract _executeSql(sql: Sql, bindings: Bindings, addReturning?: false | string): Promise<Result>; protected abstract _rollback(): Promise<void>; protected abstract _commit(): Promise<void>; abstract tableList(extraWhereClause?: string): Promise<Result>; dropTable(tableName: string, ifExists?: boolean): Promise<any>; } export declare const connect: (databaseOptions: { engine: string; params: {}; }) => Database;