Add typings for node-crate (#29375)

* Add typings for node-crate

* Fix indentation

* Fix array types
This commit is contained in:
Greg Jednaszewski
2018-10-02 20:50:19 -04:00
committed by Wesley Wigham
parent df782384c2
commit 8607133d93
4 changed files with 114 additions and 0 deletions

65
types/node-crate/index.d.ts vendored Normal file
View File

@@ -0,0 +1,65 @@
// Type definitions for node-crate 2.0
// Project: https://github.com/arobson/rabbot
// Definitions by: Greg Jednaszewski <https://github.com/gjednaszewski>
// 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<string|number|Date>) => Promise<DBResultObject>;
/**
* Inserts a row in table.
*/
insert: (tableName: string, data: object) => Promise<DBResultObject>;
/**
* Creates a table with the given schema.
*/
create: (schema: object) => Promise<DBResultObject>;
/**
* Drops a table.
*/
drop: (tableName: string) => Promise<DBResultObject>;
/**
* Updates one or more rows in table.
*/
update: (tableName: string, data: object, where: string) => Promise<DBResultObject>;
/**
* Deletes one or more rows in a table.
*/
delete: (tableName: string, where: string) => Promise<DBResultObject>;
/**
* Creates a BLOB table
*/
createBlobTable: (tableName: string, replicas: number, shards: number) => Promise<DBResultObject>;
/**
* Inserts a BLOB
*/
insertBlob: (tableName: string, buffer: string) => Promise<string>;
/**
* Inserts a BLOB from the filesystem
*/
insertBlobFile: (tableName: string, filename: string) => Promise<string>;
/**
* Retrieves a BLOB with the given hash key
*/
getBlob: (tableName: string, hashKey: string) => Promise<string>;
}
}
declare var crate: crate.Crate;
export = crate;

View File

@@ -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');

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }