Skip to content

Commit f075636

Browse files
committed
logging connections, no id, specs use docker dbs
1 parent 26159e7 commit f075636

17 files changed

+1388
-1278
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ services:
88
- mysql
99
before_script:
1010
- mysql -e 'create database sworm;'
11-
- psql -c 'create database sworm;' -U postgres

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '2'
2+
3+
services:
4+
oracle:
5+
image: wnameless/oracle-xe-11g
6+
ports:
7+
- "1521:1521"
8+
mysql:
9+
image: mysql
10+
ports:
11+
- "3306:3306"
12+
environment:
13+
- MYSQL_ROOT_PASSWORD=password
14+
postgres:
15+
image: postgres
16+
ports:
17+
- "5432:5432"
18+
environment:
19+
- POSTGRES_PASSWORD=password

index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ var pgDriver = require("./pgDriver");
55
var mysqlDriver = require("./mysqlDriver");
66
var oracleDriver = require("./oracleDriver");
77
var sqliteDriver = require("./sqliteDriver");
8-
var debugQuery = require("debug")("sworm");
8+
var debug = require("debug")("sworm");
99
var debugResults = require("debug")("sworm:results");
10+
var redactConfig = require('./redactConfig');
1011

1112
var rowBase = function() {
1213
function fieldsForObject(obj) {
@@ -294,7 +295,7 @@ exports.db = function(config) {
294295
id: id,
295296
db: this,
296297
foreignKeyFor: foreignKeyFor,
297-
compoundKey: id instanceof Array
298+
compoundKey: id == false || id instanceof Array
298299
};
299300

300301
var modelPrototype = _.extend(Object.create(rowBase), modelConfig);
@@ -351,17 +352,17 @@ exports.db = function(config) {
351352
},
352353

353354
logError: function(query, params, error) {
354-
debugQuery(query, params, error);
355+
debug(query, params, error);
355356
},
356357

357358
logResults: function(query, params, results, options) {
358359
if (typeof this.log == 'function') {
359360
return this.log(query, params, results, options);
360361
} else {
361362
if (params) {
362-
debugQuery(query, params);
363+
debug(query, params);
363364
} else {
364-
debugQuery(query);
365+
debug(query);
365366
}
366367

367368
if (options && options.insert) {
@@ -402,7 +403,10 @@ exports.db = function(config) {
402403
}
403404

404405
this.driver = driver();
406+
407+
debug('connecting to', redactConfig(_config));
405408
this.connection = this.driver.connect(_config).then(function () {
409+
debug('connected to', redactConfig(_config));
406410
function finishRunningBeginSession() {
407411
self.runningBeginSession = false;
408412
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"debug": "2.2.0",
11+
"redact-url": "0.3.1",
1112
"underscore": "1.8.1"
1213
},
1314
"devDependencies": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ var createEntity = db.model(options);
260260
`options` can contain the following:
261261
262262
* `table` (`undefined`) the name of the table to save entities to
263-
* `id` (`'id'`) the name of the identity column. This can be an array of id columns for compound keys.
263+
* `id` (`'id'`) the name of the identity column. This can be an array of id columns for compound keys, or `false` if there is no id column.
264264
* `foreignKeyFor` a function that returns a foreign key field name for a member (see [Relationships](#relationships)), defaults to:
265265
266266
```js

redactConfig.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var redactUrl = require('./redactUrl');
2+
3+
module.exports = function(config) {
4+
var copy = JSON.parse(JSON.stringify(config));
5+
if (copy.url) {
6+
copy.url = redactUrl(copy.url, '********');
7+
}
8+
9+
if (copy.config && copy.config.password) {
10+
copy.config.password = '********';
11+
}
12+
13+
return copy;
14+
};

redactUrl.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var urlUtils = require('url');
2+
3+
module.exports = function(url, replacement) {
4+
var urlComponents = urlUtils.parse(url);
5+
if (urlComponents.auth) {
6+
urlComponents.auth = urlComponents.auth.replace(/:.*/, ':' + replacement);
7+
8+
return urlUtils.format(urlComponents);
9+
} else {
10+
return url;
11+
}
12+
};

0 commit comments

Comments
 (0)