diff --git a/types/node-crate/index.d.ts b/types/node-crate/index.d.ts new file mode 100644 index 0000000000..8fa75581e0 --- /dev/null +++ b/types/node-crate/index.d.ts @@ -0,0 +1,65 @@ +// Type definitions for node-crate 2.0 +// Project: https://github.com/arobson/rabbot +// Definitions by: Greg Jednaszewski +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare namespace crate { + interface DBResultObject { + json: object[]; + duration: number; + rowcount: number; + cols: string[]; + rows: object[][]; + } + + interface Crate { + /** + * Connect to a single crate instance with host and port + */ + connect: (host: string, port?: number) => void; + /** + * Executes a parameterized sql statement. + */ + execute: (sql: string, args?: Array) => Promise; + /** + * Inserts a row in table. + */ + insert: (tableName: string, data: object) => Promise; + /** + * Creates a table with the given schema. + */ + create: (schema: object) => Promise; + /** + * Drops a table. + */ + drop: (tableName: string) => Promise; + /** + * Updates one or more rows in table. + */ + update: (tableName: string, data: object, where: string) => Promise; + /** + * Deletes one or more rows in a table. + */ + delete: (tableName: string, where: string) => Promise; + /** + * Creates a BLOB table + */ + createBlobTable: (tableName: string, replicas: number, shards: number) => Promise; + /** + * Inserts a BLOB + */ + insertBlob: (tableName: string, buffer: string) => Promise; + /** + * Inserts a BLOB from the filesystem + */ + insertBlobFile: (tableName: string, filename: string) => Promise; + /** + * Retrieves a BLOB with the given hash key + */ + getBlob: (tableName: string, hashKey: string) => Promise; + } +} + +declare var crate: crate.Crate; +export = crate; diff --git a/types/node-crate/node-crate-tests.ts b/types/node-crate/node-crate-tests.ts new file mode 100644 index 0000000000..d98f8c2694 --- /dev/null +++ b/types/node-crate/node-crate-tests.ts @@ -0,0 +1,25 @@ +import * as crate from "node-crate"; + +crate.connect("127.0.0.1"); +crate.connect("127.0.0.1", 1234); + +crate.execute('select * from users'); +crate.execute('select * from users where id = ?', ['test']); + +crate.insert('users', {id: 'test', password: 'password'}); + +crate.create({users: {id: 'string primary key', password: 'string'}}); + +crate.drop('users'); + +crate.update('users', {password: 'newPassword'}, "id = 'test'"); + +crate.delete('users', "id = 'test'"); + +crate.createBlobTable('photos', 1, 2); + +crate.insertBlob('photos', 'XXXXXXXX'); + +crate.insertBlobFile('photos', '/path/to/photo.png'); + +crate.getBlob('photos', 'WEWERTWERTWSHSDFG'); diff --git a/types/node-crate/tsconfig.json b/types/node-crate/tsconfig.json new file mode 100644 index 0000000000..a8fc4d93b5 --- /dev/null +++ b/types/node-crate/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "node-crate-tests.ts" + ] +} diff --git a/types/node-crate/tslint.json b/types/node-crate/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/node-crate/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }