mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 20:02:05 +08:00
Updated for massive 3.0.0-rc1
This commit is contained in:
146
types/massive/index.d.ts
vendored
146
types/massive/index.d.ts
vendored
@@ -1,105 +1,57 @@
|
||||
// Type definitions for massive-js 2.2
|
||||
// Project: https://github.com/robconery/massive-js
|
||||
// Type definitions for massive 3.0.0-rc1
|
||||
// Project: https://github.com/dmfay/massive-js.git
|
||||
// Definitions by: Pascal Birchler <https://github.com/swissspidy>
|
||||
// Clarence Ho <https://github.com/clarenceh>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export namespace massive {
|
||||
interface ConnectionOptions {
|
||||
connectionString?: string;
|
||||
db?: string;
|
||||
}
|
||||
/// <reference types="node" />
|
||||
|
||||
interface Doc {
|
||||
findDoc(context: any, callback: ResultCallback): void;
|
||||
searchDoc(
|
||||
options: { keys: string[], term: string },
|
||||
callback: ResultCallback): void;
|
||||
saveDoc(context: string, callback: ResultCallback): void;
|
||||
destroy(context: any, callback: ResultCallback): void;
|
||||
}
|
||||
export = massive;
|
||||
|
||||
interface QueryFile {
|
||||
schema: string;
|
||||
name: string;
|
||||
db: Massive;
|
||||
delimitedName: string;
|
||||
delimitedSchema: string;
|
||||
fullname: string;
|
||||
delimitedFullName: string;
|
||||
sql: string;
|
||||
filePath: string;
|
||||
}
|
||||
declare function massive(
|
||||
connection: object | string,
|
||||
loaderConfig?: object,
|
||||
driverConfig?: object): Promise<massive.Database>;
|
||||
|
||||
interface QueryFunction {
|
||||
find(params: any|any[], callback: ResultCallback): void;
|
||||
}
|
||||
declare namespace massive {
|
||||
|
||||
export interface ConnectionInfo {
|
||||
|
||||
user?: string;
|
||||
database?: string;
|
||||
password?: string | null;
|
||||
port?: number;
|
||||
host?: string;
|
||||
ssl?: boolean;
|
||||
application_name?: string;
|
||||
fallback_application_name?: boolean;
|
||||
|
||||
}
|
||||
|
||||
export interface Database {
|
||||
|
||||
attach(ctor: Function, ...sources: (Function | Promise<any>)[]): Promise<any>;
|
||||
|
||||
detach(entity: string, collection: string): void;
|
||||
|
||||
reload(): void;
|
||||
|
||||
query(query: any, params: any, options: any): Promise<any>;
|
||||
|
||||
saveDoc(collection: any, doc: any): any;
|
||||
|
||||
createDocumentTable(path: any): Promise<any>;
|
||||
|
||||
getObject(path: any, collection: any): object;
|
||||
|
||||
dropTable(table: string, options: any): void;
|
||||
|
||||
createSchema(schemaName: string): void;
|
||||
|
||||
dropSchema(schemaName: string, options: any): void;
|
||||
|
||||
[name: string]: any;
|
||||
|
||||
}
|
||||
|
||||
interface QueryArguments {
|
||||
sql: string;
|
||||
options: any;
|
||||
params: any;
|
||||
next: ResultCallback;
|
||||
}
|
||||
}
|
||||
|
||||
export interface Massive {
|
||||
custom: any;
|
||||
comment: Table;
|
||||
friendship: Table;
|
||||
participation: Table;
|
||||
person: Table;
|
||||
practice: Table;
|
||||
practicesession: Table;
|
||||
sport: Table;
|
||||
testdata(callback: ResultCallback): void;
|
||||
team: Table;
|
||||
teammember: Table;
|
||||
teamsport: Table;
|
||||
scriptsDir: string;
|
||||
connectionString: string;
|
||||
query(): void;
|
||||
stream(): void;
|
||||
executeSqlFile(args: any, next: ResultCallback): void;
|
||||
end(): void;
|
||||
tables: Array<massive.Doc|Table>;
|
||||
views: any[];
|
||||
queryFiles: massive.QueryFile[];
|
||||
schemas: any[];
|
||||
functions: any[];
|
||||
allowedSchemas: string;
|
||||
blacklist: string;
|
||||
exceptions: string;
|
||||
excludeFunctions: boolean;
|
||||
functionBlacklist: string;
|
||||
}
|
||||
|
||||
export type ResultCallback = (err: Error, res: any) => void;
|
||||
export type ConnectCallback = (err: Error, db: Massive) => void;
|
||||
|
||||
export interface QueryOptions {
|
||||
limit?: number;
|
||||
order?: string;
|
||||
offset?: number;
|
||||
columns?: string[];
|
||||
}
|
||||
|
||||
export interface Table {
|
||||
count(context: any, callback: ResultCallback): void;
|
||||
find(context: any, callback: ResultCallback): void;
|
||||
find(context: any, options: QueryOptions, callback: ResultCallback): void;
|
||||
findOne(context: any, callback: ResultCallback): void;
|
||||
findOne(context: any, options: QueryOptions, callback: ResultCallback): void;
|
||||
insert(context: any, callback: ResultCallback): void;
|
||||
save(context: any, callback: ResultCallback): void;
|
||||
update(context: any, callback: ResultCallback): void;
|
||||
update(context: any, data: any, callback: ResultCallback): void;
|
||||
destroy(context: any, callback: ResultCallback): void;
|
||||
}
|
||||
|
||||
export function connectSync(options: massive.ConnectionOptions): Massive;
|
||||
|
||||
export function connect(options: massive.ConnectionOptions, callback: ConnectCallback): void;
|
||||
|
||||
export function run(context: string, filter: number|number[], callback: ResultCallback): void;
|
||||
|
||||
export function saveDoc(name: string, data: any, callback: ResultCallback): void;
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
import * as Massive from 'massive';
|
||||
import massive = require('massive');
|
||||
|
||||
Massive.connect({connectionString: 'foo'}, (err: Error, db: Massive.Massive) => {});
|
||||
let dbconn: massive.Database;
|
||||
|
||||
Massive.run('foo', 123, (err: Error, db: Massive.Massive) => {});
|
||||
function findUserById(id: number): Promise<any> {
|
||||
return dbconn.users.findOne({id: id});
|
||||
}
|
||||
|
||||
massive('postgres://app:password@localhost:5432/app').then( db => {
|
||||
|
||||
console.log(`DB connected successfully`);
|
||||
|
||||
dbconn = db;
|
||||
|
||||
findUserById(1).then(user => console.log(`User: ${JSON.stringify(user)}`));
|
||||
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es5"
|
||||
"es2015"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
@@ -19,4 +19,4 @@
|
||||
"index.d.ts",
|
||||
"massive-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user