pqb 0.4.5 → 0.4.7

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 (51) hide show
  1. package/dist/index.d.ts +24 -13
  2. package/dist/index.esm.js +44 -33
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +44 -32
  5. package/dist/index.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/columnSchema/columnTypes.test.ts +55 -53
  8. package/src/columnSchema/timestamps.test.ts +3 -4
  9. package/src/columnSchema/timestamps.ts +1 -1
  10. package/src/columnsOperators.test.ts +18 -19
  11. package/src/columnsOperators.ts +1 -1
  12. package/src/common.ts +17 -30
  13. package/src/db.ts +19 -8
  14. package/src/errors.test.ts +2 -4
  15. package/src/index.ts +1 -1
  16. package/src/query.ts +7 -1
  17. package/src/queryMethods/aggregate.test.ts +9 -7
  18. package/src/queryMethods/create.test.ts +5 -5
  19. package/src/queryMethods/create.ts +1 -1
  20. package/src/queryMethods/delete.ts +2 -0
  21. package/src/queryMethods/for.test.ts +1 -2
  22. package/src/queryMethods/for.ts +1 -1
  23. package/src/queryMethods/from.test.ts +2 -3
  24. package/src/queryMethods/get.test.ts +5 -5
  25. package/src/queryMethods/having.test.ts +6 -5
  26. package/src/queryMethods/index.ts +1 -0
  27. package/src/queryMethods/json.ts +2 -2
  28. package/src/queryMethods/merge.test.ts +10 -4
  29. package/src/queryMethods/queryMethods.test.ts +10 -12
  30. package/src/queryMethods/queryMethods.ts +7 -4
  31. package/src/queryMethods/raw.test.ts +19 -0
  32. package/src/queryMethods/raw.ts +27 -0
  33. package/src/queryMethods/select.test.ts +5 -209
  34. package/src/queryMethods/then.test.ts +2 -4
  35. package/src/queryMethods/union.test.ts +11 -6
  36. package/src/queryMethods/update.test.ts +3 -3
  37. package/src/queryMethods/where.test.ts +65 -56
  38. package/src/queryMethods/where.ts +1 -1
  39. package/src/queryMethods/with.test.ts +5 -6
  40. package/src/relations.ts +15 -4
  41. package/src/sql/common.ts +0 -1
  42. package/src/sql/fromAndAs.ts +1 -1
  43. package/src/sql/insert.ts +1 -1
  44. package/src/sql/join.ts +1 -1
  45. package/src/sql/orderBy.ts +1 -1
  46. package/src/sql/select.ts +1 -2
  47. package/src/sql/toSql.ts +1 -1
  48. package/src/sql/update.ts +1 -1
  49. package/src/sql/where.ts +1 -1
  50. package/src/sql/window.ts +3 -4
  51. package/src/sql/with.ts +1 -1
package/dist/index.js CHANGED
@@ -119,33 +119,6 @@ class ColumnType {
119
119
  }
120
120
  }
121
121
 
122
- const raw = (...args) => {
123
- if (typeof args[0] === "string") {
124
- return {
125
- __raw: args[0],
126
- __values: args.slice(1)
127
- };
128
- } else {
129
- return {
130
- __column: args[0],
131
- __raw: args[1],
132
- __values: args.slice(2)
133
- };
134
- }
135
- };
136
- const isRaw = (obj) => "__raw" in obj;
137
- const getRaw = (raw2, values) => {
138
- values.push(...raw2.__values);
139
- return raw2.__raw;
140
- };
141
- const getRawSql = (raw2) => {
142
- return raw2.__raw;
143
- };
144
- const EMPTY_OBJECT = {};
145
- const getQueryParsers = (q) => {
146
- return q.query.parsers || q.columnsParsers;
147
- };
148
-
149
122
  const singleQuoteRegex = /'/g;
150
123
  const doubleQuoteRegex = /"/g;
151
124
  const quoteValue$1 = (value) => {
@@ -184,6 +157,23 @@ const quote = (value) => {
184
157
  return `'${JSON.stringify(value).replace(singleQuoteRegex, "''")}'`;
185
158
  };
186
159
 
160
+ const raw = (sql, ...values) => ({
161
+ __raw: sql,
162
+ __values: values
163
+ });
164
+ const isRaw = (obj) => "__raw" in obj;
165
+ const getRaw = (raw2, values) => {
166
+ values.push(...raw2.__values);
167
+ return raw2.__raw;
168
+ };
169
+ const getRawSql = (raw2) => {
170
+ return raw2.__raw;
171
+ };
172
+ const EMPTY_OBJECT = {};
173
+ const getQueryParsers = (q) => {
174
+ return q.query.parsers || q.columnsParsers;
175
+ };
176
+
187
177
  const q = (sql) => `"${sql}"`;
188
178
  const qc = (column, quotedAs) => quotedAs ? `${quotedAs}.${q(column)}` : column;
189
179
  const quoteFullColumn = (fullColumn, quotedAs) => {
@@ -4766,7 +4756,7 @@ class Json {
4766
4756
  _json() {
4767
4757
  const q = this._wrap(this.__model.clone());
4768
4758
  q._getOptional(
4769
- raw(
4759
+ this.raw(
4770
4760
  queryTypeWithLimitOne[this.query.returnType] ? `row_to_json("t".*)` : `COALESCE(json_agg(row_to_json("t".*)), '[]')`
4771
4761
  )
4772
4762
  );
@@ -5381,6 +5371,23 @@ class QueryUpsert {
5381
5371
  }
5382
5372
  }
5383
5373
 
5374
+ class RawMethods {
5375
+ raw(...args) {
5376
+ if (typeof args[0] === "string") {
5377
+ return {
5378
+ __raw: args[0],
5379
+ __values: args.slice(1)
5380
+ };
5381
+ } else {
5382
+ return {
5383
+ __column: args[0](this.columnTypes),
5384
+ __raw: args[1],
5385
+ __values: args.slice(2)
5386
+ };
5387
+ }
5388
+ }
5389
+ }
5390
+
5384
5391
  class QueryMethods {
5385
5392
  all() {
5386
5393
  return this.clone()._all();
@@ -5500,7 +5507,7 @@ class QueryMethods {
5500
5507
  _wrap(query, as) {
5501
5508
  const sql = this.toSql();
5502
5509
  return query.as(as != null ? as : "t")._from(
5503
- raw(`(${sql.text})`, ...sql.values)
5510
+ this.raw(`(${sql.text})`, ...sql.values)
5504
5511
  );
5505
5512
  }
5506
5513
  order(...args) {
@@ -5527,7 +5534,7 @@ class QueryMethods {
5527
5534
  return this.clone()._exists();
5528
5535
  }
5529
5536
  _exists() {
5530
- const q = this._getOptional(raw("true"));
5537
+ const q = this._getOptional(this.raw("true"));
5531
5538
  q.query.notFoundDefault = false;
5532
5539
  q.query.coalesceValue = false;
5533
5540
  return q;
@@ -5570,7 +5577,8 @@ applyMixins(QueryMethods, [
5570
5577
  QueryCallbacks,
5571
5578
  QueryUpsert,
5572
5579
  QueryGet,
5573
- MergeQueryMethods
5580
+ MergeQueryMethods,
5581
+ RawMethods
5574
5582
  ]);
5575
5583
 
5576
5584
  var __defProp = Object.defineProperty;
@@ -5602,11 +5610,12 @@ var __objRest = (source, exclude) => {
5602
5610
  return target;
5603
5611
  };
5604
5612
  class Db {
5605
- constructor(adapter, queryBuilder, table = void 0, shape = {}, options) {
5613
+ constructor(adapter, queryBuilder, table = void 0, shape = {}, columnTypes, options) {
5606
5614
  this.adapter = adapter;
5607
5615
  this.queryBuilder = queryBuilder;
5608
5616
  this.table = table;
5609
5617
  this.shape = shape;
5618
+ this.columnTypes = columnTypes;
5610
5619
  this.whereQueryBuilder = WhereQueryBuilder;
5611
5620
  this.onQueryBuilder = OnQueryBuilder;
5612
5621
  this.__model = this;
@@ -5681,6 +5690,7 @@ const createDb = (_a) => {
5681
5690
  void 0,
5682
5691
  void 0,
5683
5692
  {},
5693
+ ct,
5684
5694
  commonOptions
5685
5695
  );
5686
5696
  qb.queryBuilder = qb;
@@ -5691,6 +5701,7 @@ const createDb = (_a) => {
5691
5701
  qb,
5692
5702
  table,
5693
5703
  typeof shape === "function" ? getColumnTypes(ct, shape) : shape,
5704
+ ct,
5694
5705
  __spreadValues(__spreadValues({}, commonOptions), options2)
5695
5706
  );
5696
5707
  },
@@ -5770,6 +5781,7 @@ exports.QueryGet = QueryGet;
5770
5781
  exports.QueryLog = QueryLog;
5771
5782
  exports.QueryMethods = QueryMethods;
5772
5783
  exports.QueryUpsert = QueryUpsert;
5784
+ exports.RawMethods = RawMethods;
5773
5785
  exports.RealColumn = RealColumn;
5774
5786
  exports.Select = Select;
5775
5787
  exports.SerialColumn = SerialColumn;