mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-01-12 22:46:38 +08:00
Add typings for node-crate (#29375)
* Add typings for node-crate * Fix indentation * Fix array types
This commit is contained in:
committed by
Wesley Wigham
parent
df782384c2
commit
8607133d93
65
types/node-crate/index.d.ts
vendored
Normal file
65
types/node-crate/index.d.ts
vendored
Normal 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;
|
||||
25
types/node-crate/node-crate-tests.ts
Normal file
25
types/node-crate/node-crate-tests.ts
Normal 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');
|
||||
23
types/node-crate/tsconfig.json
Normal file
23
types/node-crate/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/node-crate/tslint.json
Normal file
1
types/node-crate/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user