Skip to content

Commit 0dd85d4

Browse files
aaqilnizdhmlau
authored andcommitted
feat: query to fetch unique columns
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent bb65262 commit 0dd85d4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/sql.js

+29
Original file line numberDiff line numberDiff line change
@@ -2151,3 +2151,32 @@ SQLConnector.prototype.setNullableProperty = function(property) {
21512151
throw new Error(g.f('{{setNullableProperty}} must be implemented by' +
21522152
'the connector'));
21532153
};
2154+
2155+
/**
2156+
* Build sql to discover properties with unique index
2157+
*/
2158+
SQLConnector.prototype.buildQueryUniqueKeys = function(schema, table) {
2159+
throw new Error(g.f('{{buildQueryUniqueKeys}} must be implemented by the connector'));
2160+
};
2161+
2162+
/**
2163+
* Discover properties with unique index
2164+
* @param {String} table The table name
2165+
* @param {Object} options The options for discovery
2166+
* @param {Function} [cb] The callback function
2167+
*/
2168+
SQLConnector.prototype.discoverUniqueKeys = function(table, options, cb) {
2169+
const self = this;
2170+
const args = self.getArgs(table, options, cb);
2171+
let schema = args.schema || args.owner;
2172+
2173+
if (typeof (self.getDefaultSchema) === 'function' && !schema) {
2174+
schema = self.getDefaultSchema();
2175+
}
2176+
table = args.table;
2177+
options = args.options;
2178+
cb = args.cb;
2179+
2180+
const sql = self.buildQueryUniqueKeys(schema, table);
2181+
this.execute(sql, cb);
2182+
};

0 commit comments

Comments
 (0)