neopg 2.0.4 → 2.0.6

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/ModelChain.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const makeId = require('./makeId.js')
4
4
  const makeTimestamp = require('./makeTimestamp.js')
5
+ const serialId = makeId.serialId
5
6
 
6
7
  // 提取常量定义
7
8
  const INT_TYPES = new Set([
@@ -429,6 +430,10 @@ class ModelChain {
429
430
  return this.ctx.transaction(callback)
430
431
  }
431
432
 
433
+ model(name) {
434
+ return this.ctx.model(name)
435
+ }
436
+
432
437
  async _aggregate(func, field) {
433
438
  this._ensureActive()
434
439
  try {
@@ -547,6 +552,10 @@ class ModelChain {
547
552
  this.def.validateField(key, row[key])
548
553
  }
549
554
  }
555
+
556
+ makeId(len=16) {
557
+ return this.def ? this.def.makeId(this.def.pkLen) : serialId(len)
558
+ }
550
559
  }
551
560
 
552
561
  module.exports = ModelChain
package/lib/NeoPG.js CHANGED
@@ -204,6 +204,10 @@ class NeoPG {
204
204
  await this.sql.notify(channel, data)
205
205
  }
206
206
 
207
+ createSchema(name) {
208
+ return SchemaSync.createSchema(this.sql, name)
209
+ }
210
+
207
211
  async close() {
208
212
  await this.driver.end()
209
213
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neopg",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "orm for postgres",
5
5
  "keywords": [
6
6
  "neopg",
package/test/test-db.js CHANGED
@@ -141,6 +141,7 @@ const User = {
141
141
  db.add(User)
142
142
 
143
143
  ;(async () => {
144
+ await db.createSchema('test')
144
145
  await db.sync({force: true, debug: true})
145
146
  // 插入
146
147