Skip to content

Commit

Permalink
fix(switchDatabase): scope configuration not working with schema
Browse files Browse the repository at this point in the history
Signed-off-by: Jéssica Schissato <jessicaschissato@gmail.com>
  • Loading branch information
jessicaschissato committed Jul 10, 2023
1 parent b64a02a commit d52cdcf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ var PgDriver = Base.extend({
'Ignore database option, not available with postgres. Use schema instead!'
);
this.runSql(
util.format('SET search_path TO `%s`', options.database),
util.format('SET search_path TO %s', options.database),
callback
);
} else if (typeof options.schema === 'string') {
this.schema = options.schema
this.runSql(
util.format('SET search_path TO %s', options.schema),
callback
);
}
} else if (typeof options === 'string') {
this.runSql(util.format('SET search_path TO `%s`', options), callback);
this.runSql(util.format('SET search_path TO %s', options), callback);
} else callback(null);
},

Expand Down
26 changes: 26 additions & 0 deletions test/pg_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,32 @@ vows
}
}
})
.addBatch({
switchDatabase: {
topic: function () {
db.switchDatabase({ schema: 'test_schema2' }, this.callback);
},

'has search path': {
topic: function () {
db.runSql('SHOW search_path', this.callback);
},

'containing the new schema': function (err, result) {
assert.isNull(err);
var rows = result.rows;
assert.isNotNull(rows);
assert.strictEqual(rows.length, 1);
var row = rows[0];
assert.strictEqual(row.search_path, 'test_schema2');
}
},

teardown: function () {
db.switchDatabase({ schema: config.schema }, this.callback);
}
}
})
.export(module);

function findByName (columns, name) {
Expand Down

0 comments on commit d52cdcf

Please sign in to comment.