neopg 2.2.0 → 2.2.1

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.
package/lib/SchemaSync.js CHANGED
@@ -299,7 +299,7 @@ class SchemaSync {
299
299
  continue;
300
300
  }
301
301
 
302
- const idxCols = indname.split(',').map(s=>s.trim()).filter(s=>s);
302
+ let idxCols = Array.isArray(indname) ? indname : indname.split(',').map(s=>s.trim()).filter(s=>s);
303
303
  const idxNamePart = idxCols.join('_');
304
304
  const targetIdxName = `${def.tableName}_${idxNamePart}_idx`;
305
305
 
@@ -329,7 +329,7 @@ class SchemaSync {
329
329
  for (const indname of uniques) {
330
330
  if (!this._checkColumnsExist(indname, def)) continue;
331
331
 
332
- const idxCols = indname.split(',').map(s=>s.trim()).filter(s=>s);
332
+ let idxCols = Array.isArray(indname) ? indname : indname.split(',').map(s=>s.trim()).filter(s=>s);
333
333
 
334
334
  // 监测是否等于主键
335
335
  if (pkSet.size > 0 && idxCols.length === pkSet.size) {
@@ -372,7 +372,7 @@ class SchemaSync {
372
372
  const uniques = def.unique || [];
373
373
 
374
374
  const keepSet = new Set();
375
- const makeName = (n) => `${tableName}_${n.split(',').map(x=>x.trim()).filter(x=>x).join('_')}_idx`;
375
+ const makeName = (n) => `${tableName}_${Array.isArray(n) ? n.map(x=>x.trim()).join('_') : n.split(',').map(x=>x.trim()).filter(x=>x).join('_')}_idx`;
376
376
 
377
377
  indices.forEach(n => keepSet.add(makeName(n)));
378
378
  uniques.forEach(n => keepSet.add(makeName(n)));
@@ -483,7 +483,13 @@ class SchemaSync {
483
483
  }
484
484
 
485
485
  static _checkColumnsExist(colsStr, def) {
486
- const parts = colsStr.split(',').map(x=>x.trim()).filter(x=>x);
486
+ let parts;
487
+ if (Array.isArray(colsStr)) {
488
+ parts = colsStr;
489
+ } else {
490
+ parts = colsStr.split(',').map(x=>x.trim()).filter(x=>x);
491
+ }
492
+
487
493
  for (const p of parts) {
488
494
  if (!def.columns[p]) return false;
489
495
  }
@@ -501,4 +507,4 @@ class SchemaSync {
501
507
  }
502
508
  }
503
509
 
504
- module.exports = SchemaSync
510
+ module.exports = SchemaSync
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neopg",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "orm for postgres",
5
5
  "keywords": [
6
6
  "neopg",
package/test/test-db.js CHANGED
@@ -129,13 +129,16 @@ const User = {
129
129
  index: [
130
130
  'create_time',
131
131
  'level',
132
- 'is_root'
132
+ 'is_root',
133
+ ['level', 'is_root']
133
134
  ],
134
135
 
135
136
  //唯一索引
136
137
  unique: [
137
138
  'username',
138
- 'email', 'id'
139
+ 'email', 'id',
140
+ ['mobile', 'email']
141
+
139
142
  ]
140
143
  }
141
144