@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
74 lines (73 loc) • 2.61 kB
TypeScript
/// <reference types="websql" />
import type { Resolvable } from '../sbvr-api/common-types';
import { Engines } from '@resin/abstract-sql-compiler';
import * as Bluebird from 'bluebird';
import * as EventEmitter from 'eventemitter3';
import { TypedError } from 'typed-error';
export declare const metrics: EventEmitter<string | symbol, any>;
export interface CodedError extends Error {
code: number | string;
}
export interface Row {
[fieldName: string]: any;
}
export interface Result {
rows: 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 {
}
interface TransactionFn {
<T>(fn: (tx: Tx) => Resolvable<T>): Bluebird<T>;
(): Bluebird<Tx>;
}
export interface Database {
DatabaseError: typeof DatabaseError;
ConstraintError: typeof ConstraintError;
UniqueConstraintError: typeof UniqueConstraintError;
ForeignKeyConstraintError: typeof ForeignKeyConstraintError;
engine: Engines;
executeSql: (this: Database, sql: Sql, bindings?: Bindings) => Bluebird<Result>;
transaction: TransactionFn;
readTransaction?: TransactionFn;
}
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[]): Bluebird<Result>;
rollback(): Bluebird<void>;
end(): Bluebird<void>;
private listeners;
on(name: keyof Tx['listeners'], fn: () => void): void;
private clearListeners;
protected abstract _executeSql(sql: Sql, bindings: Bindings, addReturning?: false | string): Bluebird<Result>;
protected abstract _rollback(): Bluebird<void>;
protected abstract _commit(): Bluebird<void>;
abstract tableList(extraWhereClause?: string): Bluebird<Result>;
dropTable(tableName: string, ifExists?: boolean): Bluebird<Result>;
}
export declare const connect: (databaseOptions: {
engine: string;
params: {};
}) => Database;
export {};