mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Definitions for node module mariasql added
https://github.com/mscdex/node-mariasql On branch mariasql new file: mariasql/mariasql-tests.ts new file: mariasql/mariasql.d.ts
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
// These are the examples from the node-mariasql README transposed to TypeScript
|
||||
// https://github.com/mscdex/node-mariasql
|
||||
|
||||
/// <reference path="../node/node-0.10.d.ts" />
|
||||
|
||||
// Example 1 - SHOW DATABASES
|
||||
import util = require('util');
|
||||
import Client = require('mariasql');
|
||||
|
||||
var c:Client = new Client(),
|
||||
inspect = util.inspect;
|
||||
|
||||
c.connect({
|
||||
host: '127.0.0.1',
|
||||
user: 'foo',
|
||||
password: 'bar'
|
||||
});
|
||||
|
||||
c.on('connect', function () {
|
||||
console.log('Client connected');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Client error: ' + err);
|
||||
})
|
||||
.on('close', function (hadError) {
|
||||
console.log('Client closed');
|
||||
});
|
||||
|
||||
c.query('SHOW DATABASES')
|
||||
.on('result', function (res) {
|
||||
res.on('row', function (row) {
|
||||
console.log('Result row: ' + inspect(row));
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Result error: ' + inspect(err));
|
||||
})
|
||||
.on('end', function (info) {
|
||||
console.log('Result finished successfully');
|
||||
});
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Done with all results');
|
||||
});
|
||||
|
||||
c.end();
|
||||
|
||||
|
||||
// Example 2 - Query Placeholders
|
||||
var c = new Client();
|
||||
|
||||
c.connect({
|
||||
host: '127.0.0.1',
|
||||
user: 'foo',
|
||||
password: 'bar',
|
||||
db: 'mydb'
|
||||
});
|
||||
|
||||
c.on('connect', function () {
|
||||
console.log('Client connected');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Client error: ' + err);
|
||||
})
|
||||
.on('close', function (hadError) {
|
||||
console.log('Client closed');
|
||||
});
|
||||
|
||||
c.query('SELECT * FROM users WHERE id = :id AND name = :name',
|
||||
{id: 1337, name: 'Frylock'})
|
||||
.on('result', function (res) {
|
||||
res.on('row', function (row) {
|
||||
console.log('Result row: ' + inspect(row));
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Result error: ' + inspect(err));
|
||||
})
|
||||
.on('end', function (info) {
|
||||
console.log('Result finished successfully');
|
||||
});
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Done with all results');
|
||||
});
|
||||
|
||||
c.query('SELECT * FROM users WHERE id = ? AND name = ?',
|
||||
[1337, 'Frylock'])
|
||||
.on('result', function (res) {
|
||||
res.on('row', function (row) {
|
||||
console.log('Result row: ' + inspect(row));
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Result error: ' + inspect(err));
|
||||
})
|
||||
.on('end', function (info) {
|
||||
console.log('Result finished successfully');
|
||||
});
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Done with all results');
|
||||
});
|
||||
|
||||
c.end();
|
||||
|
||||
|
||||
// Example 3 prepared query
|
||||
c = new Client();
|
||||
|
||||
c.connect({
|
||||
host: '127.0.0.1',
|
||||
user: 'foo',
|
||||
password: 'bar',
|
||||
db: 'mydb'
|
||||
});
|
||||
|
||||
c.on('connect', function () {
|
||||
console.log('Client connected');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Client error: ' + err);
|
||||
})
|
||||
.on('close', function (hadError) {
|
||||
console.log('Client closed');
|
||||
});
|
||||
|
||||
var pq = c.prepare('SELECT * FROM users WHERE id = :id AND name = :name');
|
||||
|
||||
c.query(pq({id: 1337, name: 'Frylock'}))
|
||||
.on('result', function (res) {
|
||||
res.on('row', function (row) {
|
||||
console.log('Result row: ' + inspect(row));
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Result error: ' + inspect(err));
|
||||
})
|
||||
.on('end', function (info) {
|
||||
console.log('Result finished successfully');
|
||||
});
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Done with all results');
|
||||
});
|
||||
|
||||
c.end();
|
||||
|
||||
|
||||
// Example 4 - Abort Query
|
||||
c = new Client()
|
||||
var qcnt:number = 0;
|
||||
|
||||
c.connect({
|
||||
host: '127.0.0.1',
|
||||
user: 'foo',
|
||||
password: 'bar',
|
||||
multiStatements: true
|
||||
});
|
||||
|
||||
c.on('connect', function () {
|
||||
console.log('Client connected');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Client error: ' + err);
|
||||
})
|
||||
.on('close', function (hadError) {
|
||||
console.log('Client closed');
|
||||
});
|
||||
|
||||
c.query('SELECT "first query"; SELECT "second query"; SELECT "third query"', true)
|
||||
.on('result', function (res) {
|
||||
if (++qcnt === 2)
|
||||
res.abort();
|
||||
res.on('row', function (row) {
|
||||
console.log('Query #' + (qcnt) + ' row: ' + inspect(row));
|
||||
})
|
||||
.on('error', function (err) {
|
||||
console.log('Query #' + (qcnt) + ' error: ' + inspect(err));
|
||||
})
|
||||
.on('abort', function () {
|
||||
console.log('Query #' + (qcnt) + ' was aborted');
|
||||
})
|
||||
.on('end', function (info) {
|
||||
console.log('Query #' + (qcnt) + ' finished successfully');
|
||||
});
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Done with all queries');
|
||||
});
|
||||
|
||||
c.end();
|
||||
/* output:
|
||||
Client connected
|
||||
Query #1 row: [ 'first query' ]
|
||||
Query #1 finished successfully
|
||||
Query #2 was aborted
|
||||
Query #3 row: [ 'third query' ]
|
||||
Query #3 finished successfully
|
||||
Done with all queries
|
||||
Client closed
|
||||
*/
|
||||
Vendored
+97
@@ -0,0 +1,97 @@
|
||||
// Type definitions for mariasql v0.1.22
|
||||
// Project: https://github.com/mscdex/node-mariasql
|
||||
// Definitions by: MichaelBennett <https://github.com/bennett000/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
interface MariaCallBackError {
|
||||
(error:Error):void
|
||||
}
|
||||
|
||||
interface MariaCallBackResult {
|
||||
(result:MariaResult):void
|
||||
}
|
||||
|
||||
interface MariaCallBackRow {
|
||||
(result:Array<any>):void
|
||||
}
|
||||
|
||||
interface MariaCallBackBoolean {
|
||||
(result:boolean):void
|
||||
}
|
||||
|
||||
interface MariaCallBackObject {
|
||||
(result:Object):void
|
||||
}
|
||||
|
||||
interface MariaCallBackVoid {
|
||||
():void
|
||||
}
|
||||
|
||||
interface Dictionary {
|
||||
[index: string]: any;
|
||||
}
|
||||
|
||||
interface MariaPreparedQuery {
|
||||
(values:Dictionary):string;
|
||||
(values:Array<any>):string;
|
||||
}
|
||||
|
||||
interface ClientConfig {
|
||||
host: string;
|
||||
user: string;
|
||||
password: string;
|
||||
db?: string;
|
||||
port?: number;
|
||||
unixSocket?: string;
|
||||
keepQueries?: boolean;
|
||||
multiStatements?: boolean;
|
||||
connTimeout?: number;
|
||||
pingInterval?: number;
|
||||
secureAuth?: boolean;
|
||||
compress?: boolean;
|
||||
ssl?:any;
|
||||
local_infile?: boolean;
|
||||
read_default_group?: string;
|
||||
charset?: string;
|
||||
}
|
||||
|
||||
declare class MariaResult {
|
||||
on(signal:string, cb:MariaCallBackObject):MariaResult; // signal 'end'
|
||||
on(signal:string, cb:MariaCallBackError):MariaResult; // signal 'error'
|
||||
on(signal:string, cb:MariaCallBackRow):MariaResult; // signal 'row'
|
||||
on(signal:string, cb:MariaCallBackVoid):MariaResult; // signal 'abort'
|
||||
abort():void;
|
||||
}
|
||||
|
||||
declare class MariaQuery {
|
||||
on(signal:string, cb:MariaCallBackResult):MariaQuery; // signal 'result'
|
||||
on(signal:string, cb:MariaCallBackVoid):MariaQuery; // signal 'end'
|
||||
on(signal:string, cb:MariaCallBackVoid):MariaQuery; // signal 'abort'
|
||||
on(signal:string, cb:MariaCallBackError):MariaQuery; // signal 'error'
|
||||
abort():void;
|
||||
}
|
||||
|
||||
declare class MariaClient {
|
||||
connect(config:ClientConfig):void;
|
||||
end():void;
|
||||
destroy():void;
|
||||
escape(query:string):string;
|
||||
query(q:string, placeHolders?:Dictionary, useArray?:boolean):MariaQuery;
|
||||
query(q:string, placeHolders?:Array<any>, useArray?:boolean):MariaQuery;
|
||||
query(q:string, useArray?:boolean):MariaQuery;
|
||||
prepare(query:string): MariaPreparedQuery;
|
||||
isMariaDB():boolean;
|
||||
on(signal:string, cb:MariaCallBackError): MariaClient; // signal 'error'
|
||||
on(signal:string, cb:MariaCallBackObject): MariaClient; // signal 'close'
|
||||
on(signal:string, cb:MariaCallBackVoid): MariaClient; // signal 'connect'
|
||||
connected: boolean;
|
||||
threadId: string;
|
||||
}
|
||||
|
||||
declare module 'mariasql' {
|
||||
export = MariaClient;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user