orange-dragonfly-orm-model-to-sql 0.7.6 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/mysql.js +5 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-dragonfly-orm-model-to-sql",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "Converts Orange Dragonfly validator model to SQL CREATE TABLE syntax",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/mysql.js CHANGED
@@ -119,12 +119,14 @@ class OrangeDragonflyORMSchemaToMySQL {
119
119
  _convertIndexesToSql(indexes) {
120
120
  const queries = []
121
121
  for (let [index, indexType] of Object.entries(indexes)) {
122
+ const [table] = index.split('/')[0].split('.')
123
+ const cols = index.split('/').map((v) => v.split('.')[1])
122
124
  if (indexType === 'unique') {
123
- queries.push(`CREATE UNIQUE INDEX uq_${index.replaceAll('.', '__').replaceAll('/', '___')} ON ${index.split('/')[0].split('.')[0]} (${index.split('/').map(v => v.split('.')[1]).join(', ')});`)
125
+ queries.push(`CREATE UNIQUE INDEX uq_${table}__${cols.join('__')} ON ${table} (${cols.join(', ')});`)
124
126
  } else if (indexType === 'asc') {
125
- queries.push(`CREATE INDEX ix_${index.replace('.', '__')} ON ${index.split('.')[0]} (${index.split('.')[1]});`)
127
+ queries.push(`CREATE INDEX ix_${table}__${cols.join('__')} ON ${table} (${cols.join(', ')});`)
126
128
  } else if (indexType === 'fulltext') {
127
- queries.push(`CREATE FULLTEXT INDEX ft_${index.replaceAll('.', '__').replaceAll('/', '___')} ON ${index.split('/')[0].split('.')[0]} (${index.split('/').map(v => v.split('.')[1]).join(', ')});`)
129
+ queries.push(`CREATE FULLTEXT INDEX ft_${table}__${cols.join('__')} ON ${table} (${cols.join(', ')});`)
128
130
  } else {
129
131
  throw new Error(`Unknown index type: ${indexType}`)
130
132
  }