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
6 changes: 3 additions & 3 deletions deps/juggler-v3/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

'use strict';

var should = require('../../test/init');
var juggler = require('loopback-datasource-juggler');
var name = require('./package.json').name;
const should = require('../../test/init');
const juggler = require('loopback-datasource-juggler');
const name = require('./package.json').name;

describe(name, function() {
before(function() {
Expand Down
6 changes: 3 additions & 3 deletions deps/juggler-v4/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

'use strict';

var should = require('../../test/init');
var juggler = require('loopback-datasource-juggler');
var name = require('./package.json').name;
const should = require('../../test/init');
const juggler = require('loopback-datasource-juggler');
const name = require('./package.json').name;

describe(name, function() {
before(function() {
Expand Down
12 changes: 6 additions & 6 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// License text available at https://opensource.org/licenses/Artistic-2.0

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

var config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;
const config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;

var ds = new DataSource(require('../'), config);
const ds = new DataSource(require('../'), config);

function show(err, models) {
if (err) {
Expand All @@ -26,10 +26,10 @@ ds.discoverModelProperties('product', show);

// ds.discoverModelProperties('INVENTORY_VIEW', {owner: 'STRONGLOOP'}, show);

ds.discoverPrimaryKeys('inventory', show);
ds.discoverForeignKeys('inventory', show);
ds.discoverPrimaryKeys('inventory', show);
ds.discoverForeignKeys('inventory', show);

ds.discoverExportedForeignKeys('product', show);
ds.discoverExportedForeignKeys('product', show);

/*

Expand Down
14 changes: 7 additions & 7 deletions example/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
// License text available at https://opensource.org/licenses/Artistic-2.0

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

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

var config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;
const config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;

var ds = new DataSource(require('../'), config);
const ds = new DataSource(require('../'), config);

// Define a account model
var Account = ds.createModel('account', {
const Account = ds.createModel('account', {
name: String,
emails: [String],
age: Number},
{strict: true});
{strict: true});

ds.automigrate('account', function(err) {
// Create two instances
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// License text available at https://opensource.org/licenses/Artistic-2.0

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

module.exports = require('./lib/postgresql.js');
52 changes: 26 additions & 26 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
// License text available at https://opensource.org/licenses/Artistic-2.0

'use strict';
var g = require('strong-globalize')();
const g = require('strong-globalize')();

module.exports = mixinDiscovery;

function mixinDiscovery(PostgreSQL) {
var async = require('async');
const async = require('async');

PostgreSQL.prototype.paginateSQL = function(sql, orderBy, options) {
options = options || {};
var limit = '';
let limit = '';
if (options.offset || options.skip || options.limit) {
limit = ' OFFSET ' + (options.offset || options.skip || 0); // Offset starts from 0
if (options.limit) {
Expand All @@ -32,8 +32,8 @@ function mixinDiscovery(PostgreSQL) {
* @returns {string} The sql statement
*/
PostgreSQL.prototype.buildQueryTables = function(options) {
var sqlTables = null;
var owner = options.owner || options.schema;
let sqlTables = null;
const owner = options.owner || options.schema;

if (options.all && !owner) {
sqlTables = this.paginateSQL('SELECT \'table\' AS "type", table_name AS "name", table_schema AS "owner"'
Expand All @@ -44,7 +44,7 @@ function mixinDiscovery(PostgreSQL) {
} else {
sqlTables = this.paginateSQL('SELECT \'table\' AS "type", table_name AS "name",'
+ ' table_schema AS "owner" FROM information_schema.tables WHERE table_schema=current_schema()',
'table_name', options);
'table_name', options);
}
return sqlTables;
};
Expand All @@ -55,22 +55,22 @@ function mixinDiscovery(PostgreSQL) {
* @returns {string} The sql statement
*/
PostgreSQL.prototype.buildQueryViews = function(options) {
var sqlViews = null;
let sqlViews = null;
if (options.views) {
var owner = options.owner || options.schema;
const owner = options.owner || options.schema;

if (options.all && !owner) {
sqlViews = this.paginateSQL('SELECT \'view\' AS "type", table_name AS "name",'
+ ' table_schema AS "owner" FROM information_schema.views',
'table_schema, table_name', options);
'table_schema, table_name', options);
} else if (owner) {
sqlViews = this.paginateSQL('SELECT \'view\' AS "type", table_name AS "name",'
+ ' table_schema AS "owner" FROM information_schema.views WHERE table_schema=\'' + owner + '\'',
'table_schema, table_name', options);
'table_schema, table_name', options);
} else {
sqlViews = this.paginateSQL('SELECT \'view\' AS "type", table_name AS "name",'
+ ' current_schema() AS "owner" FROM information_schema.views',
'table_name', options);
'table_name', options);
}
}
return sqlViews;
Expand Down Expand Up @@ -117,9 +117,9 @@ function mixinDiscovery(PostgreSQL) {
* @param {Function} [cb] The callback function
*/
PostgreSQL.prototype.discoverModelProperties = function(table, options, cb) {
var self = this;
var args = self.getArgs(table, options, cb);
var schema = args.schema;
const self = this;
const args = self.getArgs(table, options, cb);
let schema = args.schema;

table = args.table;
options = args.options;
Expand All @@ -131,8 +131,8 @@ function mixinDiscovery(PostgreSQL) {
self.setDefaultOptions(options);
cb = args.cb;

var sql = self.buildQueryColumns(schema, table);
var callback = function(err, results) {
const sql = self.buildQueryColumns(schema, table);
const callback = function(err, results) {
if (err) {
cb(err, results);
} else {
Expand Down Expand Up @@ -164,23 +164,23 @@ function mixinDiscovery(PostgreSQL) {
* @returns {String} The sql statement
*/
PostgreSQL.prototype.buildQueryColumns = function(owner, table) {
var sql = null;
let sql = null;
if (owner) {
sql = this.paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
+ 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
+ ' FROM information_schema.columns'
+ ' WHERE table_schema=\'' + owner + '\''
+ (table ? ' AND table_name=\'' + table + '\'' : ''),
'table_name, ordinal_position', {});
'table_name, ordinal_position', {});
} else {
sql = this.paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName",'
+ ' column_name AS "columnName",'
+ ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
+ ' FROM information_schema.columns'
+ (table ? ' WHERE table_name=\'' + table + '\'' : ''),
'table_name, ordinal_position', {});
'table_name, ordinal_position', {});
}
return sql;
};
Expand All @@ -193,7 +193,7 @@ function mixinDiscovery(PostgreSQL) {
*
*/

// http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)
// http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)

/*
SELECT kc.table_schema AS "owner", kc.table_name AS "tableName",
Expand All @@ -212,7 +212,7 @@ function mixinDiscovery(PostgreSQL) {
* @returns {string}
*/
PostgreSQL.prototype.buildQueryPrimaryKeys = function(owner, table) {
var sql = 'SELECT kc.table_schema AS "owner", '
let sql = 'SELECT kc.table_schema AS "owner", '
+ 'kc.table_name AS "tableName", kc.column_name AS "columnName",'
+ ' kc.ordinal_position AS "keySeq",'
+ ' kc.constraint_name AS "pkName" FROM'
Expand Down Expand Up @@ -260,7 +260,7 @@ function mixinDiscovery(PostgreSQL) {
* @returns {string}
*/
PostgreSQL.prototype.buildQueryForeignKeys = function(owner, table) {
var sql =
let sql =
'SELECT tc.table_schema AS "fkOwner", tc.constraint_name AS "fkName", tc.table_name AS "fkTableName",'
+ ' kcu.column_name AS "fkColumnName", kcu.ordinal_position AS "keySeq",'
+ ' ccu.table_schema AS "pkOwner",'
Expand Down Expand Up @@ -298,7 +298,7 @@ function mixinDiscovery(PostgreSQL) {
* @returns {string}
*/
PostgreSQL.prototype.buildQueryExportedForeignKeys = function(owner, table) {
var sql = 'SELECT kcu.constraint_name AS "fkName", kcu.table_schema AS "fkOwner", kcu.table_name AS "fkTableName",'
let sql = 'SELECT kcu.constraint_name AS "fkName", kcu.table_schema AS "fkOwner", kcu.table_name AS "fkTableName",'
+ ' kcu.column_name AS "fkColumnName", kcu.ordinal_position AS "keySeq",'
+ ' (SELECT constraint_name'
+ ' FROM information_schema.table_constraints tc2'
Expand Down Expand Up @@ -328,8 +328,8 @@ function mixinDiscovery(PostgreSQL) {
*/

PostgreSQL.prototype.buildPropertyType = function(columnDefinition, dataLength) {
var mysqlType = columnDefinition.dataType;
var type = mysqlType.toUpperCase();
const mysqlType = columnDefinition.dataType;
const type = mysqlType.toUpperCase();
switch (type) {
case 'BOOLEAN':
return 'Boolean';
Expand Down Expand Up @@ -369,7 +369,7 @@ function mixinDiscovery(PostgreSQL) {
*/
PostgreSQL.prototype.discoverModelIndexes = function(model, cb) {
this.getTableStatus(model, function(err, fields, indexes) {
var indexData = {};
const indexData = {};
indexes.forEach(function(index) {
indexData[index.name] = index;
delete index.name;
Expand Down
Loading