From 514630bdcd3a6529a594b78baae351574d0d1123 Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sun, 14 Apr 2024 15:57:11 +0500 Subject: [PATCH] feat: query to fetch unique columns Signed-off-by: Muhammad Aaqil --- lib/sql.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/sql.js b/lib/sql.js index 4f07a6bc..cdd325a9 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -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); +};