Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ results

npm-debug.log
docs

!intl/
intl/*
!intl/en/
2 changes: 2 additions & 0 deletions example/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Node module: loopback-connector-postgresql
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
var SG = require('strong-globalize');
var g = SG();

var DataSource = require('loopback-datasource-juggler').DataSource;

Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

var SG = require('strong-globalize');
SG.SetRootDir(__dirname);

module.exports = require('./lib/postgresql.js');
9 changes: 9 additions & 0 deletions intl/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"a0078d732b2dbabf98ed2efcdb55b402": "{{table}} is a required string argument: {0}",
"fc3b8fde2e08c74cafb55f25c4841a4b": "{{options}} must be an object: {0}",
"16cbc6b164ad51e193938132d059ce3f": "{{Index keys}} definition appears to be invalid: {0}",
"80a32e80cbed65eba2103201a7c94710": "Model not found: {0}",
"1752695ee513f17d70e82753c0b6ef1a": "{{PostgreSQL}} regex syntax does not respect the {{`m`}} flag",
"b811d24a7d249e0aedff11523626fbfd": "{{Placeholder}} for identifiers is not supported",
"bfe8fb104f017b365e64da57ed975db6": "{{PostgreSQL}} regex syntax does not respect the {{`g`}} flag"
}
7 changes: 5 additions & 2 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

var SG = require('strong-globalize');
var g = SG();

module.exports = mixinDiscovery;

function mixinDiscovery(PostgreSQL) {
Expand Down Expand Up @@ -119,15 +122,15 @@ function mixinDiscovery(PostgreSQL) {
*/
function getArgs(table, options, cb) {
if ('string' !== typeof table || !table) {
throw new Error('table is a required string argument: ' + table);
throw new Error(g.f('{{table}} is a required string argument: %s' + table));
}
options = options || {};
if (!cb && 'function' === typeof options) {
cb = options;
options = {};
}
if (typeof options !== 'object') {
throw new Error('options must be an object: ' + options);
throw new Error(g.f('{{options}} must be an object: %s' + options));
}
return {
owner: options.owner || options.schema,
Expand Down
7 changes: 5 additions & 2 deletions lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

var SG = require('strong-globalize');
var g = SG();
var async = require('async');

module.exports = mixinMigration;

function mixinMigration(PostgreSQL) {
Expand Down Expand Up @@ -92,7 +95,7 @@ function mixinMigration(PostgreSQL) {
async.each(models, function(model, done) {
if (!(model in self._models)) {
return process.nextTick(function() {
done(new Error('Model not found: ' + model));
done(new Error(g.f('Model not found: %s' + model)));
});
}
self.getTableStatus(model, function(err, fields, indexes) {
Expand Down Expand Up @@ -821,7 +824,7 @@ function mixinMigration(PostgreSQL) {
return column && [column, 'ASC'];
});
} else {
throw Error('Index keys definition appears to be invalid: ', keys);
throw Error(g.f('{{Index keys}} definition appears to be invalid: %s', keys));
}

return result;
Expand Down
8 changes: 5 additions & 3 deletions lib/postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/*!
* PostgreSQL connector for LoopBack
*/
var SG = require('strong-globalize');
var g = SG();
var postgresql = require('pg');
var SqlConnector = require('loopback-connector').SqlConnector;
var ParameterizedSQL = SqlConnector.ParameterizedSQL;
Expand Down Expand Up @@ -385,10 +387,10 @@ PostgreSQL.prototype.buildExpression = function(columnName, operator,
[operatorValue]);
case 'regexp':
if (operatorValue.global)
console.warn('PostgreSQL regex syntax does not respect the `g` flag');
g.warn('{{PostgreSQL}} regex syntax does not respect the {{`g`}} flag');

if (operatorValue.multiline)
console.warn('PostgreSQL regex syntax does not respect the `m` flag');
g.warn('{{PostgreSQL}} regex syntax does not respect the {{`m`}} flag');

var regexOperator = operatorValue.ignoreCase ? ' ~* ?' : ' ~ ?';
return new ParameterizedSQL(columnName + regexOperator,
Expand Down Expand Up @@ -499,7 +501,7 @@ PostgreSQL.prototype.toColumnValue = function(prop, val) {
* @returns {String} The place holder
*/
PostgreSQL.prototype.getPlaceholderForIdentifier = function(key) {
throw new Error('Placeholder for identifiers is not supported');
throw new Error(g.f('{{Placeholder}} for identifiers is not supported'));
};

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"async": "^0.9.0",
"debug": "^2.1.1",
"loopback-connector": "^2.1.0",
"pg": "^6.0.0"
"pg": "^6.0.0",
"strong-globalize": "^2.5.8"
},
"devDependencies": {
"bluebird": "^2.9.12",
Expand Down