Skip to content

Commit

Permalink
feat: query to fetch unique columns
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <[email protected]>
  • Loading branch information
aaqilniz committed Apr 15, 2024
1 parent 012c2de commit 514630b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2105,3 +2105,32 @@ SQLConnector.prototype.setNullableProperty = function(property) {
throw new Error(g.f('{{setNullableProperty}} must be implemented by' +
'the connector'));
};

/**
* Build sql to discover properties with unique index
*/
SQLConnector.prototype.buildQueryUniqueKeys = function(schema, table) {
throw new Error(g.f('{{buildQueryUniqueKeys}} must be implemented by the connector'));
};

/**
* Discover properties with unique index
* @param {String} table The table name
* @param {Object} options The options for discovery
* @param {Function} [cb] The callback function
*/
SQLConnector.prototype.discoverUniqueKeys = function(table, options, cb) {
const self = this;
const args = self.getArgs(table, options, cb);
let schema = args.schema || args.owner;

if (typeof (self.getDefaultSchema) === 'function' && !schema) {
schema = self.getDefaultSchema();
}
table = args.table;
options = args.options;
cb = args.cb;

const sql = self.buildQueryUniqueKeys(schema, table);
this.execute(sql, cb);
};

0 comments on commit 514630b

Please sign in to comment.