Skip to content

Commit

Permalink
feat: fetch index information for models
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
  • Loading branch information
aaqilniz committed Oct 15, 2024
1 parent b604aa0 commit 3931fb6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {

columns.forEach(function(item) {
const propName = nameMapper('column', item.columnName);
schema.properties[propName] = {
const propertyDetails = {
type: item.type,
required: !item.generated && (item.nullable === 'N' || item.nullable === 'NO' ||
item.nullable === 0 || item.nullable === false),
Expand All @@ -1726,13 +1726,26 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
precision: item.dataPrecision,
scale: item.dataScale,
generated: item.generated || false,
};
}

Check failure on line 1729 in lib/datasource.js

View workflow job for this annotation

GitHub Actions / Code Lint

Missing semicolon
if (
item.indexType === 'BTREE' &&
item.indexName !== 'PRIMARY' &&

Check failure on line 1732 in lib/datasource.js

View workflow job for this annotation

GitHub Actions / Code Lint

Multiple spaces found before '&&'
!item.isForeignKey
) {
propertyDetails.index = {unique: true}

Check failure on line 1735 in lib/datasource.js

View workflow job for this annotation

GitHub Actions / Code Lint

Missing semicolon
}

Check failure on line 1737 in lib/datasource.js

View workflow job for this annotation

GitHub Actions / Code Lint

Trailing spaces not allowed
if (pks[item.columnName]) {
schema.properties[propName].id = pks[item.columnName];
propertyDetails[propName].id = pks[item.columnName];
}
if (uniqueKeys.includes(propName)) {
schema.properties[propName]['index'] = {unique: true};
if (
uniqueKeys.includes(propName) &&
propertyDetails[propName]['index'] === undefined
) {
propertyDetails[propName]['index'] = {unique: true};
}

schema.properties[propName] = propertyDetails;
const dbSpecific = schema.properties[propName][dbType] = {
columnName: item.columnName,
dataType: item.dataType,
Expand Down

0 comments on commit 3931fb6

Please sign in to comment.