Browse Source

No more callbacks in the public interface/New implementation to allow multiple adapters for a database type

Timothy J. Warren 2 years ago
parent
commit
d4a8231947

+ 29
- 0
.editorconfig View File

@@ -0,0 +1,29 @@
1
+# EditorConfig is awesome: http://EditorConfig.org
2
+
3
+# top-most EditorConfig file
4
+root = true
5
+
6
+# Unix-style newlines with a newline ending every file
7
+[*]
8
+end_of_line = lf
9
+insert_final_newline = true
10
+
11
+# Matches multiple files with brace expansion notation
12
+# Set default charset
13
+[*]
14
+charset = utf-8
15
+
16
+# Tab indentation (no size specified)
17
+[*]
18
+indent_style = tab
19
+indent_size = 4
20
+
21
+# Indentation override for all JS under lib directory
22
+[*.js]
23
+indent_size = 2
24
+
25
+# Matches the exact files either package.json or .travis.yml
26
+[*.yml]
27
+indent_style = space
28
+indent_size = 2
29
+

+ 1
- 3
lib/NodeQuery.js View File

@@ -55,10 +55,8 @@ class NodeQuery {
55 55
 			const driver = require(`./drivers/${drivername}`);
56 56
 			const Adapter = require(`./adapters/${drivername}`);
57 57
 
58
-			let adapter = new Adapter(config.connection);
58
+			let adapter = Adapter(config);
59 59
 			this.instance = new QueryBuilder(driver, adapter);
60
-		} else {
61
-			throw new Error('What am I supposed to do without any config options, guess?');
62 60
 		}
63 61
 	}
64 62
 

+ 1
- 3
lib/QueryBuilder.js View File

@@ -23,8 +23,7 @@ class QueryBuilder extends QueryBuilderBase {
23 23
 	 * @return {Promise} - Promise with result of query
24 24
 	 */
25 25
 	query (sql, params) {
26
-		return this.adapter.execute(sql, params)
27
-			.catch(e => console.error(e));
26
+		return this.adapter.execute(sql, params);
28 27
 	}
29 28
 
30 29
 	/**
@@ -546,7 +545,6 @@ class QueryBuilder extends QueryBuilderBase {
546 545
 	 * @return {Promise} - If no callback is passed, a promise is returned
547 546
 	 */
548 547
 	update (table, data) {
549
-
550 548
 		if (data) {
551 549
 			this.set(data);
552 550
 		}

+ 8
- 0
lib/adapters/Firebird/index.js View File

@@ -0,0 +1,8 @@
1
+'use strict';
2
+
3
+const NodeFirebird = require('./node-firebird');
4
+
5
+module.exports = config => {
6
+	return new NodeFirebird(config.connection);
7
+};
8
+

lib/adapters/Firebird.js → lib/adapters/Firebird/node-firebird.js View File

@@ -1,10 +1,10 @@
1 1
 'use strict';
2 2
 
3
-const Adapter = require('../Adapter');
3
+const Adapter = require('../../Adapter');
4
+const Result = require('../../Result');
4 5
 const fb = require('node-firebird');
5 6
 
6 7
 class Firebird extends Adapter {
7
-
8 8
 	constructor (config) {
9 9
 		super({});
10 10
 		this.instance = new Promise((resolve, reject) => {
@@ -13,7 +13,7 @@ class Firebird extends Adapter {
13 13
 					return reject(err);
14 14
 				}
15 15
 
16
-				return resolve(instance)
16
+				return resolve(instance);
17 17
 			});
18 18
 		});
19 19
 	}
@@ -33,12 +33,22 @@ class Firebird extends Adapter {
33 33
 						return reject(err);
34 34
 					}
35 35
 
36
-					return resolve(result);
37
-				})
36
+					return resolve(this.transformResult(result));
37
+				});
38 38
 			});
39 39
 		});
40 40
 	}
41 41
 
42
+	/**
43
+	 * Transform the adapter's result into a standard format
44
+	 *
45
+	 * @param {*} originalResult - the original result object from the driver
46
+	 * @return {Result} - the new result object
47
+	 */
48
+	transformResult (originalResult) {
49
+		return new Result(originalResult);
50
+	}
51
+
42 52
 	/**
43 53
 	 * Close the current database connection
44 54
 	 * @return {void}
@@ -48,4 +58,4 @@ class Firebird extends Adapter {
48 58
 	}
49 59
 }
50 60
 
51
-module.exports = Firebird;
61
+module.exports = Firebird;

+ 0
- 3
lib/adapters/MariaDB.js View File

@@ -1,3 +0,0 @@
1
-'use strict';
2
-
3
-module.exports = require('./Mysql');

+ 3
- 0
lib/adapters/MariaDB/index.js View File

@@ -0,0 +1,3 @@
1
+'use strict';
2
+
3
+module.exports = require('../Mysql');

+ 7
- 0
lib/adapters/Mysql/index.js View File

@@ -0,0 +1,7 @@
1
+'use strict';
2
+
3
+const Mysql2 = require('./mysql2');
4
+
5
+module.exports = config => {
6
+	return new Mysql2(config.connection);
7
+};

lib/adapters/Mysql.js → lib/adapters/Mysql/mysql2.js View File

@@ -1,9 +1,8 @@
1 1
 'use strict';
2 2
 
3
-const Adapter = require('../Adapter');
4
-const Result = require('../Result');
5
-const helpers = require('../helpers');
6
-const getArgs = require('getargs');
3
+const Adapter = require('../../Adapter');
4
+const Result = require('../../Result');
5
+const helpers = require('../../helpers');
7 6
 const mysql2 = require('mysql2/promise');
8 7
 
9 8
 class Mysql extends Adapter {
@@ -41,12 +40,12 @@ class Mysql extends Adapter {
41 40
 	 *
42 41
 	 * @param {String} sql - The sql with placeholders
43 42
 	 * @param {Array|undefined} params - The values to insert into the query
44
-	 * @return {Promise}
43
+	 * @return {Promise} Result of query
45 44
 	 */
46 45
 	execute (sql, params) {
47
-		return this.instance.then(conn => {
48
-			return conn.execute(sql, params);
49
-		}).then(result => this.transformResult(result));
46
+		return this.instance
47
+			.then(conn => conn.execute(sql, params))
48
+			.then(result => this.transformResult(result));
50 49
 	}
51 50
 }
52 51
 

lib/adapters/Pg.js → lib/adapters/Pg/Pg.js View File

@@ -1,13 +1,12 @@
1 1
 'use strict';
2 2
 
3
-const Adapter = require('../Adapter');
4
-const Result = require('../Result');
5
-const helpers = require('../helpers');
3
+const Adapter = require('../../Adapter');
4
+const Result = require('../../Result');
5
+const helpers = require('../../helpers');
6 6
 const pg = require('pg');
7 7
 const url = require('url');
8 8
 
9 9
 class Pg extends Adapter {
10
-
11 10
 	constructor (config) {
12 11
 		let instance = null;
13 12
 		let connectionString = '';
@@ -71,7 +70,6 @@ class Pg extends Adapter {
71 70
 	 * @return {void|Promise} - Returns a promise if no callback is provided
72 71
 	 */
73 72
 	execute (sql, params) {
74
-
75 73
 		// Replace question marks with numbered placeholders, because this adapter is different...
76 74
 		let count = 0;
77 75
 		sql = sql.replace(/\?/g, () => {
@@ -81,7 +79,7 @@ class Pg extends Adapter {
81 79
 
82 80
 		return this.instance.then(conn => {
83 81
 			return new Promise((resolve, reject) => {
84
-                conn.query(sql, params, (err, result) =>
82
+				conn.query(sql, params, (err, result) =>
85 83
 					(err)
86 84
 						? reject(err)
87 85
 						: resolve(this.transformResult(result))

+ 7
- 0
lib/adapters/Pg/index.js View File

@@ -0,0 +1,7 @@
1
+'use strict';
2
+
3
+const Pg = require('./pg');
4
+
5
+module.exports = config => {
6
+	return new Pg(config.connection);
7
+};

+ 67
- 0
lib/adapters/Sqlite/dblite.js View File

@@ -0,0 +1,67 @@
1
+'use strict';
2
+
3
+const Adapter = require('../../Adapter');
4
+const Result = require('../../Result');
5
+const helpers = require('../../helpers');
6
+const dbliteAdapter = require('dblite');
7
+
8
+class SqliteDblite extends Adapter {
9
+	constructor (config) {
10
+		let file = (helpers.isString(config)) ? config : config.file;
11
+
12
+		const instance = new Promise((resolve, reject) => {
13
+			let conn = dbliteAdapter(file);
14
+
15
+			// Stop the stupid 'bye bye' message being output
16
+			conn.on('close', () => {});
17
+
18
+			conn.on('error', err => {
19
+				reject(err);
20
+			});
21
+
22
+			// Make sure to actually pass on the connection!
23
+			return resolve(conn);
24
+		});
25
+
26
+		super(instance);
27
+	}
28
+
29
+	/**
30
+	 * Run the sql query as a prepared statement
31
+	 *
32
+	 * @param {String} sql - The sql with placeholders
33
+	 * @param {Array} params - The values to insert into the query
34
+	 * @return {Promise} - Returns a promise if no callback is provided
35
+	 */
36
+	execute (sql, params) {
37
+		return this.instance.then(conn => new Promise((resolve, reject) => {
38
+			return conn.query(sql, params, (err, rows) => {
39
+				if (err) {
40
+					return reject(err);
41
+				}
42
+				return resolve(this.transformResult(rows));
43
+			});
44
+		}));
45
+	}
46
+
47
+	/**
48
+	 * Transform the adapter's result into a standard format
49
+	 *
50
+	 * @param {*} originalResult - the original result object from the driver
51
+	 * @return {Result} - the new result object
52
+	 */
53
+	transformResult (originalResult) {
54
+		return new Result(originalResult);
55
+	}
56
+
57
+	/**
58
+	 * Close the current database connection
59
+	 *
60
+	 * @return {void}
61
+	 */
62
+	close () {
63
+		this.instance.then(conn => conn.close());
64
+	}
65
+}
66
+
67
+module.exports = SqliteDblite;

+ 10
- 0
lib/adapters/Sqlite/index.js View File

@@ -0,0 +1,10 @@
1
+'use strict';
2
+
3
+module.exports = config => {
4
+	const Implementation = (config.adapter && config.adapter === 'dblite')
5
+		? require('./dblite')
6
+		: require('./sqlite3');
7
+
8
+	return new Implementation(config.connection);
9
+};
10
+

lib/adapters/Sqlite.js → lib/adapters/Sqlite/sqlite3.js View File

@@ -1,25 +1,23 @@
1 1
 'use strict';
2 2
 
3
-const Adapter = require('../Adapter');
4
-const Result = require('../Result');
5
-const helpers = require('../helpers');
6
-const dbliteAdapter = require('dblite');
3
+const Adapter = require('../../Adapter');
4
+const Result = require('../../Result');
5
+const helpers = require('../../helpers');
6
+const sqlite3 = require('sqlite3').verbose();
7 7
 
8
-class Sqlite extends Adapter {
8
+class SqliteSqlite3 extends Adapter {
9 9
 	constructor (config) {
10 10
 		let file = (helpers.isString(config)) ? config : config.file;
11 11
 
12
-		const instance = Promise.resolve(dbliteAdapter(file)).then(conn => {
13
-			// Stop the stupid 'bye bye' message being output
14
-			conn.on('close', () => {});
15
-
16
-			conn.on('error', (err) => {
17
-				throw new Error(err);
12
+		const instance = new Promise((resolve, reject) => {
13
+			let conn = new sqlite3.Database(file, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, err => {
14
+				if (err) {
15
+					reject(err);
16
+				}
18 17
 			});
19 18
 
20
-			// Make sure to actually pass on the connection!
21
-			return conn;
22
-		}).catch(e => console.error(e));
19
+			conn.on('open', resolve(conn));
20
+		});
23 21
 
24 22
 		super(instance);
25 23
 	}
@@ -42,15 +40,14 @@ class Sqlite extends Adapter {
42 40
 	 * @return {Promise} - Returns a promise if no callback is provided
43 41
 	 */
44 42
 	execute (sql, params) {
45
-
46
-		return this.instance.then(conn => {
47
-			return conn.query(sql, params, (err, result) => {
43
+		return this.instance.then(conn => new Promise((resolve, reject) => {
44
+			conn.all(sql, params, (err, rows) => {
48 45
 				if (err) {
49
-					throw new Error(err);
46
+					return reject(err);
50 47
 				}
51
-				return Promise.resolve(this.instance).then(() => result);
48
+				return resolve(this.transformResult(rows));
52 49
 			});
53
-		});
50
+		}));
54 51
 	}
55 52
 
56 53
 	/**
@@ -63,4 +60,4 @@ class Sqlite extends Adapter {
63 60
 	}
64 61
 }
65 62
 
66
-module.exports = Sqlite;
63
+module.exports = SqliteSqlite3;

+ 2
- 3
lib/drivers/Firebird.js View File

@@ -24,8 +24,7 @@ module.exports = (() => {
24 24
 	driver.limit = (origSql, limit, offset) => {
25 25
 		let sql = `FIRST ${limit}`;
26 26
 
27
-		if (helpers.isNumber(offset))
28
-		{
27
+		if (helpers.isNumber(offset)) {
29 28
 			sql += ` SKIP ${offset}`;
30 29
 		}
31 30
 
@@ -43,4 +42,4 @@ module.exports = (() => {
43 42
 	};
44 43
 
45 44
 	return driver;
46
-})();
45
+})();

+ 1
- 1
lib/drivers/Sqlite.js View File

@@ -54,7 +54,7 @@ module.exports = (() => {
54 54
 
55 55
 		return {
56 56
 			sql: sql,
57
-			values: null
57
+			values: undefined
58 58
 		};
59 59
 	};
60 60
 

+ 1
- 0
package.json View File

@@ -42,6 +42,7 @@
42 42
     "node-firebird": "^0.7.5",
43 43
     "pg": "^6.0.0",
44 44
     "require-reload": "~0.2.2",
45
+    "sqlite3": "^3.1.8",
45 46
     "xregexp": "^3.0.0"
46 47
   },
47 48
   "devDependencies": {

+ 38
- 0
test/adapters/00node-firebird_test.js View File

@@ -0,0 +1,38 @@
1
+/* eslint-env node, mocha */
2
+'use strict';
3
+
4
+// Load the test base
5
+const path = require('path');
6
+const reload = require('require-reload')(require);
7
+const testBase = reload('../base');
8
+const expect = testBase.expect;
9
+const testRunner = testBase.promiseTestRunner;
10
+
11
+// Skip on CI
12
+if (!(process.env.CI || process.env.TRAVIS)) {
13
+	// Load the test config file
14
+	let adapterName = 'node-firebird';
15
+	const config = reload('../config.json')[adapterName];
16
+	config.connection.database = path.join(__dirname, config.connection.database);
17
+	let nodeQuery = reload('../../lib/NodeQuery')(config);
18
+
19
+	let qb = nodeQuery.getQuery();
20
+
21
+	suite('Firebird adapter tests -', () => {
22
+		test('nodeQuery.getQuery = nodeQuery.init', () => {
23
+			expect(nodeQuery.getQuery())
24
+				.to.be.deep.equal(qb);
25
+		});
26
+		test('insertBatch throws error', () => {
27
+			expect(() => {
28
+				qb.driver.insertBatch('create_test', []);
29
+			}).to.throw(Error, 'Not Implemented');
30
+		});
31
+
32
+		testRunner(qb);
33
+
34
+		suiteTeardown(() => {
35
+			qb.end();
36
+		});
37
+	});
38
+}

+ 8
- 27
test/adapters/dblite_test.js View File

@@ -4,11 +4,9 @@
4 4
 // Load the test base
5 5
 const reload = require('require-reload')(require);
6 6
 reload.emptyCache();
7
-const fs = require('fs');
8 7
 const testBase = reload('../base');
9 8
 const expect = testBase.expect;
10 9
 const testRunner = testBase.promiseTestRunner;
11
-// let tests = reload('../base/tests');
12 10
 
13 11
 // Load the test config file
14 12
 const config = testBase.config;
@@ -20,33 +18,16 @@ let qb = nodeQuery.getQuery();
20 18
 suite('Dblite adapter tests -', () => {
21 19
 	suiteSetup(done => {
22 20
 		// Set up the sqlite database
23
-		fs.readFile(`${__dirname}/../sql/sqlite.sql`, 'utf8', (err, data) => {
24
-			if (err) {
25
-				return done(err);
26
-			}
27
-
28
-			qb.query(data)
29
-				.then(() => done)
30
-				.catch(e => done(e));
31
-		});
21
+		const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
22
+		const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
23
+
24
+		qb.query(createTest)
25
+			.then(() => qb.query(createJoin))
26
+			.then(() => {
27
+				return done();
28
+			});
32 29
 	});
33 30
 
34
-	// ---------------------------------------------------------------------------
35
-	// Callback Tests
36
-	// ---------------------------------------------------------------------------
37
-
38
-	/* testRunner(qb, (err, result, done) => {
39
-		expect(err).is.not.ok;
40
-		expect(result.rows).is.an('array');
41
-		expect(result.columns).is.an('array');
42
-		expect(result.rowCount()).to.not.be.undefined;
43
-		expect(result.columnCount()).to.not.be.undefined;
44
-		done();
45
-	}); */
46
-
47
-	// ---------------------------------------------------------------------------
48
-	// Promise Tests
49
-	// ---------------------------------------------------------------------------
50 31
 	testRunner(qb);
51 32
 	test('Promise - Select with function and argument in WHERE clause', () => {
52 33
 		let promise = qb.select('id')

test/adapters/mysql2_est.js → test/adapters/mysql2_test.js View File

@@ -22,21 +22,6 @@ suite('Mysql2 adapter tests -', () => {
22 22
 			.to.be.deep.equal(qb);
23 23
 	});
24 24
 
25
-	// --------------------------------------------------------------------------
26
-	// Callback Tests
27
-	// --------------------------------------------------------------------------
28
-	/* testRunner(qb, (err, result, done) => {
29
-		expect(err).is.not.ok;
30
-		expect(result.rows).is.an('array');
31
-		expect(result.columns).is.an('array');
32
-		expect(result.rowCount()).to.not.be.undefined;
33
-		expect(result.columnCount()).to.not.be.undefined;
34
-		done();
35
-	}); */
36
-
37
-	// ---------------------------------------------------------------------------
38
-	// Promise Tests
39
-	// ---------------------------------------------------------------------------
40 25
 	testRunner(qb);
41 26
 	test('Promise - Select with function and argument in WHERE clause', () => {
42 27
 		let promise = qb.select('id')
@@ -70,7 +55,7 @@ suite('Mysql2 adapter tests -', () => {
70 55
 		return expect(qb.insertBatch('create_test', data)).to.be.fulfilled;
71 56
 	});
72 57
 
73
-	suiteTeardown(() => {
58
+	/* suiteTeardown(() => {
74 59
 		qb.end();
75
-	});
60
+	}); */
76 61
 });

+ 0
- 40
test/adapters/node-firebird_test.js View File

@@ -1,40 +0,0 @@
1
-'use strict';
2
-
3
-// Load the test base
4
-const path = require('path');
5
-const reload = require('require-reload')(require);
6
-const testBase = reload('../base');
7
-const expect = testBase.expect;
8
-const testRunner = testBase.promiseTestRunner;
9
-
10
-// Skip on CI
11
-if (process.env.CI || process.env.TRAVIS) {
12
-	return;
13
-}
14
-
15
-// Load the test config file
16
-let adapterName = 'node-firebird';
17
-let Firebird = reload(adapterName);
18
-const config = reload('../config.json')[adapterName];
19
-config.connection.database = path.join(__dirname, config.connection.database);
20
-let nodeQuery = reload('../../lib/NodeQuery')(config);
21
-
22
-let qb = nodeQuery.getQuery();
23
-
24
-suite('Firebird adapter tests -', () => {
25
-	test('nodeQuery.getQuery = nodeQuery.init', () => {
26
-		expect(nodeQuery.getQuery())
27
-			.to.be.deep.equal(qb);
28
-	});
29
-	test('insertBatch throws error', () => {
30
-		expect(() => {
31
-			qb.driver.insertBatch('create_test', []);
32
-		}).to.throw(Error, 'Not Implemented');
33
-	});
34
-
35
-	testRunner(qb);
36
-
37
-	suiteTeardown(() => {
38
-		qb.end();
39
-	});
40
-});

+ 0
- 14
test/adapters/pg_test.js View File

@@ -43,20 +43,6 @@ suite('Pg adapter tests -', () => {
43 43
 		}
44 44
 	});
45 45
 
46
-	// --------------------------------------------------------------------------
47
-	// Callback Tests
48
-	// --------------------------------------------------------------------------
49
-	/* testRunner(qb, (err, result, done) => {
50
-		expect(err).is.not.ok;
51
-		expect(result.rows).is.an('array');
52
-		expect(result.rowCount()).to.not.be.undefined;
53
-		expect(result.columnCount()).to.not.be.undefined;
54
-		done();
55
-	}); */
56
-	
57
-	// --------------------------------------------------------------------------
58
-	// Promise Tests
59
-	// --------------------------------------------------------------------------
60 46
 	testRunner(qb);
61 47
 	test('Promise - Select with function and argument in WHERE clause', () => {
62 48
 		let promise = qb.select('id')

+ 63
- 0
test/adapters/sqlite3_test.js View File

@@ -0,0 +1,63 @@
1
+/* eslint-env node, mocha */
2
+'use strict';
3
+
4
+// Load the test base
5
+const reload = require('require-reload')(require);
6
+reload.emptyCache();
7
+const testBase = reload('../base');
8
+const expect = testBase.expect;
9
+const testRunner = testBase.promiseTestRunner;
10
+
11
+// Load the test config file
12
+const config = testBase.config;
13
+
14
+// Set up the query builder object
15
+let nodeQuery = require('../../lib/NodeQuery')(config.sqlite3);
16
+let qb = nodeQuery.getQuery();
17
+
18
+suite('Sqlite3 adapter tests -', () => {
19
+	suiteSetup(done => {
20
+		// Set up the sqlite database
21
+		const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
22
+		const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
23
+
24
+		qb.query(createTest)
25
+			.then(() => qb.query(createJoin))
26
+			.then(() => {
27
+				return done();
28
+			});
29
+	});
30
+
31
+	testRunner(qb);
32
+	test('Promise - Select with function and argument in WHERE clause', () => {
33
+		let promise = qb.select('id')
34
+			.from('create_test')
35
+			.where('id', 'ABS(-88)')
36
+			.get();
37
+
38
+		expect(promise).to.be.fulfilled;
39
+	});
40
+	test('Promise - Test Insert Batch', () => {
41
+		let data = [
42
+			{
43
+				id: 544,
44
+				key: 3,
45
+				val: Buffer.from('7')
46
+			}, {
47
+				id: 89,
48
+				key: 34,
49
+				val: Buffer.from('10 o\'clock')
50
+			}, {
51
+				id: 48,
52
+				key: 403,
53
+				val: Buffer.from('97')
54
+			}
55
+		];
56
+
57
+		let promise = qb.insertBatch('create_test', data);
58
+		expect(promise).to.be.fulfilled;
59
+	});
60
+	suiteTeardown(() => {
61
+		qb.end();
62
+	});
63
+});

+ 7
- 2
test/base/adapterPromiseTestRunner.js View File

@@ -15,7 +15,7 @@ module.exports = function promiseTestRunner (qb) {
15 15
 		suite(suiteName, () => {
16 16
 			let currentSuite = tests[suiteName];
17 17
 			Object.keys(currentSuite).forEach(testDesc => {
18
-				test(testDesc, () => {
18
+				test(testDesc, done => {
19 19
 					const methodObj = currentSuite[testDesc];
20 20
 					const methodNames = Object.keys(methodObj);
21 21
 					let results = [];
@@ -35,7 +35,12 @@ module.exports = function promiseTestRunner (qb) {
35 35
 					});
36 36
 
37 37
 					let promise = results.pop();
38
-					return expect(promise).to.be.fulfilled;
38
+					promise.then(result => {
39
+						expect(result.rows).is.an('array');
40
+						expect(result.rowCount()).to.not.be.undefined;
41
+						expect(result.columnCount()).to.not.be.undefined;
42
+						return done();
43
+					}).catch(e => done(e));
39 44
 				});
40 45
 			});
41 46
 		});

+ 21
- 21
test/query-parser_test.js View File

@@ -14,30 +14,30 @@ const State = require('../lib/State');
14 14
 // Simulate query builder state
15 15
 let state = new State();
16 16
 
17
-let mixedSet = function mixedSet(letName, valType, key, val) {
18
-    let obj = {};
17
+let mixedSet = function mixedSet (letName, valType, key, val) {
18
+	let obj = {};
19 19
 
20
-    if (helpers.isScalar(key) && !helpers.isUndefined(val)) {
21
-        // Convert key/val pair to a simple object
22
-        obj[key] = val;
23
-    } else if (helpers.isScalar(key) && helpers.isUndefined(val)) {
24
-        // If just a string for the key, and no value, create a simple object with duplicate key/val
25
-        obj[key] = key;
26
-    } else {
27
-        obj = key;
28
-    }
20
+	if (helpers.isScalar(key) && !helpers.isUndefined(val)) {
21
+		// Convert key/val pair to a simple object
22
+		obj[key] = val;
23
+	} else if (helpers.isScalar(key) && helpers.isUndefined(val)) {
24
+		// If just a string for the key, and no value, create a simple object with duplicate key/val
25
+		obj[key] = key;
26
+	} else {
27
+		obj = key;
28
+	}
29 29
 
30
-    Object.keys(obj).forEach(k => {
31
-        // If a single value for the return
32
-        if (['key', 'value'].indexOf(valType) !== -1) {
33
-            let pushVal = (valType === 'key') ? k : obj[k];
34
-            state[letName].push(pushVal);
35
-        } else {
36
-            state[letName][k] = obj[k];
37
-        }
38
-    });
30
+	Object.keys(obj).forEach(k => {
31
+		// If a single value for the return
32
+		if (['key', 'value'].indexOf(valType) !== -1) {
33
+			let pushVal = (valType === 'key') ? k : obj[k];
34
+			state[letName].push(pushVal);
35
+		} else {
36
+			state[letName][k] = obj[k];
37
+		}
38
+	});
39 39
 
40
-    return state[letName];
40
+	return state[letName];
41 41
 };
42 42
 
43 43
 let whereMock = function (key, val) {