orange-orm 4.9.0 → 4.10.0-beta.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.
Files changed (42) hide show
  1. package/README.md +120 -0
  2. package/deno.lock +76 -0
  3. package/dist/index.browser.mjs +192 -56
  4. package/dist/index.mjs +292 -179
  5. package/docs/changelog.md +2 -0
  6. package/other.db +0 -0
  7. package/package.json +1 -1
  8. package/src/bunPg/newDatabase.js +3 -14
  9. package/src/bunPg/newTransaction.js +1 -0
  10. package/src/bunSqlite/newDatabase.js +22 -13
  11. package/src/bunSqlite/newTransaction.js +1 -0
  12. package/src/client/index.js +8 -1
  13. package/src/client/netAdapter.js +13 -2
  14. package/src/d1/newDatabase.js +3 -13
  15. package/src/d1/newTransaction.js +1 -0
  16. package/src/getTSDefinition.js +14 -1
  17. package/src/hostExpress.js +8 -3
  18. package/src/hostLocal.js +66 -6
  19. package/src/map2.d.ts +18 -1
  20. package/src/mssql/newDatabase.js +3 -13
  21. package/src/mssql/newTransaction.js +1 -0
  22. package/src/mySql/newDatabase.js +3 -13
  23. package/src/mySql/newTransaction.js +1 -0
  24. package/src/nodeSqlite/newDatabase.js +29 -18
  25. package/src/nodeSqlite/newTransaction.js +1 -0
  26. package/src/oracle/newDatabase.js +3 -13
  27. package/src/oracle/newTransaction.js +1 -0
  28. package/src/pg/newDatabase.js +4 -16
  29. package/src/pg/newTransaction.js +1 -0
  30. package/src/pglite/newDatabase.js +3 -14
  31. package/src/pglite/newTransaction.js +1 -0
  32. package/src/sap/newDatabase.js +3 -13
  33. package/src/sap/newTransaction.js +1 -0
  34. package/src/sqlite3/newDatabase.js +22 -13
  35. package/src/sqlite3/newTransaction.js +1 -0
  36. package/src/sqliteFunction.js +20 -0
  37. package/src/table/begin.js +0 -1
  38. package/src/table/commit.js +21 -1
  39. package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +6 -4
  40. package/src/table/rollback.js +22 -2
  41. package/src/tedious/newDatabase.js +3 -13
  42. package/src/tedious/newTransaction.js +1 -0
package/docs/changelog.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Changelog
2
+ __4.9.1__
3
+ Fix: Avoid double-quoting aliases in discriminator join SQL [#144](https://github.com/alfateam/orange-orm/issues/144)
2
4
  __4.9.0__
3
5
  Node.js 22.5+: Continues using built-in `node:sqlite` (no action needed)
4
6
  Node.js 18-22.4: Now requires `better-sqlite3` instead of `sqlite3`
package/other.db ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.9.0",
3
+ "version": "4.10.0-beta.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -10,7 +10,6 @@ let express = require('../hostExpress');
10
10
  let hostLocal = require('../hostLocal');
11
11
  let doQuery = require('../query');
12
12
  let releaseDbClient = require('../table/releaseDbClient');
13
- let setSessionSingleton = require('../table/setSessionSingleton');
14
13
 
15
14
  function newDatabase(connectionString, poolOptions) {
16
15
  if (!connectionString)
@@ -27,10 +26,9 @@ function newDatabase(connectionString, poolOptions) {
27
26
  }
28
27
  let domain = createDomain();
29
28
 
30
- if (fn)
31
- return domain.run(runInTransaction);
32
- else
33
- return domain.run(run);
29
+ if (!fn)
30
+ throw new Error('transaction requires a function');
31
+ return domain.run(runInTransaction);
34
32
 
35
33
  async function runInTransaction() {
36
34
  let result;
@@ -49,14 +47,6 @@ function newDatabase(connectionString, poolOptions) {
49
47
  return _begin(domain, options);
50
48
  }
51
49
 
52
- function run() {
53
- let p;
54
- let transaction = newTransaction(domain, pool, options);
55
- p = new Promise(transaction);
56
-
57
- return p.then(begin)
58
- .then(negotiateSchema);
59
- }
60
50
 
61
51
  function negotiateSchema(previous) {
62
52
  let schema = options && options.schema;
@@ -97,7 +87,6 @@ function newDatabase(connectionString, poolOptions) {
97
87
  let domain = createDomain();
98
88
  let transaction = newTransaction(domain, pool);
99
89
  let p = domain.run(() => new Promise(transaction)
100
- .then(() => setSessionSingleton(domain, 'changes', []))
101
90
  .then(() => doQuery(domain, query).then(onResult, onError)));
102
91
  return p;
103
92
 
@@ -40,6 +40,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
40
40
  rdb.aggregateCount = 0;
41
41
  rdb.quote = quote;
42
42
  rdb.cache = {};
43
+ rdb.changes = [];
43
44
 
44
45
  if (readonly) {
45
46
  rdb.dbClient = {
@@ -7,8 +7,8 @@ let newPool = require('./newPool');
7
7
  let express = require('../hostExpress');
8
8
  let hostLocal = require('../hostLocal');
9
9
  let doQuery = require('../query');
10
+ let doSqliteFunction = require('../sqliteFunction');
10
11
  let releaseDbClient = require('../table/releaseDbClient');
11
- let setSessionSingleton = require('../table/setSessionSingleton');
12
12
 
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
@@ -25,10 +25,9 @@ function newDatabase(connectionString, poolOptions) {
25
25
  }
26
26
  let domain = createDomain();
27
27
 
28
- if (fn)
29
- return domain.run(runInTransaction);
30
- else
31
- return domain.run(run);
28
+ if (!fn)
29
+ throw new Error('transaction requires a function');
30
+ return domain.run(runInTransaction);
32
31
 
33
32
  function begin() {
34
33
  return _begin(domain, options);
@@ -46,13 +45,6 @@ function newDatabase(connectionString, poolOptions) {
46
45
  return result;
47
46
  }
48
47
 
49
- function run() {
50
- let p;
51
- let transaction = newTransaction(domain, pool, options);
52
- p = new Promise(transaction);
53
-
54
- return p.then(begin);
55
- }
56
48
 
57
49
  };
58
50
 
@@ -77,7 +69,6 @@ function newDatabase(connectionString, poolOptions) {
77
69
  let domain = createDomain();
78
70
  let transaction = newTransaction(domain, pool);
79
71
  let p = domain.run(() => new Promise(transaction)
80
- .then(() => setSessionSingleton(domain, 'changes', []))
81
72
  .then(() => doQuery(domain, query).then(onResult, onError)));
82
73
  return p;
83
74
 
@@ -92,6 +83,24 @@ function newDatabase(connectionString, poolOptions) {
92
83
  }
93
84
  };
94
85
 
86
+ c.sqliteFunction = function(...args) {
87
+ let domain = createDomain();
88
+ let transaction = newTransaction(domain, pool);
89
+ let p = domain.run(() => new Promise(transaction)
90
+ .then(() => doSqliteFunction(domain, ...args).then(onResult, onError)));
91
+ return p;
92
+
93
+ function onResult(result) {
94
+ releaseDbClient(domain);
95
+ return result;
96
+ }
97
+
98
+ function onError(e) {
99
+ releaseDbClient(domain);
100
+ throw e;
101
+ }
102
+ };
103
+
95
104
 
96
105
  c.rollback = rollback;
97
106
  c.commit = commit;
@@ -39,6 +39,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
39
39
  rdb.aggregateCount = 0;
40
40
  rdb.quote = quote;
41
41
  rdb.cache = {};
42
+ rdb.changes = [];
42
43
 
43
44
  if (readonly) {
44
45
  rdb.dbClient = {
@@ -51,6 +51,7 @@ function rdbClient(options = {}) {
51
51
  }
52
52
  };
53
53
  client.query = query;
54
+ client.function = sqliteFunction;
54
55
  client.transaction = runInTransaction;
55
56
  client.db = baseUrl;
56
57
  client.mssql = onProvider.bind(null, 'mssql');
@@ -139,6 +140,11 @@ function rdbClient(options = {}) {
139
140
  return adapter.query.apply(null, arguments);
140
141
  }
141
142
 
143
+ async function sqliteFunction() {
144
+ const adapter = netAdapter(baseUrl, undefined, { tableOptions: { db: baseUrl, transaction } });
145
+ return adapter.sqliteFunction.apply(null, arguments);
146
+ }
147
+
142
148
  function express(arg) {
143
149
  if (providers.express) {
144
150
  return providers.express(client, { ...options, ...arg });
@@ -822,6 +828,7 @@ function rdbClient(options = {}) {
822
828
  return;
823
829
 
824
830
  let body = stringify({ patch, options: { ...tableOptions, ...concurrencyOptions, strategy, deduceStrategy } });
831
+
825
832
  let adapter = netAdapter(url, tableName, { axios: axiosInterceptor, tableOptions });
826
833
  let { changed, strategy: newStrategy } = await adapter.patch(body);
827
834
  copyInto(changed, [row]);
@@ -1059,4 +1066,4 @@ function onChange(target, onChange) {
1059
1066
  }
1060
1067
 
1061
1068
 
1062
- module.exports = rdbClient();
1069
+ module.exports = rdbClient();
@@ -10,6 +10,7 @@ function httpAdapter(baseURL, path, axiosInterceptor) {
10
10
  post,
11
11
  patch,
12
12
  query,
13
+ sqliteFunction,
13
14
  express
14
15
  };
15
16
 
@@ -65,6 +66,10 @@ function httpAdapter(baseURL, path, axiosInterceptor) {
65
66
  throw new Error('Queries are not supported through http');
66
67
  }
67
68
 
69
+ function sqliteFunction() {
70
+ throw new Error('Sqlite Function is not supported through http');
71
+ }
72
+
68
73
  function express() {
69
74
  throw new Error('Hosting in express is not supported on the client side');
70
75
  }
@@ -78,7 +83,8 @@ function netAdapter(url, tableName, { axios, tableOptions }) {
78
83
  get,
79
84
  post,
80
85
  patch,
81
- query
86
+ query,
87
+ sqliteFunction
82
88
  };
83
89
 
84
90
  return c;
@@ -103,6 +109,11 @@ function netAdapter(url, tableName, { axios, tableOptions }) {
103
109
  return adapter.query.apply(null, arguments);
104
110
  }
105
111
 
112
+ async function sqliteFunction() {
113
+ const adapter = await getInnerAdapter();
114
+ return adapter.sqliteFunction.apply(null, arguments);
115
+ }
116
+
106
117
  async function getInnerAdapter() {
107
118
  const db = await getDb();
108
119
  if (typeof db === 'string') {
@@ -132,4 +143,4 @@ function netAdapter(url, tableName, { axios, tableOptions }) {
132
143
 
133
144
  }
134
145
 
135
- module.exports = netAdapter;
146
+ module.exports = netAdapter;
@@ -8,7 +8,6 @@ let express = require('../hostExpress');
8
8
  let hostLocal = require('../hostLocal');
9
9
  let doQuery = require('../query');
10
10
  let releaseDbClient = require('../table/releaseDbClient');
11
- let setSessionSingleton = require('../table/setSessionSingleton');
12
11
 
13
12
  function newDatabase(d1Database, poolOptions) {
14
13
  if (!d1Database)
@@ -25,10 +24,9 @@ function newDatabase(d1Database, poolOptions) {
25
24
  }
26
25
  let domain = createDomain();
27
26
 
28
- if (fn)
29
- return domain.run(runInTransaction);
30
- else
31
- return domain.run(run);
27
+ if (!fn)
28
+ throw new Error('transaction requires a function');
29
+ return domain.run(runInTransaction);
32
30
 
33
31
  async function runInTransaction() {
34
32
  let result;
@@ -47,13 +45,6 @@ function newDatabase(d1Database, poolOptions) {
47
45
  return _begin(domain, transactionLess);
48
46
  }
49
47
 
50
- function run() {
51
- let p;
52
- let transaction = newTransaction(domain, pool, options);
53
- p = new Promise(transaction);
54
-
55
- return p.then(begin);
56
- }
57
48
 
58
49
  };
59
50
 
@@ -81,7 +72,6 @@ function newDatabase(d1Database, poolOptions) {
81
72
  let domain = createDomain();
82
73
  let transaction = newTransaction(domain, pool);
83
74
  let p = domain.run(() => new Promise(transaction)
84
- .then(() => setSessionSingleton(domain, 'changes', []))
85
75
  .then(() => doQuery(domain, query).then(onResult, onError)));
86
76
  return p;
87
77
 
@@ -35,6 +35,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
35
35
  rdb.aggregateCount = 0;
36
36
  rdb.quote = (name) => `"${name}"`;
37
37
  rdb.cache = {};
38
+ rdb.changes = [];
38
39
 
39
40
  if (readonly) {
40
41
  rdb.dbClient = {
@@ -441,6 +441,7 @@ export interface ExpressConfig {
441
441
  concurrency?: Concurrency;
442
442
  readonly?: boolean;
443
443
  disableBulkDeletes?: boolean;
444
+ hooks?: ExpressHooks;
444
445
  }
445
446
 
446
447
  export interface ExpressContext {
@@ -449,6 +450,18 @@ export interface ExpressContext {
449
450
  client: RdbClient;
450
451
  }
451
452
 
453
+ export interface ExpressTransactionHooks {
454
+ beforeBegin?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
455
+ afterBegin?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
456
+ beforeCommit?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
457
+ afterCommit?: (db: Pool, request: import('express').Request, response: import('express').Response) => void | Promise<void>;
458
+ afterRollback?: (db: Pool, request: import('express').Request, response: import('express').Response, error?: unknown) => void | Promise<void>;
459
+ }
460
+
461
+ export interface ExpressHooks extends ExpressTransactionHooks {
462
+ transaction?: ExpressTransactionHooks;
463
+ }
464
+
452
465
  export interface ExpressTables {${getExpressTables()}
453
466
  }
454
467
  `;
@@ -515,4 +528,4 @@ export interface ExpressTables {${getExpressTables()}
515
528
  }
516
529
  }
517
530
 
518
- module.exports = getTSDefinition;
531
+ module.exports = getTSDefinition;
@@ -8,13 +8,18 @@ function hostExpress(hostLocal, client, options = {}) {
8
8
  const dbOptions = { db: options.db || client.db };
9
9
  let c = {};
10
10
  const readonly = { readonly: options.readonly};
11
+ const sharedHooks = options.hooks;
11
12
  for (let tableName in client.tables) {
13
+ const tableOptions = options[tableName] || {};
14
+ const hooks = tableOptions.hooks || sharedHooks;
12
15
  c[tableName] = hostLocal({
13
16
  ...dbOptions,
14
17
  ...readonly,
15
- ...options[tableName],
18
+ ...tableOptions,
16
19
  table: client.tables[tableName],
17
- isHttp: true, client
20
+ isHttp: true,
21
+ client,
22
+ hooks
18
23
 
19
24
  });
20
25
  }
@@ -117,4 +122,4 @@ function hostExpress(hostLocal, client, options = {}) {
117
122
  return handler;
118
123
  }
119
124
 
120
- module.exports = hostExpress;
125
+ module.exports = hostExpress;
package/src/hostLocal.js CHANGED
@@ -2,6 +2,7 @@ let executePath = require('./hostExpress/executePath');
2
2
  let getMeta = require('./hostExpress/getMeta');
3
3
  let setSessionSingleton = require('./table/setSessionSingleton');
4
4
  let executeQuery = require('./query');
5
+ let executeSqliteFunction = require('./sqliteFunction');
5
6
  let hostExpress = require('./hostExpress');
6
7
  const readonlyOps = ['getManyDto', 'getMany', 'aggregate', 'count'];
7
8
  // { db, table, defaultConcurrency,
@@ -12,9 +13,12 @@ const readonlyOps = ['getManyDto', 'getMany', 'aggregate', 'count'];
12
13
  // disableBulkDeletes, isBrowser }
13
14
  function hostLocal() {
14
15
  const _options = arguments[0];
15
- let { table, transaction, db, isHttp } = _options;
16
+ let { table, transaction, db, isHttp, hooks, client } = _options;
17
+ const transactionHooks = hooks && hooks.transaction;
18
+ const getTransactionHook = (name) =>
19
+ (transactionHooks && transactionHooks[name]) || (hooks && hooks[name]);
16
20
 
17
- let c = { get, post, patch, query, express };
21
+ let c = { get, post, patch, query, sqliteFunction, express };
18
22
 
19
23
  function get() {
20
24
  return getMeta(table);
@@ -65,10 +69,41 @@ function hostLocal() {
65
69
  else
66
70
  db = dbPromise;
67
71
  }
68
- if (readonlyOps.includes(body.path))
72
+ const beforeBegin = getTransactionHook('beforeBegin');
73
+ const afterBegin = getTransactionHook('afterBegin');
74
+ const beforeCommit = getTransactionHook('beforeCommit');
75
+ const afterCommit = getTransactionHook('afterCommit');
76
+ const afterRollback = getTransactionHook('afterRollback');
77
+ const hasTransactionHooks = !!(beforeBegin
78
+ || afterBegin
79
+ || beforeCommit
80
+ || afterCommit
81
+ || afterRollback);
82
+ if (!hasTransactionHooks && readonlyOps.includes(body.path))
69
83
  await db.transaction({ readonly: true }, fn);
70
- else
71
- await db.transaction(fn);
84
+ else {
85
+ await db.transaction(async (context) => {
86
+ const hookDb = typeof client === 'function'
87
+ ? client({ transaction: (fn) => fn(context) })
88
+ : (client || db);
89
+ if (afterCommit)
90
+ setSessionSingleton(context, 'afterCommitHook', () =>
91
+ afterCommit(hookDb, request, response)
92
+ );
93
+ if (afterRollback)
94
+ setSessionSingleton(context, 'afterRollbackHook', (error) =>
95
+ afterRollback(hookDb, request, response, error)
96
+ );
97
+ if (beforeBegin)
98
+ await beforeBegin(hookDb, request, response);
99
+ if (afterBegin)
100
+ await afterBegin(hookDb, request, response);
101
+ await fn(context);
102
+ if (beforeCommit)
103
+ await beforeCommit(hookDb, request, response);
104
+ });
105
+ }
106
+
72
107
  }
73
108
  return result;
74
109
 
@@ -103,6 +138,31 @@ function hostLocal() {
103
138
 
104
139
  }
105
140
 
141
+ async function sqliteFunction() {
142
+ let args = arguments;
143
+ let result;
144
+
145
+ if (transaction)
146
+ await transaction(fn);
147
+ else {
148
+ if (typeof db === 'function') {
149
+ let dbPromise = db();
150
+ if (dbPromise.then)
151
+ db = await dbPromise;
152
+ else
153
+ db = dbPromise;
154
+ }
155
+ result = await db.sqliteFunction.apply(null, arguments);
156
+ }
157
+
158
+ return result;
159
+
160
+ async function fn(...args1) {
161
+ result = await executeSqliteFunction.apply(null, [...args1, ...args]);
162
+ }
163
+
164
+ }
165
+
106
166
  function express(client, options) {
107
167
  return hostExpress(hostLocal, client, options);
108
168
  }
@@ -110,4 +170,4 @@ function hostLocal() {
110
170
  return c;
111
171
  }
112
172
 
113
- module.exports = hostLocal;
173
+ module.exports = hostLocal;
package/src/map2.d.ts CHANGED
@@ -903,6 +903,10 @@ export type DBClient<M extends Record<string, TableDefinition<M>>> = {
903
903
  and(f: Filter | RawFilter[], ...filters: RawFilter[]): Filter;
904
904
  or(f: Filter | RawFilter[], ...filters: RawFilter[]): Filter;
905
905
  not(): Filter;
906
+ /**
907
+ * Register a user-defined SQLite function on the connection.
908
+ */
909
+ function(name: string, fn: (...args: any[]) => unknown): Promise<unknown> | void;
906
910
  query(filter: RawFilter | string): Promise<unknown[]>;
907
911
  query<T>(filter: RawFilter | string): Promise<T[]>;
908
912
  createPatch(original: any[], modified: any[]): JsonPatch;
@@ -924,16 +928,29 @@ type ExpressConfig<M extends Record<string, TableDefinition<M>>> = {
924
928
  [TableName in keyof M]?: ExpressTableConfig<M>;
925
929
  } & {
926
930
  db?: Pool | ((connectors: Connectors) => Pool | Promise<Pool>);
931
+ hooks?: ExpressHooks<M>;
927
932
  }
928
933
 
929
934
  type ExpressTableConfig<M extends Record<string, TableDefinition<M>>> = {
930
935
  baseFilter?: RawFilter | ((db: DBClient<M>, req: import('express').Request, res: import('express').Response) => RawFilter);
931
936
  }
932
937
 
938
+ type ExpressTransactionHooks<M extends Record<string, TableDefinition<M>>> = {
939
+ beforeBegin?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response) => void | Promise<void>;
940
+ afterBegin?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response) => void | Promise<void>;
941
+ beforeCommit?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response) => void | Promise<void>;
942
+ afterCommit?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response) => void | Promise<void>;
943
+ afterRollback?: (db: DBClient<M>, req: import('express').Request, res: import('express').Response, error?: unknown) => void | Promise<void>;
944
+ }
945
+
946
+ type ExpressHooks<M extends Record<string, TableDefinition<M>>> = ExpressTransactionHooks<M> & {
947
+ transaction?: ExpressTransactionHooks<M>;
948
+ }
949
+
933
950
  export type DeepExpand<T> =
934
951
  T extends Date ? T :
935
952
  T extends Array<infer U> ? Array<DeepExpand<U>> :
936
953
  T extends object ? { [K in keyof T]: DeepExpand<T[K]> } :
937
954
  T;
938
955
 
939
- export function db<M extends Record<string, TableDefinition<M>>>(): DBClient<M>;
956
+ export function db<M extends Record<string, TableDefinition<M>>>(): DBClient<M>;
@@ -8,7 +8,6 @@ let express = require('../hostExpress');
8
8
  let hostLocal = require('../hostLocal');
9
9
  let doQuery = require('../query');
10
10
  let releaseDbClient = require('../table/releaseDbClient');
11
- let setSessionSingleton = require('../table/setSessionSingleton');
12
11
 
13
12
  function newDatabase(connectionString, poolOptions) {
14
13
  if (!connectionString)
@@ -25,10 +24,9 @@ function newDatabase(connectionString, poolOptions) {
25
24
  }
26
25
  let domain = createDomain();
27
26
 
28
- if (fn)
29
- return domain.run(runInTransaction);
30
- else
31
- return domain.run(run);
27
+ if (!fn)
28
+ throw new Error('transaction requires a function');
29
+ return domain.run(runInTransaction);
32
30
 
33
31
  async function runInTransaction() {
34
32
  let result;
@@ -46,13 +44,6 @@ function newDatabase(connectionString, poolOptions) {
46
44
  return _begin(domain, options);
47
45
  }
48
46
 
49
- function run() {
50
- let p;
51
- let transaction = newTransaction(domain, pool, options);
52
- p = new Promise(transaction);
53
-
54
- return p.then(begin);
55
- }
56
47
 
57
48
  };
58
49
 
@@ -81,7 +72,6 @@ function newDatabase(connectionString, poolOptions) {
81
72
  let domain = createDomain();
82
73
  let transaction = newTransaction(domain, pool);
83
74
  let p = domain.run(() => new Promise(transaction)
84
- .then(() => setSessionSingleton(domain, 'changes', []))
85
75
  .then(() => doQuery(domain, query).then(onResult, onError)));
86
76
  return p;
87
77
 
@@ -48,6 +48,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
48
48
  rdb.aggregateCount = 0;
49
49
  rdb.quote = quote;
50
50
  rdb.cache = {};
51
+ rdb.changes = [];
51
52
 
52
53
  if (readonly) {
53
54
  rdb.dbClient = {
@@ -8,7 +8,6 @@ let express = require('../hostExpress');
8
8
  let hostLocal = require('../hostLocal');
9
9
  let doQuery = require('../query');
10
10
  let releaseDbClient = require('../table/releaseDbClient');
11
- let setSessionSingleton = require('../table/setSessionSingleton');
12
11
 
13
12
  function newDatabase(connectionString, poolOptions) {
14
13
  if (!connectionString)
@@ -25,10 +24,9 @@ function newDatabase(connectionString, poolOptions) {
25
24
  }
26
25
  let domain = createDomain();
27
26
 
28
- if (fn)
29
- return domain.run(runInTransaction);
30
- else
31
- return domain.run(run);
27
+ if (!fn)
28
+ throw new Error('transaction requires a function');
29
+ return domain.run(runInTransaction);
32
30
 
33
31
  async function runInTransaction() {
34
32
  let result;
@@ -46,13 +44,6 @@ function newDatabase(connectionString, poolOptions) {
46
44
  return _begin(domain, options);
47
45
  }
48
46
 
49
- function run() {
50
- let p;
51
- let transaction = newTransaction(domain, pool, options);
52
- p = new Promise(transaction);
53
-
54
- return p.then(begin);
55
- }
56
47
 
57
48
  };
58
49
 
@@ -78,7 +69,6 @@ function newDatabase(connectionString, poolOptions) {
78
69
  let domain = createDomain();
79
70
  let transaction = newTransaction(domain, pool);
80
71
  let p = domain.run(() => new Promise(transaction)
81
- .then(() => setSessionSingleton(domain, 'changes', []))
82
72
  .then(() => doQuery(domain, query).then(onResult, onError)));
83
73
  return p;
84
74
 
@@ -34,6 +34,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
34
34
  rdb.aggregateCount = 0;
35
35
  rdb.quote = quote;
36
36
  rdb.cache = {};
37
+ rdb.changes = [];
37
38
 
38
39
  if (readonly) {
39
40
  rdb.dbClient = {