Skip to content

Commit a244067

Browse files
Michael AndersonMichael Anderson
Michael Anderson
authored and
Michael Anderson
committed
Adding postgres query into the test for Travis.CI
1 parent 7480231 commit a244067

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ language: node_js
22
node_js:
33
- "8"
44
- "7"
5-
- "6"
5+
- "6"
6+
services: postgresql
7+
before_script:
8+
- psql -c 'create database test;' -U postgres

index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class PostgreSQL {
99
this[m_transaction] = false;
1010
}
1111

12+
/**
13+
* Queries the database
14+
* @param {string} sql
15+
* @returns {Promise<Array<any>>}
16+
*/
1217
query(sql) {
1318
var self = this;
1419
return new Promise((resolve, reject) => {
@@ -24,10 +29,19 @@ class PostgreSQL {
2429
});
2530
}
2631

32+
/**
33+
* Executes the sql on the database
34+
* @param {string} sql
35+
* @returns {Promise<Array<any>>}
36+
*/
2737
execute(sql) {
2838
return this.query(sql);
2939
}
3040

41+
/**
42+
* Closes the database
43+
* @returns {Promise}
44+
*/
3145
close() {
3246
var self = this;
3347
return new Promise((resolve, reject) => {
@@ -102,8 +116,9 @@ class PostgreSQL {
102116
}
103117

104118
/**
105-
*
119+
* Opens a connection
106120
* @param {{Hostname: string, Port: number, Username: string, Password: string, Database: string}} connection
121+
* @returns {PostgreSQL}
107122
*/
108123
function OpenConnection(connection) {
109124
let base = new pg.Client({

test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
var Postgres = require('.');
2+
3+
4+
var Connection = Postgres.open({
5+
Hostname: 'localhost',
6+
Port: 5432,
7+
Username: 'postgres',
8+
Database: 'test'
9+
});
10+
11+
var promises = [];
12+
promises.push(Connection.execute('DROP TABLE IF EXISTS test1; CREATE TABLE test1 (key character varying(255), value character varying(1024));').then(() => {
13+
promises.push(Connection.execute("INSERT INTO test1 VALUES('name', 'Michael Anderson');").then(() => {
14+
promises.push(Connection.query("SELECT * FROM test1 WHERE key = 'name';").then(data => {
15+
if (data.length != 1) {
16+
console.error('Invalid data returned');
17+
Connection.execute('DROP TABLE test1;').then(() => {
18+
Connection.close().then(() => {
19+
process.exit(1);
20+
});
21+
})
22+
}
23+
}));
24+
}));
25+
}));
26+
27+
Promise.all(promises).then(() => {
28+
Connection.execute('DROP TABLE IF EXISTS test1;').then(() => {
29+
Connection.close().then(() => {
30+
process.exit(0);
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)