orange-orm 4.7.10-beta.3 → 4.7.11-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 (48) hide show
  1. package/dist/index.browser.mjs +264 -113
  2. package/dist/index.mjs +431 -122
  3. package/package.json +1 -1
  4. package/src/bunSqlite/newTransaction.js +2 -0
  5. package/src/d1/newTransaction.js +2 -0
  6. package/src/map.d.ts +39 -0
  7. package/src/map2.d.ts +5 -5
  8. package/src/mssql/formatBigintIn.js +5 -0
  9. package/src/mssql/newTransaction.js +4 -0
  10. package/src/mssql/pool/newGenericPool.js +7 -0
  11. package/src/mssql/wrapQuery.js +1 -0
  12. package/src/mySql/formatBigintOut.js +11 -0
  13. package/src/mySql/newTransaction.js +2 -0
  14. package/src/nodeSqlite/newTransaction.js +2 -0
  15. package/src/oracle/formatBigintOut.js +12 -0
  16. package/src/oracle/formatDateOut.js +4 -1
  17. package/src/oracle/insertSql.js +2 -2
  18. package/src/oracle/mergeSql.js +1 -1
  19. package/src/oracle/newTransaction.js +2 -0
  20. package/src/pg/formatDateOut.js +4 -1
  21. package/src/sap/encodeBigint.js +8 -0
  22. package/src/sap/formatBigintIn.js +5 -0
  23. package/src/sap/formatBigintOut.js +11 -0
  24. package/src/sap/formatDateOut.js +4 -1
  25. package/src/sap/insertSql.js +1 -1
  26. package/src/sap/mergeSql.js +1 -1
  27. package/src/sap/newTransaction.js +4 -0
  28. package/src/sqlite/formatBigintOut.js +11 -0
  29. package/src/sqlite/lastInsertedSql.js +1 -1
  30. package/src/sqlite3/newTransaction.js +2 -0
  31. package/src/table/column/bigint/newDecode.js +18 -0
  32. package/src/table/column/bigint/newEncode.js +44 -0
  33. package/src/table/column/bigint.js +16 -0
  34. package/src/table/column/date/formatOut.js +3 -1
  35. package/src/table/column/formatOutGeneric.js +14 -0
  36. package/src/table/column/in.js +7 -5
  37. package/src/table/column/json.js +2 -2
  38. package/src/table/column.js +5 -0
  39. package/src/table/commands/newGetLastInsertedCommandCore.js +11 -1
  40. package/src/table/commands/newInsertCommandCore.js +1 -1
  41. package/src/tedious/formatBigintOut.js +11 -0
  42. package/src/tedious/formatDateOut.js +4 -1
  43. package/src/tedious/formatJSONOut.js +4 -1
  44. package/src/tedious/insertSql.js +5 -5
  45. package/src/tedious/mergeSql.js +3 -3
  46. package/src/tedious/newTransaction.js +2 -0
  47. package/src/tedious/outputInsertedSql.js +11 -2
  48. package/src/table/column/json/formatOut.js +0 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.7.10-beta.3",
3
+ "version": "4.7.11-beta.0",
4
4
  "main": "./src/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "browser": "./dist/index.browser.mjs",
@@ -2,6 +2,7 @@ const wrapQuery = require('./wrapQuery');
2
2
  const encodeBoolean = require('../sqlite/encodeBoolean');
3
3
  const encodeBinary = require('../nodeSqlite/encodeBinary');
4
4
  const decodeBinary = require('../nodeSqlite/decodeBinary');
5
+ const formatBigintOut = require('../sqlite/formatBigintOut');
5
6
  const deleteFromSql = require('../sqlite/deleteFromSql');
6
7
  const selectForUpdateSql = require('../sqlite/selectForUpdateSql');
7
8
  const lastInsertedSql = require('../sqlite/lastInsertedSql');
@@ -20,6 +21,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
20
21
  rdb.encodeBoolean = encodeBoolean;
21
22
  rdb.encodeBinary = encodeBinary;
22
23
  rdb.decodeBinary = decodeBinary;
24
+ rdb.formatBigintOut = formatBigintOut;
23
25
  rdb.decodeJSON = decodeJSON;
24
26
  rdb.encodeJSON = JSON.stringify;
25
27
  rdb.deleteFromSql = deleteFromSql;
@@ -1,5 +1,6 @@
1
1
  const wrapQuery = require('./wrapQuery');
2
2
  const encodeBoolean = require('../sqlite/encodeBoolean');
3
+ const formatBigintOut = require('../sqlite/formatBigintOut');
3
4
  const deleteFromSql = require('../sqlite/deleteFromSql');
4
5
  const selectForUpdateSql = require('../sqlite/selectForUpdateSql');
5
6
  const lastInsertedSql = require('../sqlite/lastInsertedSql');
@@ -18,6 +19,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
18
19
  rdb.encodeBoolean = encodeBoolean;
19
20
  rdb.decodeJSON = decodeJSON;
20
21
  rdb.encodeJSON = JSON.stringify;
22
+ rdb.formatBigintOut = formatBigintOut;
21
23
  rdb.deleteFromSql = deleteFromSql;
22
24
  rdb.selectForUpdateSql = selectForUpdateSql;
23
25
  rdb.lastInsertedSql = lastInsertedSql;
package/src/map.d.ts CHANGED
@@ -102,6 +102,8 @@ type ColumnToType<T> = T extends UuidColumnSymbol
102
102
  ? string
103
103
  : T extends NumericColumnSymbol
104
104
  ? number
105
+ : T extends BigIntColumnSymbol
106
+ ? bigint
105
107
  : T extends DateColumnSymbol
106
108
  ? string | Date
107
109
  : T extends DateWithTimeZoneColumnSymbol
@@ -134,6 +136,7 @@ type RelatedColumns<T> = RemoveNeverFlat<{
134
136
  T[K] extends StringColumnTypeDef<infer M> ? StringColumnSymbol
135
137
  : T[K] extends UuidColumnTypeDef<infer M> ? UuidColumnSymbol
136
138
  : T[K] extends NumericColumnTypeDef<infer M> ? NumericColumnSymbol
139
+ : T[K] extends BigIntColumnTypeDef<infer M> ? BigIntColumnSymbol
137
140
  : T[K] extends DateColumnTypeDef<infer M> ? DateColumnSymbol
138
141
  : T[K] extends DateWithTimeZoneColumnTypeDef<infer M> ? DateWithTimeZoneColumnSymbol
139
142
  : T[K] extends BinaryColumnTypeDef<infer M> ? BinaryColumnSymbol
@@ -149,6 +152,7 @@ type RelatedColumns<T> = RemoveNeverFlat<{
149
152
  type AggregateColumns<T> = RemoveNeverFlat<{
150
153
  [K in keyof T]:
151
154
  T[K] extends NumericColumnTypeDef<infer M> ? NumericColumnSymbol
155
+ : T[K] extends BigIntColumnTypeDef<infer M> ? BigIntColumnSymbol
152
156
  : T[K] extends ManyRelation
153
157
  ? AggregateColumns<T[K]>
154
158
  : T[K] extends RelatedTable
@@ -174,6 +178,7 @@ type ColumnSymbols =
174
178
  | StringColumnSymbol
175
179
  | UuidColumnSymbol
176
180
  | NumericColumnSymbol
181
+ | BigIntColumnSymbol
177
182
  | DateColumnSymbol
178
183
  | DateWithTimeZoneColumnSymbol
179
184
  | BooleanColumnSymbol
@@ -245,6 +250,8 @@ type ToColumnTypes<T> = {
245
250
  ? StringColumnSymbol
246
251
  : T[K] extends NumericColumnSymbol
247
252
  ? NumericColumnSymbol
253
+ : T[K] extends BigIntColumnSymbol
254
+ ? BigIntColumnSymbol
248
255
  : T[K] extends DateColumnSymbol
249
256
  ? DateColumnSymbol
250
257
  : T[K] extends DateWithTimeZoneColumnSymbol
@@ -593,6 +600,12 @@ type NumericColumnSymbol = {
593
600
  type NumericColumnType<M> = M &
594
601
  NumericColumnSymbol;
595
602
 
603
+ type BigIntColumnSymbol = {
604
+ [' isBigInt']: true;
605
+ };
606
+ type BigIntColumnType<M> = M &
607
+ BigIntColumnSymbol;
608
+
596
609
  type JSONColumnSymbol = {
597
610
  [' isJSON']: true;
598
611
  };
@@ -621,6 +634,7 @@ interface ColumnType<M> {
621
634
  string(): StringColumnTypeDef<M & StringColumnSymbol>;
622
635
  uuid(): UuidColumnTypeDef<M & UuidColumnSymbol>;
623
636
  numeric(): NumericColumnTypeDef<M & NumericColumnSymbol>;
637
+ bigint(): BigIntColumnTypeDef<M & BigIntColumnSymbol>;
624
638
  date(): DateColumnTypeDef<M & DateColumnSymbol>;
625
639
  dateWithTimeZone(): DateWithTimeZoneColumnTypeDef<M & DateWithTimeZoneColumnSymbol>;
626
640
  binary(): BinaryColumnTypeDef<M & BinaryColumnSymbol>;
@@ -657,6 +671,15 @@ type NumericValidator<M> = M extends NotNull
657
671
  validator: (value?: number | null) => void
658
672
  ): NumericColumnTypeDef<M>;
659
673
  };
674
+ type BigIntValidator<M> = M extends NotNull
675
+ ? {
676
+ validate(validator: (value: bigint) => void): BigIntColumnTypeDef<M>;
677
+ }
678
+ : {
679
+ validate(
680
+ validator: (value?: bigint | null) => void
681
+ ): BigIntColumnTypeDef<M>;
682
+ };
660
683
  type BinaryValidator<M> = M extends NotNull
661
684
  ? {
662
685
  validate(validator: (value: string) => void): BinaryColumnTypeDef<M>;
@@ -732,6 +755,17 @@ type NumericColumnTypeDef<M> = NumericValidator<M> & {
732
755
  } & ColumnTypeOf<NumericColumnType<M>> &
733
756
  M;
734
757
 
758
+ type BigIntColumnTypeDef<M> = BigIntValidator<M> & {
759
+ primary(): BigIntColumnTypeDef<M & IsPrimary> & IsPrimary;
760
+ notNull(): BigIntColumnTypeDef<M & NotNull> & NotNull;
761
+ notNullExceptInsert(): BigIntColumnTypeDef<M & NotNull & NotNullExceptInsert> & NotNull & NotNullExceptInsert;
762
+ serializable(value: boolean): BigIntColumnTypeDef<M>;
763
+ JSONSchema(schema: object, options?: Options): BigIntColumnTypeDef<M>;
764
+ default(value: bigint | null | undefined | (() => bigint | null | undefined)): BigIntColumnTypeDef<M>;
765
+ dbNull(value: bigint): BigIntColumnTypeDef<M>;
766
+ } & ColumnTypeOf<BigIntColumnType<M>> &
767
+ M;
768
+
735
769
  type UuidColumnTypeDef<M> = UuidValidator<M> & {
736
770
  primary(): UuidColumnTypeDef<M & IsPrimary> & IsPrimary;
737
771
  notNull(): UuidColumnTypeDef<M & NotNull> & NotNull;
@@ -992,6 +1026,11 @@ type ColumnToSchemaType<T> =
992
1026
  & (T extends NotNullExceptInsert ? { ' notNull': true; ' notNullExceptInsert': true }
993
1027
  : T extends NotNull ? { ' notNull': true }
994
1028
  : {}) :
1029
+ T extends BigIntColumnSymbol
1030
+ ? { ' type': 'bigint' }
1031
+ & (T extends NotNullExceptInsert ? { ' notNull': true; ' notNullExceptInsert': true }
1032
+ : T extends NotNull ? { ' notNull': true }
1033
+ : {}) :
995
1034
  T extends DateColumnSymbol | DateWithTimeZoneColumnSymbol
996
1035
  ? { ' type': 'date' }
997
1036
  & (T extends NotNullExceptInsert ? { ' notNull': true; ' notNullExceptInsert': true }
package/src/map2.d.ts CHANGED
@@ -676,20 +676,20 @@ export type TableClient<M extends Record<string, TableDefinition<M>>, K extends
676
676
  // Array methods - return arrays with array-level active record methods, but individual items are plain
677
677
  getAll(): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
678
678
  getAll<strategy extends FetchStrategy<M, K>>(strategy: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
679
- getMany(filter: RawFilter | Array<PrimaryKeyObject<M, K>>): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
680
- getMany<strategy extends FetchStrategy<M, K>>(filter: RawFilter | Array<PrimaryKeyObject<M, K>>, strategy: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
679
+ getMany(filter?: RawFilter | Array<PrimaryKeyObject<M, K>>): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, {}>>>, M, K>>;
680
+ getMany<strategy extends FetchStrategy<M, K>>(filter?: RawFilter | Array<PrimaryKeyObject<M, K>>, strategy?: strategy): Promise<WithArrayActiveRecord<Array<DeepExpand<Selection<M, K, strategy>>>, M, K>>;
681
681
 
682
682
  // Aggregate methods - return plain objects (no active record methods)
683
683
  aggregate<strategy extends AggregateStrategy<M, K>>(strategy: strategy): Promise<Array<DeepExpand<AggregateCustomSelectorProperties<M, K, strategy>>>>;
684
684
 
685
685
  // Single item methods - return individual objects with individual active record methods
686
686
  getOne<strategy extends FetchStrategy<M, K>>(
687
- filter: RawFilter | Array<PrimaryKeyObject<M, K>>
687
+ filter?: RawFilter | Array<PrimaryKeyObject<M, K>>
688
688
  ): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
689
689
 
690
690
  getOne<strategy extends FetchStrategy<M, K>>(
691
- filter: RawFilter | Array<PrimaryKeyObject<M, K>>,
692
- strategy: strategy
691
+ filter?: RawFilter | Array<PrimaryKeyObject<M, K>>,
692
+ strategy?: strategy
693
693
  ): Promise<WithActiveRecord<DeepExpand<Selection<M, K, strategy>>, M, K>>;
694
694
 
695
695
  getById<strategy extends FetchStrategy<M, K>>(
@@ -0,0 +1,5 @@
1
+ function formatBigintIn(value) {
2
+ return `CONVERT(BIGINT, ${value})`;
3
+ }
4
+
5
+ module.exports = formatBigintIn;
@@ -4,6 +4,8 @@ var deleteFromSql = require('../tedious/deleteFromSql');
4
4
  var selectForUpdateSql = require('../tedious/selectForUpdateSql');
5
5
  const limitAndOffset = require('../tedious/limitAndOffset');
6
6
  const formatDateOut = require('../tedious/formatDateOut');
7
+ const formatBigintOut = require('../tedious/formatBigintOut');
8
+ const formatBigintIn = require('./formatBigintIn');
7
9
  const formatJSONOut = require('../tedious/formatJSONOut');
8
10
  const insertSql = require('../tedious/insertSql');
9
11
  const insert = require('../tedious/insert');
@@ -20,6 +22,8 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
20
22
  rdb.decodeJSON = decodeJSON;
21
23
  rdb.encodeJSON = JSON.stringify;
22
24
  rdb.formatDateOut = formatDateOut;
25
+ rdb.formatBigintOut = formatBigintOut;
26
+ rdb.formatBigintIn = formatBigintIn;
23
27
  rdb.formatJSONOut = formatJSONOut;
24
28
  rdb.deleteFromSql = deleteFromSql;
25
29
  rdb.selectForUpdateSql = selectForUpdateSql;
@@ -22,12 +22,19 @@ function newGenericPool(connectionString, poolOptions) {
22
22
  return cb(err, null);
23
23
  }
24
24
  var client;
25
+ // const config = {
26
+ // connectionString: connectionString,
27
+ // options: {
28
+ // useNumericString: true
29
+ // }
30
+ // };
25
31
  mssql.open(connectionString, onConnected);
26
32
 
27
33
  function onConnected(err, _client) {
28
34
  if(err)
29
35
  return cb(err, null);
30
36
  client = _client;
37
+ // client.setUseNumericString(true);
31
38
  client.poolCount = 0;
32
39
  client.msnodesqlv8 = mssql;
33
40
  return cb(null, client);
@@ -113,6 +113,7 @@ function wrapQuery(_context, connection) {
113
113
  result.push(rows);
114
114
  return;
115
115
  }
116
+
116
117
  result.push(rows);
117
118
  if (!hasMore) {
118
119
  if (result.length === 1)
@@ -0,0 +1,11 @@
1
+ const quote = require('./quote');
2
+
3
+ function formatBigintOut(column, alias) {
4
+ const quotedCol = quote(column._dbName);
5
+ if (alias)
6
+ return `CAST(${alias}.${quotedCol} AS CHAR)`;
7
+ else
8
+ return `CAST(${quotedCol} AS CHAR)`;
9
+ }
10
+
11
+ module.exports = formatBigintOut;
@@ -4,6 +4,7 @@ const deleteFromSql = require('./deleteFromSql');
4
4
  const selectForUpdateSql = require('./selectForUpdateSql');
5
5
  const lastInsertedSql = require('./lastInsertedSql');
6
6
  const limitAndOffset = require('./limitAndOffset');
7
+ const formatBigintOut = require('./formatBigintOut');
7
8
  const insertSql = require('./insertSql');
8
9
  const insert = require('./insert');
9
10
  const quote = require('./quote');
@@ -21,6 +22,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
21
22
  rdb.selectForUpdateSql = selectForUpdateSql;
22
23
  rdb.lastInsertedIsSeparate = true;
23
24
  rdb.lastInsertedSql = lastInsertedSql;
25
+ rdb.formatBigintOut = formatBigintOut;
24
26
  rdb.insertSql = insertSql;
25
27
  rdb.insert = insert;
26
28
  rdb.multipleStatements = false;
@@ -6,6 +6,7 @@ const deleteFromSql = require('../sqlite/deleteFromSql');
6
6
  const selectForUpdateSql = require('../sqlite/selectForUpdateSql');
7
7
  const lastInsertedSql = require('../sqlite/lastInsertedSql');
8
8
  const limitAndOffset = require('../sqlite/limitAndOffset');
9
+ const formatBigintOut = require('../sqlite/formatBigintOut');
9
10
  const insertSql = require('../sqlite/insertSql');
10
11
  const insert = require('../sqlite/insert');
11
12
  const quote = require('../sqlite/quote');
@@ -22,6 +23,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
22
23
  rdb.decodeBinary = decodeBinary;
23
24
  rdb.decodeJSON = decodeJSON;
24
25
  rdb.encodeJSON = JSON.stringify;
26
+ rdb.formatBigintOut = formatBigintOut;
25
27
  rdb.deleteFromSql = deleteFromSql;
26
28
  rdb.selectForUpdateSql = selectForUpdateSql;
27
29
  rdb.lastInsertedSql = lastInsertedSql;
@@ -0,0 +1,12 @@
1
+ const quote = require('./quote');
2
+
3
+ function formatBigintOut(column, alias) {
4
+ const quotedCol = quote(column._dbName);
5
+ if (alias)
6
+ return `TO_CHAR(${alias}.${quotedCol})`;
7
+ else
8
+ return `TO_CHAR(${quotedCol})`;
9
+ }
10
+
11
+
12
+ module.exports = formatBigintOut;
@@ -1,7 +1,10 @@
1
1
  const quote = require('./quote');
2
2
 
3
3
  function formatDateColumn(column, alias) {
4
- return `TO_CHAR(${alias}.${quote(column._dbName)}, 'YYYY-MM-DD"T"HH24:MI:SS.FF3')`;
4
+ if (alias)
5
+ return `TO_CHAR(${alias}.${quote(column._dbName)}, 'YYYY-MM-DD"T"HH24:MI:SS.FF3')`;
6
+ else
7
+ return `TO_CHAR(${quote(column._dbName)}, 'YYYY-MM-DD"T"HH24:MI:SS.FF3')`;
5
8
  }
6
9
 
7
10
  module.exports = formatDateColumn;
@@ -1,9 +1,9 @@
1
1
  let mergeSql = require('./mergeSql');
2
2
  const quote = require('./quote');
3
3
 
4
- function getSqlTemplate(_context, _table, _row, options) {
4
+ function getSqlTemplate(context, _table, _row, options) {
5
5
  if (hasConcurrency(_table, options) && hasColumns())
6
- return mergeSql.apply(null, [...arguments].slice(1));
6
+ return mergeSql.apply(null, [...arguments]);
7
7
  else
8
8
  return insertSql.apply(null, [...arguments].slice(1));
9
9
 
@@ -1,6 +1,6 @@
1
1
  const quote = require('./quote');
2
2
 
3
- function insertSql(table, row, options) {
3
+ function insertSql(context, table, row, options) {
4
4
  let columnNames = [];
5
5
  let regularColumnNames = [];
6
6
  let conflictColumnUpdateSql = '';
@@ -6,6 +6,7 @@ const lastInsertedSql = require('./lastInsertedSql');
6
6
  const limitAndOffset = require('./limitAndOffset');
7
7
  const insertSql = require('./insertSql');
8
8
  const insert = require('./insert');
9
+ const formatBigintOut = require('./formatBigintOut');
9
10
  const formatDateOut = require('./formatDateOut');
10
11
  const formatDateIn = require('./formatDateIn');
11
12
  const quote = require('./quote');
@@ -24,6 +25,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
24
25
  rdb.encodeJSON = JSON.stringify;
25
26
  rdb.formatDateOut = formatDateOut;
26
27
  rdb.formatDateIn = formatDateIn;
28
+ rdb.formatBigintOut = formatBigintOut;
27
29
  rdb.deleteFromSql = deleteFromSql;
28
30
  rdb.selectForUpdateSql = selectForUpdateSql;
29
31
  rdb.lastInsertedSql = lastInsertedSql;
@@ -1,6 +1,9 @@
1
1
 
2
2
  function formatDateOut(column, alias) {
3
- return `${alias}."${(column._dbName)}"::text`;
3
+ if (alias)
4
+ return `${alias}."${(column._dbName)}"::text`;
5
+ else
6
+ return `"${(column._dbName)}"::text`;
4
7
  }
5
8
 
6
9
  module.exports = formatDateOut;
@@ -0,0 +1,8 @@
1
+ function encodeBoolean(value) {
2
+ return {
3
+ type: 'bigint',
4
+ value
5
+ };
6
+ }
7
+
8
+ module.exports = encodeBoolean;
@@ -0,0 +1,5 @@
1
+ function formatBigintIn(value) {
2
+ return `CONVERT(BIGINT, ${value})`;
3
+ }
4
+
5
+ module.exports = formatBigintIn;
@@ -0,0 +1,11 @@
1
+ const quote = require('./quote');
2
+
3
+ function formatBigintOut(column, alias) {
4
+ const quotedCol = quote(column._dbName);
5
+ if (alias)
6
+ return `CONVERT(VARCHAR(20), ${alias}.${quotedCol})`;
7
+ else
8
+ return `CONVERT(NVARCHAR(20), ${quotedCol})`;
9
+ }
10
+
11
+ module.exports = formatBigintOut;
@@ -1,7 +1,10 @@
1
1
  const quote = require('./quote');
2
2
 
3
3
  function formatDateOut(column, alias) {
4
- return `CONVERT(VARCHAR, ${alias}.${quote(column._dbName)}, 23)`;
4
+ if (alias)
5
+ return `CONVERT(VARCHAR, ${alias}.${quote(column._dbName)}, 23)`;
6
+ else
7
+ return `CONVERT(VARCHAR, ${quote(column._dbName)}, 23)`;
5
8
  }
6
9
 
7
10
  module.exports = formatDateOut;
@@ -4,7 +4,7 @@ const quote = require('./quote');
4
4
  function getSqlTemplate(_context, _table, _row, options) {
5
5
 
6
6
  if (hasConcurrency(_table, options) && hasColumns())
7
- return mergeSql.apply(null, [...arguments].slice(1));
7
+ return mergeSql.apply(null, [...arguments]);
8
8
  else
9
9
  return insertSql.apply(null, [...arguments].slice(1));
10
10
 
@@ -1,6 +1,6 @@
1
1
  const quote = require('./quote');
2
2
 
3
- function insertSql(table, row, options) {
3
+ function insertSql(context, table, row, options) {
4
4
  let columnNames = [];
5
5
  let conflictColumnUpdateSql = '';
6
6
  let values = [];
@@ -1,5 +1,7 @@
1
1
  const wrapQuery = require('../mssql/wrapQuery');
2
2
  const encodeBoolean = require('./encodeBoolean');
3
+ const formatBigintIn = require('./formatBigintIn');
4
+ const formatBigintOut = require('./formatBigintOut');
3
5
  const deleteFromSql = require('./deleteFromSql');
4
6
  const selectForUpdateSql = require('./selectForUpdateSql');
5
7
  const lastInsertedSql = require('./lastInsertedSql');
@@ -17,6 +19,8 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
17
19
  }
18
20
  rdb.engine = 'sap';
19
21
  rdb.encodeBoolean = encodeBoolean;
22
+ rdb.formatBigintIn = formatBigintIn;
23
+ rdb.formatBigintOut = formatBigintOut;
20
24
  rdb.decodeJSON = decodeJSON;
21
25
  rdb.encodeJSON = JSON.stringify;
22
26
  rdb.deleteFromSql = deleteFromSql;
@@ -0,0 +1,11 @@
1
+ const quote = require('./quote');
2
+
3
+ function formatBigintOut(column, alias) {
4
+ const quotedCol = quote(column._dbName);
5
+ if (alias)
6
+ return `CAST(${alias}.${quotedCol} AS TEXT)`;
7
+ else
8
+ return `CAST(${quotedCol} AS TEXT)`;
9
+ }
10
+
11
+ module.exports = formatBigintOut;
@@ -1,7 +1,7 @@
1
1
  function lastInsertedSql(context, table, keyValues) {
2
2
  return keyValues.map((value,i) => {
3
3
  let column = table._primaryColumns[i];
4
- if (value === undefined && column.tsType === 'NumberColumn')
4
+ if (value === undefined && (column.tsType === 'NumberColumn' || column.tsType === 'BigintColumn'))
5
5
  return 'rowid IN (select last_insert_rowid())';
6
6
  else
7
7
  return column.eq(context, value);
@@ -4,6 +4,7 @@ const deleteFromSql = require('../sqlite/deleteFromSql');
4
4
  const selectForUpdateSql = require('../sqlite/selectForUpdateSql');
5
5
  const lastInsertedSql = require('../sqlite/lastInsertedSql');
6
6
  const limitAndOffset = require('../sqlite/limitAndOffset');
7
+ const formatBigintOut = require('../sqlite/formatBigintOut');
7
8
  const insertSql = require('../sqlite/insertSql');
8
9
  const insert = require('../sqlite/insert');
9
10
  const quote = require('../sqlite/quote');
@@ -21,6 +22,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
21
22
  rdb.deleteFromSql = deleteFromSql;
22
23
  rdb.selectForUpdateSql = selectForUpdateSql;
23
24
  rdb.lastInsertedSql = lastInsertedSql;
25
+ rdb.formatBigintOut = formatBigintOut;
24
26
  rdb.insertSql = insertSql;
25
27
  rdb.insert = insert;
26
28
  rdb.lastInsertedIsSeparate = true;
@@ -0,0 +1,18 @@
1
+ var newDecodeCore = require('../newDecodeCore');
2
+
3
+ function _new(column) {
4
+ var decodeCore = newDecodeCore(column);
5
+
6
+ return function(context, value) {
7
+ value = decodeCore(context, value);
8
+ if (value === null)
9
+ return value;
10
+ if (typeof(value) === 'string')
11
+ return value;
12
+ if (value.toString)
13
+ return value.toString();
14
+ return value;
15
+ };
16
+ }
17
+
18
+ module.exports = _new;
@@ -0,0 +1,44 @@
1
+ var newPara = require('../../query/newParameterized');
2
+ var purify = require('../string/purify');
3
+ var getSessionContext = require('../../getSessionContext');
4
+ var getSessionSingleton = require('../../getSessionSingleton');
5
+
6
+ function _new(column) {
7
+ var encode = function(context, value) {
8
+ value = purify(value);
9
+ if (value == null) {
10
+ if (column.dbNull === null)
11
+ return newPara('null');
12
+ return newPara('\'' + column.dbNull + '\'');
13
+ }
14
+ var ctx = getSessionContext(context);
15
+ var encodeCore = ctx.encodeBigint || encodeBigint;
16
+ var formatIn = ctx.formatBigintIn;
17
+ return newPara(formatIn ? formatIn('?') : '?', [encodeCore(value)]);
18
+ };
19
+
20
+ encode.unsafe = function(context, value) {
21
+ value = purify(value);
22
+ if (value == null) {
23
+ if (column.dbNull === null)
24
+ 'null';
25
+ return '\'' + column.dbNull + '\'';
26
+ }
27
+ var encodeCore = getSessionSingleton(context, 'encodeBigint') || encodeBigint;
28
+ return encodeCore(value);
29
+ };
30
+
31
+ encode.direct = function(context, value) {
32
+ var encodeCore = getSessionSingleton(context, 'encodeBigint') || encodeBigint;
33
+ return encodeCore(value);
34
+ };
35
+
36
+ return encode;
37
+
38
+
39
+ }
40
+ function encodeBigint(value) {
41
+ return value;
42
+ }
43
+
44
+ module.exports = _new;
@@ -0,0 +1,16 @@
1
+ var newEncode = require('./bigint/newEncode');
2
+ var newDecode = require('./bigint/newDecode');
3
+ var formatOut = require('./formatOutGeneric');
4
+ var purify = require('./string/purify');
5
+
6
+ function _new(column) {
7
+ column.tsType = 'BigintColumn';
8
+ column.purify = purify;
9
+ column.lazyDefault = '0';
10
+ column.encode = newEncode(column);
11
+ column.decode = newDecode(column);
12
+ column.formatOut = (context, ...rest) => formatOut.apply(null, [context, column, 'formatBigintOut', ...rest]);
13
+
14
+ }
15
+
16
+ module.exports = _new;
@@ -5,8 +5,10 @@ function formatOut(context, column, alias) {
5
5
  var formatColumn = getSessionSingleton(context, 'formatDateOut');
6
6
  if (formatColumn)
7
7
  return formatColumn(column, alias);
8
- else
8
+ else if (alias)
9
9
  return `${alias}.${quote(context, column._dbName)}`;
10
+ else
11
+ return `${quote(context, column._dbName)}`;
10
12
  }
11
13
 
12
14
  module.exports = formatOut;
@@ -0,0 +1,14 @@
1
+ var getSessionSingleton = require('../getSessionSingleton');
2
+ const quote = require('../quote');
3
+
4
+ function formatOutGeneric(context, column, fnName, alias) {
5
+ var formatColumn = getSessionSingleton(context, fnName);
6
+ if (formatColumn)
7
+ return formatColumn(column, alias);
8
+ else if (alias)
9
+ return `${alias}.${quote(context, column._dbName)}`;
10
+ else
11
+ return `${quote(context, column._dbName)}`;
12
+ }
13
+
14
+ module.exports = formatOutGeneric;
@@ -10,13 +10,15 @@ function _in(context, column,values,alias) {
10
10
  }
11
11
  const firstPart = `${quote(context, alias)}.${quote(context, column._dbName)} in (`;
12
12
 
13
- const encode = column.encode.direct;
14
- const params = new Array(values.length);
13
+ const encode = column.encode;
14
+ const paramsSql = new Array(values.length);
15
+ let paramsValues = [];
15
16
  for (let i = 0; i < values.length; i++) {
16
- params[i] = encode(context, values[i]);
17
+ paramsSql[i] = encode(context, values[i]);
18
+ paramsValues = [...paramsValues, ...paramsSql[i].parameters];
17
19
  }
18
- const sql = `${firstPart + new Array(values.length).fill('?').join(',')})`;
19
- return newBoolean(newParameterized(sql, params));
20
+ const sql = `${firstPart + paramsSql.map(x => x.sql()).join(',')})`;
21
+ return newBoolean(newParameterized(sql, paramsValues));
20
22
  }
21
23
 
22
24
  module.exports = _in;
@@ -1,6 +1,6 @@
1
1
  var newEncode = require('./json/newEncode');
2
2
  var newDecode = require('./json/newDecode');
3
- var formatOut = require('./json/formatOut');
3
+ var formatOut = require('./formatOutGeneric');
4
4
  var purify = require('./json/purify');
5
5
  var onChange = require('@lroal/on-change');
6
6
  let clone = require('rfdc/default');
@@ -10,7 +10,7 @@ function _new(column) {
10
10
  column.purify = purify;
11
11
  column.encode = newEncode(column);
12
12
  column.decode = newDecode(column);
13
- column.formatOut = (context, ...rest) => formatOut.apply(null, [context, column, ...rest]);
13
+ column.formatOut = (context, ...rest) => formatOut.apply(null, [context, column, 'formatJSONOut', ...rest]);
14
14
 
15
15
  column.onChange = onChange;
16
16
  column.toDto = toDto;
@@ -39,6 +39,11 @@ function defineColumn(column, table) {
39
39
  return c;
40
40
  };
41
41
 
42
+ c.bigint = function() {
43
+ require('./column/bigint')(column);
44
+ return c;
45
+ };
46
+
42
47
  c.boolean = function() {
43
48
  require('./column/boolean')(column);
44
49
  return c;