orange-orm 4.6.0 → 4.7.0-beta.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/dist/index.mjs CHANGED
@@ -2087,12 +2087,12 @@ function requireNegotiateParameters () {
2087
2087
  return negotiateParameters_1;
2088
2088
  }
2089
2089
 
2090
- var wrapQuery_1$a;
2091
- var hasRequiredWrapQuery$a;
2090
+ var wrapQuery_1$b;
2091
+ var hasRequiredWrapQuery$b;
2092
2092
 
2093
- function requireWrapQuery$a () {
2094
- if (hasRequiredWrapQuery$a) return wrapQuery_1$a;
2095
- hasRequiredWrapQuery$a = 1;
2093
+ function requireWrapQuery$b () {
2094
+ if (hasRequiredWrapQuery$b) return wrapQuery_1$b;
2095
+ hasRequiredWrapQuery$b = 1;
2096
2096
  var negotiateSql = requireNegotiateSql();
2097
2097
  var negotiateParameters = requireNegotiateParameters();
2098
2098
 
@@ -2109,8 +2109,8 @@ function requireWrapQuery$a () {
2109
2109
  }
2110
2110
 
2111
2111
 
2112
- wrapQuery_1$a = wrapQuery;
2113
- return wrapQuery_1$a;
2112
+ wrapQuery_1$b = wrapQuery;
2113
+ return wrapQuery_1$b;
2114
2114
  }
2115
2115
 
2116
2116
  var query;
@@ -2120,7 +2120,7 @@ function requireQuery () {
2120
2120
  if (hasRequiredQuery) return query;
2121
2121
  hasRequiredQuery = 1;
2122
2122
  var executeQueries = requireExecuteQueries();
2123
- var wrapQuery = requireWrapQuery$a();
2123
+ var wrapQuery = requireWrapQuery$b();
2124
2124
 
2125
2125
  function doQuery(context, query) {
2126
2126
  var wrappedQuery = wrapQuery(query);
@@ -2539,6 +2539,7 @@ function requireClientMap () {
2539
2539
 
2540
2540
  dbMap.http = (url) => url;
2541
2541
  dbMap.pg = throwDb;
2542
+ dbMap.pglite = throwDb;
2542
2543
  dbMap.postgres = throwDb;
2543
2544
  dbMap.mssql = throwDb;
2544
2545
  dbMap.mssqlNative = throwDb;
@@ -2566,6 +2567,7 @@ function requireClientMap () {
2566
2567
 
2567
2568
  onFinal.http = (url) => index({ db: url, providers: dbMap });
2568
2569
  onFinal.pg = () => index({ db: throwDb, providers: dbMap });
2570
+ onFinal.pglite = () => index({ db: throwDb, providers: dbMap });
2569
2571
  onFinal.postgres = () => index({ db: throwDb, providers: dbMap });
2570
2572
  onFinal.mssql = () => index({ db: throwDb, providers: dbMap });
2571
2573
  onFinal.mssqlNative = () => index({ db: throwDb, providers: dbMap });
@@ -2718,6 +2720,7 @@ function requireClient () {
2718
2720
  client.mssql = onProvider.bind(null, 'mssql');
2719
2721
  client.mssqlNative = onProvider.bind(null, 'mssqlNative');
2720
2722
  client.pg = onProvider.bind(null, 'pg');
2723
+ client.pglite = onProvider.bind(null, 'pglite');
2721
2724
  client.postgres = onProvider.bind(null, 'postgres');
2722
2725
  client.d1 = onProvider.bind(null, 'd1');
2723
2726
  client.sqlite = onProvider.bind(null, 'sqlite');
@@ -4595,7 +4598,7 @@ function requireNewEncode$6 () {
4595
4598
  return newPara('null');
4596
4599
  return newPara('\'' + column.dbNull + '\'');
4597
4600
  }
4598
- var encodeCore = getSessionSingleton(context, 'encodeJSON');
4601
+ var encodeCore = getSessionSingleton(context, 'encodeJSON') || ((v) => v);
4599
4602
 
4600
4603
  if (encodeCore) {
4601
4604
  value = encodeCore(value);
@@ -4611,7 +4614,7 @@ function requireNewEncode$6 () {
4611
4614
  return 'null';
4612
4615
  return '\'' + column.dbNull + '\'';
4613
4616
  }
4614
- var encodeCore = getSessionSingleton(context, 'encodeJSON');
4617
+ var encodeCore = getSessionSingleton(context, 'encodeJSON') || ((v) => v);
4615
4618
 
4616
4619
  if (encodeCore) {
4617
4620
  value = encodeCore(value);
@@ -4620,7 +4623,7 @@ function requireNewEncode$6 () {
4620
4623
  };
4621
4624
 
4622
4625
  encode.direct = function(context, value) {
4623
- var encodeCore = getSessionSingleton(context, 'encodeJSON');
4626
+ var encodeCore = getSessionSingleton(context, 'encodeJSON') || ((v) => v);
4624
4627
 
4625
4628
  if (encodeCore) {
4626
4629
  value = encodeCore(value);
@@ -5219,7 +5222,7 @@ function requireNewEncode$1 () {
5219
5222
  return newParam('null');
5220
5223
  return newParam('\'' + column.dbNull + '\'');
5221
5224
  }
5222
- var encodeCore = getSessionSingleton(context, 'encodeBoolean');
5225
+ var encodeCore = getSessionSingleton(context, 'encodeBoolean') || encodeDefault;
5223
5226
 
5224
5227
 
5225
5228
  return newParam('?', [encodeCore(value)]);
@@ -5232,14 +5235,14 @@ function requireNewEncode$1 () {
5232
5235
  return 'null';
5233
5236
  return '\'' + column.dbNull + '\'';
5234
5237
  }
5235
- var encodeCore = getSessionSingleton(context, 'encodeBoolean');
5238
+ var encodeCore = getSessionSingleton(context, 'encodeBoolean') || encodeDefault;
5236
5239
 
5237
5240
 
5238
5241
  return encodeCore(value);
5239
5242
  };
5240
5243
 
5241
5244
  encode.direct = function(context, value) {
5242
- var encodeCore = getSessionSingleton(context, 'encodeBoolean');
5245
+ var encodeCore = getSessionSingleton(context, 'encodeBoolean') || encodeDefault;
5243
5246
 
5244
5247
  return encodeCore(value);
5245
5248
  };
@@ -5247,6 +5250,10 @@ function requireNewEncode$1 () {
5247
5250
  return encode;
5248
5251
  }
5249
5252
 
5253
+ function encodeDefault(value) {
5254
+ return value;
5255
+ }
5256
+
5250
5257
  newEncode$1 = _new;
5251
5258
  return newEncode$1;
5252
5259
  }
@@ -11865,6 +11872,11 @@ function requireCreateProviders () {
11865
11872
  return createPool.bind(null, 'pg');
11866
11873
  }
11867
11874
  });
11875
+ Object.defineProperty(dbMap, 'pglite', {
11876
+ get: function() {
11877
+ return createPool.bind(null, 'pglite');
11878
+ }
11879
+ });
11868
11880
  Object.defineProperty(dbMap, 'postgres', {
11869
11881
  get: function() {
11870
11882
  return createPool.bind(null, 'pg');
@@ -11933,6 +11945,9 @@ function requireCreateProviders () {
11933
11945
  get pg() {
11934
11946
  return createPool.bind(null, 'pg');
11935
11947
  },
11948
+ get pglite() {
11949
+ return createPool.bind(null, 'pglite');
11950
+ },
11936
11951
  get postgres() {
11937
11952
  return createPool.bind(null, 'pg');
11938
11953
  },
@@ -12035,6 +12050,7 @@ function requireMap () {
12035
12050
  }
12036
12051
  context.map = map.bind(null, index, context, providers);
12037
12052
  context.pg = connect.bind(null, 'pg');
12053
+ context.pglite = connect.bind(null, 'pglite');
12038
12054
  context.postgres = connect.bind(null, 'pg');
12039
12055
  context.mssql = connect.bind(null, 'mssql');
12040
12056
  context.mssqlNative = connect.bind(null, 'mssqlNative');
@@ -12543,12 +12559,12 @@ function requireCreateDomain () {
12543
12559
  return createDomain_1;
12544
12560
  }
12545
12561
 
12546
- var wrapQuery_1$9;
12547
- var hasRequiredWrapQuery$9;
12562
+ var wrapQuery_1$a;
12563
+ var hasRequiredWrapQuery$a;
12548
12564
 
12549
- function requireWrapQuery$9 () {
12550
- if (hasRequiredWrapQuery$9) return wrapQuery_1$9;
12551
- hasRequiredWrapQuery$9 = 1;
12565
+ function requireWrapQuery$a () {
12566
+ if (hasRequiredWrapQuery$a) return wrapQuery_1$a;
12567
+ hasRequiredWrapQuery$a = 1;
12552
12568
  var log = requireLog();
12553
12569
 
12554
12570
  function wrapQuery(_context, connection) {
@@ -12564,8 +12580,8 @@ function requireWrapQuery$9 () {
12564
12580
 
12565
12581
  }
12566
12582
 
12567
- wrapQuery_1$9 = wrapQuery;
12568
- return wrapQuery_1$9;
12583
+ wrapQuery_1$a = wrapQuery;
12584
+ return wrapQuery_1$a;
12569
12585
  }
12570
12586
 
12571
12587
  var encodeBoolean_1$5;
@@ -13087,13 +13103,13 @@ function requireInsert$5 () {
13087
13103
  return insert$4;
13088
13104
  }
13089
13105
 
13090
- var newTransaction$a;
13091
- var hasRequiredNewTransaction$a;
13106
+ var newTransaction$b;
13107
+ var hasRequiredNewTransaction$b;
13092
13108
 
13093
- function requireNewTransaction$a () {
13094
- if (hasRequiredNewTransaction$a) return newTransaction$a;
13095
- hasRequiredNewTransaction$a = 1;
13096
- const wrapQuery = requireWrapQuery$9();
13109
+ function requireNewTransaction$b () {
13110
+ if (hasRequiredNewTransaction$b) return newTransaction$b;
13111
+ hasRequiredNewTransaction$b = 1;
13112
+ const wrapQuery = requireWrapQuery$a();
13097
13113
  const encodeBoolean = requireEncodeBoolean$5();
13098
13114
  const deleteFromSql = requireDeleteFromSql$5();
13099
13115
  const selectForUpdateSql = requireSelectForUpdateSql$5();
@@ -13171,8 +13187,8 @@ function requireNewTransaction$a () {
13171
13187
  };
13172
13188
  }
13173
13189
 
13174
- newTransaction$a = newResolveTransaction;
13175
- return newTransaction$a;
13190
+ newTransaction$b = newResolveTransaction;
13191
+ return newTransaction$b;
13176
13192
  }
13177
13193
 
13178
13194
  var beginCommand;
@@ -13253,12 +13269,12 @@ function requirePromisify () {
13253
13269
  return promisify_1;
13254
13270
  }
13255
13271
 
13256
- var end$9;
13257
- var hasRequiredEnd$9;
13272
+ var end$a;
13273
+ var hasRequiredEnd$a;
13258
13274
 
13259
- function requireEnd$9 () {
13260
- if (hasRequiredEnd$9) return end$9;
13261
- hasRequiredEnd$9 = 1;
13275
+ function requireEnd$a () {
13276
+ if (hasRequiredEnd$a) return end$a;
13277
+ hasRequiredEnd$a = 1;
13262
13278
  var pools = requirePools();
13263
13279
 
13264
13280
  function endPool(genericPool, id, done) {
@@ -13271,8 +13287,8 @@ function requireEnd$9 () {
13271
13287
  }
13272
13288
  }
13273
13289
 
13274
- end$9 = endPool;
13275
- return end$9;
13290
+ end$a = endPool;
13291
+ return end$a;
13276
13292
  }
13277
13293
 
13278
13294
  var poolDefaults;
@@ -13982,15 +13998,15 @@ function requireNewGenericPool$7 () {
13982
13998
  return newGenericPool_1$7;
13983
13999
  }
13984
14000
 
13985
- var newPool_1$a;
13986
- var hasRequiredNewPool$a;
14001
+ var newPool_1$b;
14002
+ var hasRequiredNewPool$b;
13987
14003
 
13988
- function requireNewPool$a () {
13989
- if (hasRequiredNewPool$a) return newPool_1$a;
13990
- hasRequiredNewPool$a = 1;
14004
+ function requireNewPool$b () {
14005
+ if (hasRequiredNewPool$b) return newPool_1$b;
14006
+ hasRequiredNewPool$b = 1;
13991
14007
  const promisify = requirePromisify();
13992
14008
  const pools = requirePools();
13993
- const end = requireEnd$9();
14009
+ const end = requireEnd$a();
13994
14010
  const newGenericPool = requireNewGenericPool$7();
13995
14011
  const newId = requireNewId();
13996
14012
 
@@ -14006,22 +14022,22 @@ function requireNewPool$a () {
14006
14022
  return c;
14007
14023
  }
14008
14024
 
14009
- newPool_1$a = newPool;
14010
- return newPool_1$a;
14025
+ newPool_1$b = newPool;
14026
+ return newPool_1$b;
14011
14027
  }
14012
14028
 
14013
- var newDatabase_1$a;
14014
- var hasRequiredNewDatabase$a;
14029
+ var newDatabase_1$b;
14030
+ var hasRequiredNewDatabase$b;
14015
14031
 
14016
- function requireNewDatabase$a () {
14017
- if (hasRequiredNewDatabase$a) return newDatabase_1$a;
14018
- hasRequiredNewDatabase$a = 1;
14032
+ function requireNewDatabase$b () {
14033
+ if (hasRequiredNewDatabase$b) return newDatabase_1$b;
14034
+ hasRequiredNewDatabase$b = 1;
14019
14035
  let createDomain = requireCreateDomain();
14020
- let newTransaction = requireNewTransaction$a();
14036
+ let newTransaction = requireNewTransaction$b();
14021
14037
  let _begin = requireBegin();
14022
14038
  let commit = requireCommit();
14023
14039
  let rollback = requireRollback();
14024
- let newPool = requireNewPool$a();
14040
+ let newPool = requireNewPool$b();
14025
14041
  let express = requireHostExpress();
14026
14042
  let hostLocal = requireHostLocal();
14027
14043
  let doQuery = requireQuery();
@@ -14132,8 +14148,8 @@ function requireNewDatabase$a () {
14132
14148
  return c;
14133
14149
  }
14134
14150
 
14135
- newDatabase_1$a = newDatabase;
14136
- return newDatabase_1$a;
14151
+ newDatabase_1$b = newDatabase;
14152
+ return newDatabase_1$b;
14137
14153
  }
14138
14154
 
14139
14155
  var replaceParamChar_1$1;
@@ -14159,110 +14175,40 @@ function requireReplaceParamChar$1 () {
14159
14175
  return replaceParamChar_1$1;
14160
14176
  }
14161
14177
 
14162
- var wrapQuery_1$8;
14163
- var hasRequiredWrapQuery$8;
14178
+ var wrapQuery_1$9;
14179
+ var hasRequiredWrapQuery$9;
14164
14180
 
14165
- function requireWrapQuery$8 () {
14166
- if (hasRequiredWrapQuery$8) return wrapQuery_1$8;
14167
- hasRequiredWrapQuery$8 = 1;
14168
- const log = requireLog();
14169
- const replaceParamChar = requireReplaceParamChar$1();
14170
- const tryGetSessionContext = requireTryGetSessionContext();
14181
+ function requireWrapQuery$9 () {
14182
+ if (hasRequiredWrapQuery$9) return wrapQuery_1$9;
14183
+ hasRequiredWrapQuery$9 = 1;
14184
+ var log = requireLog();
14185
+ var replaceParamChar = requireReplaceParamChar$1();
14171
14186
 
14172
- function wrapQuery(context, connection) {
14187
+ function wrapQuery(_context, connection) {
14188
+ var runOriginalQuery = connection.query;
14173
14189
  return runQuery;
14174
14190
 
14175
- async function runQuery(query, onCompleted) {
14176
- try {
14177
-
14178
- const sql = replaceParamChar(query, query.parameters);
14179
- let rdb = tryGetSessionContext(context);
14180
- let transactionHandler = rdb.transactionHandler;
14181
- log.emitQuery({ sql, parameters: query.parameters });
14191
+ function runQuery(query, onCompleted) {
14192
+ var params = query.parameters;
14193
+ var sql = replaceParamChar(query, params);
14194
+ log.emitQuery({sql, parameters: params});
14195
+ runOriginalQuery.call(connection, sql, params).then((result) => onInnerCompleted(null, result), (e) => onInnerCompleted(e));
14182
14196
 
14183
- if (sql.length < 18 && query.parameters.length === 0) {
14184
- if (sql === 'BEGIN TRANSACTION' || sql === 'BEGIN') {
14185
- if (transactionHandler)
14186
- return onCompleted(new Error('Already inside a transaction'), []);
14187
- beginTransaction(connection).then(_transactionHandler => {
14188
- rdb.transactionHandler = _transactionHandler;
14189
- onCompleted(null, []);
14190
- }, onCompleted);
14191
- return;
14192
- }
14193
- else if (sql === 'COMMIT') {
14194
- if (!transactionHandler)
14195
- return onCompleted(new Error('Cannot commit outside transaction'), []);
14196
- transactionHandler.resolve();
14197
- transactionHandler.promise.then(() => onCompleted(null, []), err => onCompleted(err, []));
14198
- return;
14199
- }
14200
- else if (sql === 'ROLLBACK') {
14201
- if (!transactionHandler)
14202
- return onCompleted(new Error('Cannot rollback outside transaction'), []);
14203
- transactionHandler.reject(new Error('__rollback__'));
14204
- transactionHandler.promise.then(null, (err) => {
14205
- if (err.message === '__rollback__')
14206
- onCompleted(null, []);
14207
- else
14208
- onCompleted(err, []);
14209
- });
14210
- return;
14211
- }
14197
+ function onInnerCompleted(err, result) {
14198
+ if (err)
14199
+ onCompleted(err);
14200
+ else {
14201
+ if (Array.isArray(result))
14202
+ result = result[result.length-1];
14203
+ onCompleted(null, result.rows);
14212
14204
  }
14213
-
14214
- let result;
14215
- const _connection = transactionHandler?.tx || connection;
14216
- if (query.parameters.length === 0)
14217
- result = await _connection.unsafe(sql);
14218
- else
14219
- result = await _connection.unsafe(sql, query.parameters);
14220
- onCompleted(null, result);
14221
- }
14222
- catch (e) {
14223
- onCompleted(e);
14224
14205
  }
14225
14206
  }
14226
14207
 
14227
14208
  }
14228
14209
 
14229
- function beginTransaction(connection) {
14230
-
14231
- let beginIsResolved = false;
14232
- let resolve;
14233
- let reject;
14234
- let resolveBegin;
14235
- let rejectBegin;
14236
-
14237
- let sqlPromise = new Promise((res, rej) => {
14238
- resolve = res;
14239
- reject = rej;
14240
- });
14241
- let beginPromise = new Promise((res,rej) => {
14242
- resolveBegin = res;
14243
- rejectBegin = rej;
14244
- });
14245
- connection.begin(async (tx) => {
14246
- beginIsResolved = true;
14247
- resolveBegin({
14248
- tx,
14249
- resolve,
14250
- reject,
14251
- promise: sqlPromise,
14252
- });
14253
- return sqlPromise;
14254
- }).then(null,
14255
- e => {
14256
- if (!beginIsResolved)
14257
- rejectBegin(e);
14258
- if (e?.message !== '__rollback__')
14259
- throw e;
14260
- });
14261
- return beginPromise;
14262
- }
14263
-
14264
- wrapQuery_1$8 = wrapQuery;
14265
- return wrapQuery_1$8;
14210
+ wrapQuery_1$9 = wrapQuery;
14211
+ return wrapQuery_1$9;
14266
14212
  }
14267
14213
 
14268
14214
  var encodeDate_1;
@@ -14281,20 +14227,6 @@ function requireEncodeDate () {
14281
14227
  return encodeDate_1;
14282
14228
  }
14283
14229
 
14284
- var encodeBoolean_1$4;
14285
- var hasRequiredEncodeBoolean$4;
14286
-
14287
- function requireEncodeBoolean$4 () {
14288
- if (hasRequiredEncodeBoolean$4) return encodeBoolean_1$4;
14289
- hasRequiredEncodeBoolean$4 = 1;
14290
- function encodeBoolean(bool) {
14291
- return bool.toString();
14292
- }
14293
-
14294
- encodeBoolean_1$4 = encodeBoolean;
14295
- return encodeBoolean_1$4;
14296
- }
14297
-
14298
14230
  var encodeBinary_1;
14299
14231
  var hasRequiredEncodeBinary;
14300
14232
 
@@ -14423,30 +14355,6 @@ function requireFormatDateOut$3 () {
14423
14355
  return formatDateOut_1$2;
14424
14356
  }
14425
14357
 
14426
- var encodeJSON;
14427
- var hasRequiredEncodeJSON;
14428
-
14429
- function requireEncodeJSON () {
14430
- if (hasRequiredEncodeJSON) return encodeJSON;
14431
- hasRequiredEncodeJSON = 1;
14432
- function encode(arg) {
14433
- if (Array.isArray(arg))
14434
- return new JsonBArrayParam(arg);
14435
- else
14436
- return arg;
14437
- }
14438
-
14439
- class JsonBArrayParam {
14440
- constructor(actualArray) { this.actualArray = actualArray; }
14441
- toPostgres() {
14442
- return JSON.stringify(this.actualArray);
14443
- }
14444
- }
14445
-
14446
- encodeJSON = encode;
14447
- return encodeJSON;
14448
- }
14449
-
14450
14358
  var lastInsertedSql_1$3;
14451
14359
  var hasRequiredLastInsertedSql$3;
14452
14360
 
@@ -14569,22 +14477,20 @@ function requireInsert$4 () {
14569
14477
  return insert$3;
14570
14478
  }
14571
14479
 
14572
- var newTransaction$9;
14573
- var hasRequiredNewTransaction$9;
14480
+ var newTransaction$a;
14481
+ var hasRequiredNewTransaction$a;
14574
14482
 
14575
- function requireNewTransaction$9 () {
14576
- if (hasRequiredNewTransaction$9) return newTransaction$9;
14577
- hasRequiredNewTransaction$9 = 1;
14578
- var wrapQuery = requireWrapQuery$8();
14483
+ function requireNewTransaction$a () {
14484
+ if (hasRequiredNewTransaction$a) return newTransaction$a;
14485
+ hasRequiredNewTransaction$a = 1;
14486
+ var wrapQuery = requireWrapQuery$9();
14579
14487
  var encodeDate = requireEncodeDate();
14580
- var encodeBoolean = requireEncodeBoolean$4();
14581
14488
  const encodeBinary = requireEncodeBinary();
14582
14489
  const decodeBinary = requireDecodeBinary();
14583
14490
  var deleteFromSql = requireDeleteFromSql$4();
14584
14491
  var selectForUpdateSql = requireSelectForUpdateSql$4();
14585
14492
  var limitAndOffset = requireLimitAndOffset$4();
14586
14493
  var formatDateOut = requireFormatDateOut$3();
14587
- var encodeJSON = requireEncodeJSON();
14588
14494
  var insertSql = requireInsertSql$4();
14589
14495
  var insert = requireInsert$4();
14590
14496
  var quote = requireQuote$4();
@@ -14597,11 +14503,9 @@ function requireNewTransaction$9 () {
14597
14503
  }
14598
14504
 
14599
14505
  rdb.engine = 'pg';
14600
- rdb.encodeBoolean = encodeBoolean;
14601
14506
  rdb.encodeDate = encodeDate;
14602
14507
  rdb.encodeBinary = encodeBinary;
14603
14508
  rdb.decodeBinary = decodeBinary;
14604
- rdb.encodeJSON = encodeJSON;
14605
14509
  rdb.formatDateOut = formatDateOut;
14606
14510
  rdb.deleteFromSql = deleteFromSql;
14607
14511
  rdb.selectForUpdateSql = selectForUpdateSql;
@@ -14661,53 +14565,578 @@ function requireNewTransaction$9 () {
14661
14565
  };
14662
14566
  }
14663
14567
 
14664
- newTransaction$9 = newResolveTransaction;
14665
- return newTransaction$9;
14568
+ newTransaction$a = newResolveTransaction;
14569
+ return newTransaction$a;
14666
14570
  }
14667
14571
 
14668
- var end$8;
14669
- var hasRequiredEnd$8;
14572
+ var end$9;
14573
+ var hasRequiredEnd$9;
14670
14574
 
14671
- function requireEnd$8 () {
14672
- if (hasRequiredEnd$8) return end$8;
14673
- hasRequiredEnd$8 = 1;
14575
+ function requireEnd$9 () {
14576
+ if (hasRequiredEnd$9) return end$9;
14577
+ hasRequiredEnd$9 = 1;
14674
14578
  var pools = requirePools();
14675
14579
 
14676
14580
  function endPool(pgPool, id, done) {
14677
14581
  pgPool.drain(onDrained);
14678
14582
 
14679
14583
  function onDrained() {
14584
+ //todo await
14680
14585
  pgPool.destroyAllNow();
14681
14586
  delete pools[id];
14682
14587
  done();
14683
14588
  }
14684
14589
  }
14685
14590
 
14686
- end$8 = endPool;
14687
- return end$8;
14591
+ end$9 = endPool;
14592
+ return end$9;
14688
14593
  }
14689
14594
 
14690
- var require$$3 = /*@__PURE__*/getDefaultExportFromNamespaceIfPresent(url);
14691
-
14692
14595
  /* eslint-disable no-prototype-builtins */
14693
14596
 
14694
- var newPgPool_1$1;
14695
- var hasRequiredNewPgPool$1;
14597
+ var newPgPool_1$2;
14598
+ var hasRequiredNewPgPool$2;
14696
14599
 
14697
- function requireNewPgPool$1 () {
14698
- if (hasRequiredNewPgPool$1) return newPgPool_1$1;
14699
- hasRequiredNewPgPool$1 = 1;
14600
+ function requireNewPgPool$2 () {
14601
+ if (hasRequiredNewPgPool$2) return newPgPool_1$2;
14602
+ hasRequiredNewPgPool$2 = 1;
14700
14603
  // Simplified pool creator using URL API and handling search_path param
14701
14604
 
14702
14605
  const log = requireLog();
14703
14606
  const defaults = requirePoolDefaults();
14704
14607
  const genericPool = requireGenericPool();
14705
- const { URL } = require$$3;
14706
- let SQL;
14608
+ let PGlite;
14707
14609
 
14708
14610
  function newPgPool(connectionString, poolOptions = {}) {
14709
- let searchPath;
14710
- let connStr = connectionString;
14611
+ let { connStr, searchPath } = extractSearchPath(connectionString);
14612
+
14613
+ //@ts-ignore
14614
+ const pool = genericPool.Pool({
14615
+ max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
14616
+ idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
14617
+ reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
14618
+ log: poolOptions.log,
14619
+
14620
+ create: async (cb) => {
14621
+ try {
14622
+ if (!PGlite) ({ PGlite } = await import('@electric-sql/pglite'));
14623
+ const client = connStr === undefined ? new PGlite() : new PGlite(connStr);
14624
+ client.poolCount = 0;
14625
+ await applySearchPath(client, searchPath);
14626
+ cb(null, client);
14627
+ } catch (err) {
14628
+ cb(err, null);
14629
+ }
14630
+ },
14631
+
14632
+ destroy: (client) => {
14633
+ client._destroying = true;
14634
+ client.poolCount = undefined;
14635
+ client.close();
14636
+ },
14637
+ });
14638
+
14639
+ pool.connect = (cb) => {
14640
+ pool.acquire((err, client) => {
14641
+ if (err) return cb(err, null, () => { });
14642
+ client.poolCount++;
14643
+ cb(null, client, (releaseErr) => {
14644
+ releaseErr ? pool.destroy(client) : pool.release(client);
14645
+ });
14646
+ });
14647
+ };
14648
+
14649
+ return pool;
14650
+ }
14651
+
14652
+ async function applySearchPath(client, searchPath) {
14653
+ if (searchPath) {
14654
+ const sql = `SET search_path TO ${searchPath}`;
14655
+ log.emitQuery({ sql, parameters: [] });
14656
+ await client.exec(sql);
14657
+ }
14658
+ }
14659
+
14660
+ function extractSearchPath(connectionString) {
14661
+ let connStr = connectionString;
14662
+ let searchPath;
14663
+
14664
+ // Guard: nothing to do
14665
+ if (typeof connectionString !== 'string' || connectionString.length === 0) {
14666
+ return { connStr, searchPath };
14667
+ }
14668
+
14669
+ // Split on the *first* "?" only
14670
+ const qPos = connectionString.indexOf('?');
14671
+ if (qPos === -1) {
14672
+ // No query-string segment
14673
+ return { connStr, searchPath };
14674
+ }
14675
+
14676
+ const pathPart = connectionString.slice(0, qPos);
14677
+ const qsPart = connectionString.slice(qPos + 1);
14678
+
14679
+ // Robust query-string handling via URLSearchParams
14680
+ const params = new URLSearchParams(qsPart);
14681
+
14682
+ const paramName = 'search_path';
14683
+
14684
+ {
14685
+ searchPath = params.get(paramName);
14686
+ params.delete(paramName);
14687
+ }
14688
+
14689
+ // Re-assemble the cleaned connection string
14690
+ const remainingQs = params.toString();
14691
+ connStr = remainingQs ? `${pathPart}?${remainingQs}` : pathPart;
14692
+
14693
+ return { connStr, searchPath };
14694
+ }
14695
+
14696
+
14697
+ newPgPool_1$2 = newPgPool;
14698
+ return newPgPool_1$2;
14699
+ }
14700
+
14701
+ var newPool_1$a;
14702
+ var hasRequiredNewPool$a;
14703
+
14704
+ function requireNewPool$a () {
14705
+ if (hasRequiredNewPool$a) return newPool_1$a;
14706
+ hasRequiredNewPool$a = 1;
14707
+ const promisify = requirePromisify();
14708
+ const pools = requirePools();
14709
+ const end = requireEnd$9();
14710
+ const newPgPool = requireNewPgPool$2();
14711
+ const newId = requireNewId();
14712
+
14713
+ function newPool(connectionString, poolOptions) {
14714
+ let pool = newPgPool(connectionString, poolOptions);
14715
+ let id = newId();
14716
+ let boundEnd = end.bind(null, pool, id);
14717
+ let c = {};
14718
+
14719
+ c.connect = pool.connect;
14720
+ c.end = promisify(boundEnd);
14721
+ pools[id] = c;
14722
+ return c;
14723
+ }
14724
+
14725
+ newPool_1$a = newPool;
14726
+ return newPool_1$a;
14727
+ }
14728
+
14729
+ var newDatabase_1$a;
14730
+ var hasRequiredNewDatabase$a;
14731
+
14732
+ function requireNewDatabase$a () {
14733
+ if (hasRequiredNewDatabase$a) return newDatabase_1$a;
14734
+ hasRequiredNewDatabase$a = 1;
14735
+ let createDomain = requireCreateDomain();
14736
+ let newTransaction = requireNewTransaction$a();
14737
+ let _begin = requireBegin();
14738
+ let commit = requireCommit();
14739
+ let rollback = requireRollback();
14740
+ let newPool = requireNewPool$a();
14741
+ let lock = requireLock();
14742
+ let executeSchema = requireSchema();
14743
+ let express = requireHostExpress();
14744
+ let hostLocal = requireHostLocal();
14745
+ let doQuery = requireQuery();
14746
+ let releaseDbClient = requireReleaseDbClient();
14747
+ let setSessionSingleton = requireSetSessionSingleton();
14748
+
14749
+ function newDatabase(connectionString, poolOptions) {
14750
+ var pool;
14751
+ if (!poolOptions)
14752
+ pool = newPool.bind(null, connectionString, poolOptions);
14753
+ else
14754
+ pool = newPool(connectionString, poolOptions);
14755
+
14756
+ let c = { poolFactory: pool, hostLocal, express };
14757
+
14758
+ c.transaction = function(options, fn) {
14759
+ if ((arguments.length === 1) && (typeof options === 'function')) {
14760
+ fn = options;
14761
+ options = undefined;
14762
+ }
14763
+ let domain = createDomain();
14764
+
14765
+ if (fn)
14766
+ return domain.run(runInTransaction);
14767
+ else
14768
+ return domain.run(run);
14769
+
14770
+ async function runInTransaction() {
14771
+ let result;
14772
+ let transaction = newTransaction(domain, pool, options);
14773
+ await new Promise(transaction)
14774
+ .then(begin)
14775
+ .then(negotiateSchema)
14776
+ .then(() => fn(domain))
14777
+ .then((res) => result = res)
14778
+ .then(() => commit(domain))
14779
+ .then(null, (e) => rollback(domain,e));
14780
+ return result;
14781
+ }
14782
+
14783
+ function begin() {
14784
+ return _begin(domain, options);
14785
+ }
14786
+
14787
+ function run() {
14788
+ let p;
14789
+ let transaction = newTransaction(domain, pool, options);
14790
+ p = new Promise(transaction);
14791
+
14792
+ return p.then(begin)
14793
+ .then(negotiateSchema);
14794
+ }
14795
+
14796
+ function negotiateSchema(previous) {
14797
+ let schema = options && options.schema;
14798
+ if (!schema)
14799
+ return previous;
14800
+ return executeSchema(domain, schema);
14801
+ }
14802
+ };
14803
+
14804
+ c.createTransaction = function(options) {
14805
+ let domain = createDomain();
14806
+ let transaction = newTransaction(domain, pool, options);
14807
+ let p = domain.run(() => new Promise(transaction)
14808
+ .then(begin).then(negotiateSchema));
14809
+
14810
+ function run(fn) {
14811
+ return p.then(domain.run.bind(domain, fn));
14812
+ }
14813
+
14814
+ function begin() {
14815
+ return _begin(domain, options);
14816
+ }
14817
+
14818
+ function negotiateSchema(previous) {
14819
+ let schema = options && options.schema;
14820
+ if (!schema)
14821
+ return previous;
14822
+ return executeSchema(domain,schema);
14823
+ }
14824
+
14825
+ run.rollback = rollback.bind(null, domain);
14826
+ run.commit = commit.bind(null, domain);
14827
+
14828
+ return run;
14829
+ };
14830
+
14831
+ c.query = function(query) {
14832
+ let domain = createDomain();
14833
+ let transaction = newTransaction(domain, pool);
14834
+ let p = domain.run(() => new Promise(transaction)
14835
+ .then(() => setSessionSingleton(domain, 'changes', []))
14836
+ .then(() => doQuery(domain, query).then(onResult, onError)));
14837
+ return p;
14838
+
14839
+ function onResult(result) {
14840
+ releaseDbClient(domain);
14841
+ return result;
14842
+ }
14843
+
14844
+ function onError(e) {
14845
+ releaseDbClient(domain);
14846
+ throw e;
14847
+ }
14848
+ };
14849
+
14850
+ c.rollback = rollback;
14851
+ c.commit = commit;
14852
+ c.lock = lock;
14853
+ c.schema = executeSchema;
14854
+
14855
+ c.end = function() {
14856
+ if (poolOptions)
14857
+ return pool.end();
14858
+ else
14859
+ return Promise.resolve();
14860
+ };
14861
+
14862
+ c.accept = function(caller) {
14863
+ caller.visitPg();
14864
+ };
14865
+
14866
+ return c;
14867
+ }
14868
+
14869
+ newDatabase_1$a = newDatabase;
14870
+ return newDatabase_1$a;
14871
+ }
14872
+
14873
+ var wrapQuery_1$8;
14874
+ var hasRequiredWrapQuery$8;
14875
+
14876
+ function requireWrapQuery$8 () {
14877
+ if (hasRequiredWrapQuery$8) return wrapQuery_1$8;
14878
+ hasRequiredWrapQuery$8 = 1;
14879
+ const log = requireLog();
14880
+ const replaceParamChar = requireReplaceParamChar$1();
14881
+ const tryGetSessionContext = requireTryGetSessionContext();
14882
+
14883
+ function wrapQuery(context, connection) {
14884
+ return runQuery;
14885
+
14886
+ async function runQuery(query, onCompleted) {
14887
+ try {
14888
+
14889
+ const sql = replaceParamChar(query, query.parameters);
14890
+ let rdb = tryGetSessionContext(context);
14891
+ let transactionHandler = rdb.transactionHandler;
14892
+ log.emitQuery({ sql, parameters: query.parameters });
14893
+
14894
+ if (sql.length < 18 && query.parameters.length === 0) {
14895
+ if (sql === 'BEGIN TRANSACTION' || sql === 'BEGIN') {
14896
+ if (transactionHandler)
14897
+ return onCompleted(new Error('Already inside a transaction'), []);
14898
+ beginTransaction(connection).then(_transactionHandler => {
14899
+ rdb.transactionHandler = _transactionHandler;
14900
+ onCompleted(null, []);
14901
+ }, onCompleted);
14902
+ return;
14903
+ }
14904
+ else if (sql === 'COMMIT') {
14905
+ if (!transactionHandler)
14906
+ return onCompleted(new Error('Cannot commit outside transaction'), []);
14907
+ transactionHandler.resolve();
14908
+ transactionHandler.promise.then(() => onCompleted(null, []), err => onCompleted(err, []));
14909
+ return;
14910
+ }
14911
+ else if (sql === 'ROLLBACK') {
14912
+ if (!transactionHandler)
14913
+ return onCompleted(new Error('Cannot rollback outside transaction'), []);
14914
+ transactionHandler.reject(new Error('__rollback__'));
14915
+ transactionHandler.promise.then(null, (err) => {
14916
+ if (err.message === '__rollback__')
14917
+ onCompleted(null, []);
14918
+ else
14919
+ onCompleted(err, []);
14920
+ });
14921
+ return;
14922
+ }
14923
+ }
14924
+
14925
+ let result;
14926
+ const _connection = transactionHandler?.tx || connection;
14927
+ if (query.parameters.length === 0)
14928
+ result = await _connection.unsafe(sql);
14929
+ else
14930
+ result = await _connection.unsafe(sql, query.parameters);
14931
+ onCompleted(null, result);
14932
+ }
14933
+ catch (e) {
14934
+ onCompleted(e);
14935
+ }
14936
+ }
14937
+
14938
+ }
14939
+
14940
+ function beginTransaction(connection) {
14941
+
14942
+ let beginIsResolved = false;
14943
+ let resolve;
14944
+ let reject;
14945
+ let resolveBegin;
14946
+ let rejectBegin;
14947
+
14948
+ let sqlPromise = new Promise((res, rej) => {
14949
+ resolve = res;
14950
+ reject = rej;
14951
+ });
14952
+ let beginPromise = new Promise((res,rej) => {
14953
+ resolveBegin = res;
14954
+ rejectBegin = rej;
14955
+ });
14956
+ connection.begin(async (tx) => {
14957
+ beginIsResolved = true;
14958
+ resolveBegin({
14959
+ tx,
14960
+ resolve,
14961
+ reject,
14962
+ promise: sqlPromise,
14963
+ });
14964
+ return sqlPromise;
14965
+ }).then(null,
14966
+ e => {
14967
+ if (!beginIsResolved)
14968
+ rejectBegin(e);
14969
+ if (e?.message !== '__rollback__')
14970
+ throw e;
14971
+ });
14972
+ return beginPromise;
14973
+ }
14974
+
14975
+ wrapQuery_1$8 = wrapQuery;
14976
+ return wrapQuery_1$8;
14977
+ }
14978
+
14979
+ var encodeJSON;
14980
+ var hasRequiredEncodeJSON;
14981
+
14982
+ function requireEncodeJSON () {
14983
+ if (hasRequiredEncodeJSON) return encodeJSON;
14984
+ hasRequiredEncodeJSON = 1;
14985
+ function encode(arg) {
14986
+ if (Array.isArray(arg))
14987
+ return new JsonBArrayParam(arg);
14988
+ else
14989
+ return arg;
14990
+ }
14991
+
14992
+ class JsonBArrayParam {
14993
+ constructor(actualArray) { this.actualArray = actualArray; }
14994
+ toPostgres() {
14995
+ return JSON.stringify(this.actualArray);
14996
+ }
14997
+ }
14998
+
14999
+ encodeJSON = encode;
15000
+ return encodeJSON;
15001
+ }
15002
+
15003
+ var newTransaction$9;
15004
+ var hasRequiredNewTransaction$9;
15005
+
15006
+ function requireNewTransaction$9 () {
15007
+ if (hasRequiredNewTransaction$9) return newTransaction$9;
15008
+ hasRequiredNewTransaction$9 = 1;
15009
+ var wrapQuery = requireWrapQuery$8();
15010
+ var encodeDate = requireEncodeDate();
15011
+ const encodeBinary = requireEncodeBinary();
15012
+ const decodeBinary = requireDecodeBinary();
15013
+ var deleteFromSql = requireDeleteFromSql$4();
15014
+ var selectForUpdateSql = requireSelectForUpdateSql$4();
15015
+ var limitAndOffset = requireLimitAndOffset$4();
15016
+ var formatDateOut = requireFormatDateOut$3();
15017
+ var encodeJSON = requireEncodeJSON();
15018
+ var insertSql = requireInsertSql$4();
15019
+ var insert = requireInsert$4();
15020
+ var quote = requireQuote$4();
15021
+
15022
+ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
15023
+ var rdb = { poolFactory: pool };
15024
+ if (!pool.connect) {
15025
+ pool = pool();
15026
+ rdb.pool = pool;
15027
+ }
15028
+
15029
+ rdb.engine = 'pg';
15030
+ rdb.encodeDate = encodeDate;
15031
+ rdb.encodeBinary = encodeBinary;
15032
+ rdb.decodeBinary = decodeBinary;
15033
+ rdb.encodeJSON = encodeJSON;
15034
+ rdb.formatDateOut = formatDateOut;
15035
+ rdb.deleteFromSql = deleteFromSql;
15036
+ rdb.selectForUpdateSql = selectForUpdateSql;
15037
+ rdb.lastInsertedIsSeparate = false;
15038
+ rdb.insertSql = insertSql;
15039
+ rdb.insert = insert;
15040
+ rdb.multipleStatements = true;
15041
+ rdb.limitAndOffset = limitAndOffset;
15042
+ rdb.accept = function(caller) {
15043
+ caller.visitPg();
15044
+ };
15045
+ rdb.aggregateCount = 0;
15046
+ rdb.quote = quote;
15047
+ rdb.cache = {};
15048
+
15049
+ if (readonly) {
15050
+ rdb.dbClient = {
15051
+ executeQuery: function(query, callback) {
15052
+ pool.connect((err, client, done) => {
15053
+ if (err) {
15054
+ return callback(err);
15055
+ }
15056
+ try {
15057
+ wrapQuery(domain, client)(query, (err, res) => {
15058
+ done();
15059
+ callback(err, res);
15060
+ });
15061
+ } catch (e) {
15062
+ done();
15063
+ callback(e);
15064
+ }
15065
+ });
15066
+ }
15067
+ };
15068
+ domain.rdb = rdb;
15069
+ return (onSuccess) => onSuccess();
15070
+ }
15071
+
15072
+ return function(onSuccess, onError) {
15073
+ pool.connect(onConnected);
15074
+
15075
+ function onConnected(err, client, done) {
15076
+ try {
15077
+ if (err) {
15078
+ onError(err);
15079
+ return;
15080
+ }
15081
+ client.executeQuery = wrapQuery(domain, client);
15082
+ rdb.dbClient = client;
15083
+ rdb.dbClientDone = done;
15084
+ domain.rdb = rdb;
15085
+ onSuccess();
15086
+ } catch (e) {
15087
+ onError(e);
15088
+ }
15089
+ }
15090
+ };
15091
+ }
15092
+
15093
+ newTransaction$9 = newResolveTransaction;
15094
+ return newTransaction$9;
15095
+ }
15096
+
15097
+ var end$8;
15098
+ var hasRequiredEnd$8;
15099
+
15100
+ function requireEnd$8 () {
15101
+ if (hasRequiredEnd$8) return end$8;
15102
+ hasRequiredEnd$8 = 1;
15103
+ var pools = requirePools();
15104
+
15105
+ function endPool(pgPool, id, done) {
15106
+ pgPool.drain(onDrained);
15107
+
15108
+ function onDrained() {
15109
+ pgPool.destroyAllNow();
15110
+ delete pools[id];
15111
+ done();
15112
+ }
15113
+ }
15114
+
15115
+ end$8 = endPool;
15116
+ return end$8;
15117
+ }
15118
+
15119
+ var require$$3 = /*@__PURE__*/getDefaultExportFromNamespaceIfPresent(url);
15120
+
15121
+ /* eslint-disable no-prototype-builtins */
15122
+
15123
+ var newPgPool_1$1;
15124
+ var hasRequiredNewPgPool$1;
15125
+
15126
+ function requireNewPgPool$1 () {
15127
+ if (hasRequiredNewPgPool$1) return newPgPool_1$1;
15128
+ hasRequiredNewPgPool$1 = 1;
15129
+ // Simplified pool creator using URL API and handling search_path param
15130
+
15131
+ const log = requireLog();
15132
+ const defaults = requirePoolDefaults();
15133
+ const genericPool = requireGenericPool();
15134
+ const { URL } = require$$3;
15135
+ let SQL;
15136
+
15137
+ function newPgPool(connectionString, poolOptions = {}) {
15138
+ let searchPath;
15139
+ let connStr = connectionString;
14711
15140
 
14712
15141
  try {
14713
15142
  const url = new URL(connectionString);
@@ -14992,6 +15421,20 @@ function requireWrapQuery$7 () {
14992
15421
  return wrapQuery_1$7;
14993
15422
  }
14994
15423
 
15424
+ var encodeBoolean_1$4;
15425
+ var hasRequiredEncodeBoolean$4;
15426
+
15427
+ function requireEncodeBoolean$4 () {
15428
+ if (hasRequiredEncodeBoolean$4) return encodeBoolean_1$4;
15429
+ hasRequiredEncodeBoolean$4 = 1;
15430
+ function encodeBoolean(bool) {
15431
+ return bool.toString();
15432
+ }
15433
+
15434
+ encodeBoolean_1$4 = encodeBoolean;
15435
+ return encodeBoolean_1$4;
15436
+ }
15437
+
14995
15438
  var newTransaction$8;
14996
15439
  var hasRequiredNewTransaction$8;
14997
15440
 
@@ -19989,6 +20432,7 @@ function requireSrc () {
19989
20432
 
19990
20433
  let _mySql;
19991
20434
  let _pg;
20435
+ let _pglite;
19992
20436
  let _sqlite;
19993
20437
  let _mssqlNative;
19994
20438
  let _sap;
@@ -20025,7 +20469,7 @@ function requireSrc () {
20025
20469
  Object.defineProperty(connectViaPool, 'mysql', {
20026
20470
  get: function() {
20027
20471
  if (!_mySql)
20028
- _mySql = requireNewDatabase$a();
20472
+ _mySql = requireNewDatabase$b();
20029
20473
  return _mySql;
20030
20474
  }
20031
20475
  });
@@ -20033,10 +20477,17 @@ function requireSrc () {
20033
20477
  Object.defineProperty(connectViaPool, 'mySql', {
20034
20478
  get: function() {
20035
20479
  if (!_mySql)
20036
- _mySql = requireNewDatabase$a();
20480
+ _mySql = requireNewDatabase$b();
20037
20481
  return _mySql;
20038
20482
  }
20039
20483
  });
20484
+ Object.defineProperty(connectViaPool, 'pglite', {
20485
+ get: function() {
20486
+ if (!_pglite)
20487
+ _pglite = requireNewDatabase$a();
20488
+ return _pglite;
20489
+ }
20490
+ });
20040
20491
  Object.defineProperty(connectViaPool, 'postgres', {
20041
20492
  get: function() {
20042
20493
  if (!_pg)