neopg 2.1.0 → 2.2.0

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
@@ -49,8 +49,13 @@ class ModelChain {
49
49
  _ensureActive() {
50
50
  if (this._executed) {
51
51
  throw new Error(
52
- `[NeoPG] ModelChain for '${this.def.tableName}' has already been executed. ` +
53
- `Do NOT reuse the chain variable. Use .clone() if you need to fork queries.`
52
+ `[NeoPG] Security Error: This query chain for \x1b[36m'${this.def.tableName}'\x1b[0m has already been executed to prevent state pollution.\n` +
53
+ `❌ Do NOT reuse the same variable for multiple executions.\n` +
54
+ `✅ If you need to execute multiple queries based on the same conditions, use .clone() before execution.\n\x1b[35m` +
55
+ ` Example: \n` +
56
+ ` const q = model.where(...);\n` +
57
+ ` const data = await q.clone().find();\n` +
58
+ ` await q.clone().update(...);\x1b[0m`
54
59
  )
55
60
  }
56
61
  }
@@ -9,14 +9,24 @@ class TransactionScope {
9
9
 
10
10
  table(tableName, schema = null) {
11
11
  const target = schema || this.parent.defaultSchema
12
- return new this.parent.ModelChain(this, {tableName, isRaw: true}, target)
12
+ let m = new this.parent.ModelChain(this, {tableName, isRaw: true}, target)
13
+ m._isRaw = true
14
+ return m
13
15
  }
14
16
 
15
17
  model(name, schema = null) {
16
18
  const item = this.parent.registry.get(name)
17
19
  if (!item) throw new Error(`[NeoPG] Model '${name}' not found.`)
18
20
  const target = schema || this.parent.defaultSchema
19
- return new item.Class(this, item.def, target)
21
+ let m = new item.Class(this, item.def, target)
22
+ if (!m.def) {
23
+ m.def = item.def
24
+ m.ctx = this.parent
25
+ m.sql = this.sql
26
+ m.schema = target
27
+ }
28
+
29
+ return m
20
30
  }
21
31
 
22
32
  async transaction(callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neopg",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "orm for postgres",
5
5
  "keywords": [
6
6
  "neopg",