Skip to content

Commit d52cdcf

Browse files
committedJul 10, 2023
fix(switchDatabase): scope configuration not working with schema
Signed-off-by: Jéssica Schissato <jessicaschissato@gmail.com>
1 parent b64a02a commit d52cdcf

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,18 @@ var PgDriver = Base.extend({
132132
'Ignore database option, not available with postgres. Use schema instead!'
133133
);
134134
this.runSql(
135-
util.format('SET search_path TO `%s`', options.database),
135+
util.format('SET search_path TO %s', options.database),
136+
callback
137+
);
138+
} else if (typeof options.schema === 'string') {
139+
this.schema = options.schema
140+
this.runSql(
141+
util.format('SET search_path TO %s', options.schema),
136142
callback
137143
);
138144
}
139145
} else if (typeof options === 'string') {
140-
this.runSql(util.format('SET search_path TO `%s`', options), callback);
146+
this.runSql(util.format('SET search_path TO %s', options), callback);
141147
} else callback(null);
142148
},
143149

‎test/pg_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,32 @@ vows
11571157
}
11581158
}
11591159
})
1160+
.addBatch({
1161+
switchDatabase: {
1162+
topic: function () {
1163+
db.switchDatabase({ schema: 'test_schema2' }, this.callback);
1164+
},
1165+
1166+
'has search path': {
1167+
topic: function () {
1168+
db.runSql('SHOW search_path', this.callback);
1169+
},
1170+
1171+
'containing the new schema': function (err, result) {
1172+
assert.isNull(err);
1173+
var rows = result.rows;
1174+
assert.isNotNull(rows);
1175+
assert.strictEqual(rows.length, 1);
1176+
var row = rows[0];
1177+
assert.strictEqual(row.search_path, 'test_schema2');
1178+
}
1179+
},
1180+
1181+
teardown: function () {
1182+
db.switchDatabase({ schema: config.schema }, this.callback);
1183+
}
1184+
}
1185+
})
11601186
.export(module);
11611187

11621188
function findByName (columns, name) {

0 commit comments

Comments
 (0)
Please sign in to comment.