diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 3b9cd70c7..355990539 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -1,4 +1,4 @@
-# Contributors
+# Contributors
This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url.
@@ -286,6 +286,7 @@ All definitions files include a header with the author and editors, so at some p
* [SockJS](https://github.com/sockjs/sockjs-client) (by [Emil Ivanov](https://github.com/vladev))
* [SoundJS](http://www.createjs.com/#!/SoundJS) (by [Pedro Ferreira](https://bitbucket.org/drk4))
* [Spin](http://fgnass.github.com/spin.js/) (by [Boris Yankov](https://github.com/borisyankov))
+* [sqlite3](https://github.com/mapbox/node-sqlite3) (by [Nick Malaguti](https://github.com/nmalaguti))
* [status-bar](https://github.com/atom/status-bar) (by [vvakame](https://github.com/vvakame))
* [stripe](https://stripe.com/) (by [Eric J. Smith](https://github.com/ejsmith/))
* [Store.js](https://github.com/marcuswestin/store.js/) (by [Vincent Bortone](https://github.com/vbortone))
diff --git a/sqlite3/sqlite3-tests.ts b/sqlite3/sqlite3-tests.ts
new file mode 100644
index 000000000..7059a439a
--- /dev/null
+++ b/sqlite3/sqlite3-tests.ts
@@ -0,0 +1,92 @@
+///
+
+import sqlite3 = require('sqlite3');
+sqlite3.verbose();
+
+var db: sqlite3.Database;
+
+function createDb() {
+ console.log("createDb chain");
+ db = new sqlite3.Database('chain.sqlite3', createTable);
+}
+
+function createTable() {
+ console.log("createTable lorem");
+ db.run("CREATE TABLE IF NOT EXISTS lorem (info TEXT)", insertRows);
+}
+
+function insertRows() {
+ console.log("insertRows Ipsum i");
+ var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
+
+ for (var i = 0; i < 10; i++) {
+ stmt.run("Ipsum " + i);
+ }
+
+ stmt.finalize(readAllRows);
+}
+
+function readAllRows() {
+ console.log("readAllRows lorem");
+ db.all("SELECT rowid AS id, info FROM lorem", function(err, rows) {
+ rows.forEach(function (row) {
+ console.log(row.id + ": " + row.info);
+ });
+ closeDb();
+ });
+}
+
+function closeDb() {
+ console.log("closeDb");
+ db.close();
+}
+
+function runChainExample() {
+ createDb();
+}
+
+runChainExample();
+
+db.serialize(function() {
+ db.run("CREATE TABLE lorem (info TEXT)");
+
+ var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
+ for (var i = 0; i < 10; i++) {
+ stmt.run("Ipsum " + i);
+ }
+ stmt.finalize();
+
+ db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
+ console.log(row.id + ": " + row.info);
+ });
+});
+
+db.serialize(function() {
+ // These two queries will run sequentially.
+ db.run("CREATE TABLE foo (num)");
+ db.run("INSERT INTO foo VALUES (?)", 1, function() {
+ // These queries will run in parallel and the second query will probably
+ // fail because the table might not exist yet.
+ db.run("CREATE TABLE bar (num)");
+ db.run("INSERT INTO bar VALUES (?)", 1);
+ });
+});
+
+// Directly in the function arguments.
+db.run("UPDATE tbl SET name = ? WHERE id = ?", "bar", 2);
+
+// As an array.
+db.run("UPDATE tbl SET name = ? WHERE id = ?", [ "bar", 2 ]);
+
+// As an object with named parameters.
+db.run("UPDATE tbl SET name = $name WHERE id = $id", {
+ $id: 2,
+ $name: "bar"
+});
+
+db.run("UPDATE tbl SET name = ?5 WHERE id = ?", {
+ 1: 2,
+ 5: "bar"
+});
+
+db.close();
diff --git a/sqlite3/sqlite3.d.ts b/sqlite3/sqlite3.d.ts
new file mode 100644
index 000000000..c2c77cad9
--- /dev/null
+++ b/sqlite3/sqlite3.d.ts
@@ -0,0 +1,81 @@
+// Type definitions for sqlite3 2.2.3
+// Project: https://github.com/mapbox/node-sqlite3
+// Definitions by: Nick Malaguti
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+///
+
+declare module "sqlite3" {
+ import events = require("events");
+
+ export var OPEN_READONLY: number;
+ export var OPEN_READWRITE: number;
+ export var OPEN_CREATE: number;
+
+ export var cached: {
+ Database(filename: string, callback?: (err: Error) => void): Database;
+ Database(filename: string, mode?: number, callback?: (err: Error) => void): Database;
+ };
+
+ export interface RunResult {
+ lastID: number;
+ changes: number;
+ }
+
+ export class Statement {
+ public bind(callback?: (err: Error) => void): Statement;
+ public bind(...params: any[]): Statement;
+
+ public reset(callback?: (err: Error) => void): Statement;
+
+ public finalize(callback?: (err: Error) => void): Statement;
+
+ public run(callback?: (err: Error) => void): Statement;
+ public run(...params: any[]): Statement;
+
+ public get(callback?: (err: Error, row: any) => void): Statement;
+ public get(...params: any[]): Statement;
+
+ public all(callback?: (err: Error, rows: any[]) => void): Statement;
+ public all(...params: any[]): Statement;
+
+ public each(callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Statement;
+ public each(...params: any[]): Statement;
+ }
+
+ export class Database extends events.EventEmitter {
+ constructor(filename: string, callback?: (err: Error) => void);
+ constructor(filename: string, mode?: number, callback?: (err: Error) => void);
+
+ public close(callback?: (err: Error) => void): void;
+
+ public run(sql: string, callback?: (err: Error) => void): Database;
+ public run(sql: string, ...params: any[]): Database;
+
+ public get(sql: string, callback?: (err: Error, row: any) => void): Database;
+ public get(sql: string, ...params: any[]): Database;
+
+ public all(sql: string, callback?: (err: Error, rows: any[]) => void): Database;
+ public all(sql: string, ...params: any[]): Database;
+
+ public each(sql: string, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Database;
+ public each(sql: string, ...params: any[]): Database;
+
+ public exec(sql: string, callback?: (err: Error) => void): Database;
+
+ public prepare(sql: string, callback?: (err: Error) => void): Statement;
+ public prepare(sql: string, ...params: any[]): Statement;
+
+ public serialize(callback?: () => void): void;
+ public parallelize(callback?: () => void): void;
+
+ public on(event: "trace", listener: (sql: string) => void): Database;
+ public on(event: "profile", listener: (sql: string, time: number) => void): Database;
+ public on(event: "error", listener: (err: Error) => void): Database;
+ public on(event: "open", listener: () => void): Database;
+ public on(event: "close", listener: () => void): Database;
+ public on(event: string, listener: Function): Database;
+ }
+
+ function verbose(): void;
+}