forked from martintajur/node-mysql-activerecord
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #18. Added a generic config file for test tests containing mock…
… credentials and updated all files using credentials to use that instead.
- Loading branch information
1 parent
f908251
commit a41f9d9
Showing
16 changed files
with
198 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const should = require('chai').should(); | ||
const expect = require('chai').expect; | ||
const configs = require('configs'); | ||
|
||
const QueryBuilder = require('../../index.js'); | ||
const my_pool = new QueryBuilder(configs.mysql, 'mysql', 'pool'); | ||
const ms_pool = new QueryBuilder(configs.mssql, 'mssql', 'pool'); | ||
|
||
describe('Multiple Drivers', () => { | ||
it('should not get confused between pools from different drivers', done => { | ||
pool.get_connection(qb => { | ||
qb.limit(1).delete('cities', (err, result) => { | ||
qb.select(['city', 'state_code']).from('cities').limit(1).get((err2, result2) => { | ||
qb.release(); | ||
expect(err, 'should not error on delete').to.not.be.instanceof(Error); | ||
expect(result.affectedRows, 'one record should be deleted').to.be.eql(1); | ||
expect(err2, 'should not error on select').to.not.be.instanceof(Error); | ||
expect(result2.length, 'should have one result').to.be.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const configs = { | ||
mysql: { | ||
host: '127.0.0.1', | ||
database: 'mock_db', | ||
user: 'travis', | ||
version: '2.5.4', | ||
port: 3306, | ||
debug: false, | ||
}, | ||
mssql: { | ||
host: 'localhost', | ||
database: 'mock_db', | ||
user: 'travis', | ||
password: 'Password123', | ||
version: '4.1.0', | ||
port: 1433, | ||
options: { | ||
encrypt: false | ||
} | ||
}, | ||
}; | ||
module.exports = configs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const should = require('chai').should(); | ||
const expect = require('chai').expect; | ||
const settings = require('../configs').mssql; | ||
const QueryBuilder = require('../../index.js'); | ||
const pool1 = new QueryBuilder(settings, 'mssql', 'pool'); | ||
const pool2 = new QueryBuilder(Object.assign({}, settings, {database: 'mock_db2'}), 'mssql', 'pool'); | ||
let pool1_settings, pool2_settings; | ||
|
||
const compare_connections = (done) => { | ||
try { | ||
const db1 = pool1_settings.connection_settings.options.database; | ||
const db2 = pool2_settings.connection_settings.options.database; | ||
db1.should.not.be.eql(db2); | ||
done(); | ||
} catch(e) { | ||
done(e); | ||
} | ||
}; | ||
|
||
describe('MSSQL: Multiple Pools', () => { | ||
it('should not get confused by what pool settings to use', done => { | ||
let connections_established = 0; | ||
|
||
pool1.get_connection(qb1 => { | ||
pool1_settings = qb1.connection_settings(); | ||
connections_established++; | ||
if (connections_established >= 2) compare_connections(done); | ||
}); | ||
pool2.get_connection(qb2 => { | ||
pool2_settings = qb2.connection_settings(); | ||
connections_established++; | ||
if (connections_established >= 2) compare_connections(done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO [cities2] VALUES ('Aaronsburg','PA'),('Abbeville','AL'),('Abbeville','GA'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const should = require('chai').should(); | ||
const expect = require('chai').expect; | ||
const settings = require('../configs').mysql; | ||
const QueryBuilder = require('../../index.js'); | ||
const pool1 = new QueryBuilder(settings, 'mysql', 'pool'); | ||
const pool2 = new QueryBuilder(Object.assign({}, settings, {database: 'mock_db2'}), 'mysql', 'pool'); | ||
let pool1_settings, pool2_settings; | ||
|
||
const compare_connections = (done) => { | ||
try { | ||
const db1 = pool1_settings.database; | ||
const db2 = pool2_settings.database; | ||
db1.should.not.be.eql(db2); | ||
done(); | ||
} catch(e) { | ||
done(e); | ||
} | ||
}; | ||
|
||
describe('MySQL: Multiple Pools', () => { | ||
it('should not get confused by what pool settings to use', done => { | ||
let connections_established = 0; | ||
|
||
pool1.get_connection(qb1 => { | ||
pool1_settings = qb1.connection_settings(); | ||
connections_established++; | ||
if (connections_established >= 2) compare_connections(done); | ||
}); | ||
pool2.get_connection(qb2 => { | ||
pool2_settings = qb2.connection_settings(); | ||
connections_established++; | ||
if (connections_established >= 2) compare_connections(done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#!/usr/bin/env bash | ||
mysql -uroot -e "CREATE DATABSE IF NOT EXISTS mock_db;" | ||
mysql -uroot -e "CREATE USER IF NOT EXISTS 'travis'@'localhost';" | ||
mysql -uroot -e "GRANT ALL ON `mock_db`.* TO 'travis'@'localhost';" | ||
mysql -utravis mock_db < ./test/mysql/mock_data.sql | ||
mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS mock_db;" | ||
mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS mock_db2;" | ||
mysql -uroot -p -e "CREATE USER IF NOT EXISTS 'travis'@'localhost';" | ||
mysql -uroot -p -e "GRANT ALL ON mock_db.* TO 'travis'@'localhost';" | ||
mysql -uroot -p -e "GRANT ALL ON mock_db2.* TO 'travis'@'localhost';" | ||
mysql -uroot -p mock_db -e "DROP TABLE IF EXISTS cities;" | ||
mysql -uroot -p mock_db2 -e "DROP TABLE IF EXISTS cities2;" | ||
mysql -utravis mock_db < ./mock_data.sql | ||
mysql -utravis mock_db2 < ./mock_data2.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
-- MySQL dump 10.14 Distrib 5.5.40-MariaDB, for Linux (x86_64) | ||
-- | ||
-- Host: localhost Database: mock_db2 | ||
-- ------------------------------------------------------ | ||
-- Server version 5.5.40-MariaDB | ||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8 */; | ||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
|
||
-- | ||
-- Table structure for table `cities` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `cities2`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `cities2` ( | ||
`city` varchar(50) NOT NULL, | ||
`state_code` char(2) NOT NULL, | ||
KEY `idx_state_code` (`state_code`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `cities2` | ||
-- | ||
|
||
LOCK TABLES `cities2` WRITE; | ||
/*!40000 ALTER TABLE `cities2` DISABLE KEYS */; | ||
INSERT INTO `cities2` VALUES ('Aaronsburg','PA'),('Abbeville','AL'),('Abbeville','GA'); | ||
/*!40000 ALTER TABLE `cities2` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
|
||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |