pqb 0.40.0 → 0.40.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
@@ -1,4 +1,4 @@
1
- import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy, numberDataToCode, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, logColors, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, snakeCaseKey } from 'orchid-core';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, numberDataToCode, logColors, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, snakeCaseKey } from 'orchid-core';
2
2
  import pg from 'pg';
3
3
  import { inspect } from 'node:util';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -1077,193 +1077,6 @@ const Operators = {
1077
1077
  array: base
1078
1078
  };
1079
1079
 
1080
- class NumberBaseColumn extends ColumnType {
1081
- constructor() {
1082
- super(...arguments);
1083
- this.operators = Operators.number;
1084
- }
1085
- }
1086
- class IntegerBaseColumn extends NumberBaseColumn {
1087
- constructor(schema) {
1088
- super(schema, schema.int());
1089
- this.data.int = true;
1090
- }
1091
- }
1092
- class NumberAsStringBaseColumn extends ColumnType {
1093
- constructor(schema) {
1094
- super(schema, schema.stringSchema());
1095
- this.operators = Operators.number;
1096
- }
1097
- }
1098
- class DecimalColumn extends NumberAsStringBaseColumn {
1099
- constructor(schema, numericPrecision, numericScale) {
1100
- super(schema);
1101
- this.operators = Operators.number;
1102
- this.dataType = "numeric";
1103
- this.data.numericPrecision = numericPrecision;
1104
- this.data.numericScale = numericScale;
1105
- this.data.alias = "decimal";
1106
- }
1107
- toCode(ctx, key) {
1108
- const { numericPrecision, numericScale } = this.data;
1109
- return columnCode(
1110
- this,
1111
- ctx,
1112
- key,
1113
- `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
1114
- );
1115
- }
1116
- toSQL() {
1117
- const { numericPrecision, numericScale } = this.data;
1118
- return joinTruthy(
1119
- this.dataType,
1120
- numericPrecision ? numericScale ? `(${numericPrecision}, ${numericScale})` : `(${numericPrecision})` : void 0
1121
- );
1122
- }
1123
- }
1124
- const skipNumberMethods = { int: true };
1125
- const intToCode = (column, ctx, key, alias) => {
1126
- let code;
1127
- if (column.data.identity) {
1128
- code = identityToCode(column.data.identity, alias);
1129
- } else {
1130
- code = [`${alias}()`];
1131
- }
1132
- addCode(
1133
- code,
1134
- numberDataToCode(column.data, ctx.migration, skipNumberMethods)
1135
- );
1136
- return columnCode(column, ctx, key, code);
1137
- };
1138
- class SmallIntColumn extends IntegerBaseColumn {
1139
- constructor(schema) {
1140
- super(schema);
1141
- this.dataType = "int2";
1142
- this.parseItem = parseInt;
1143
- this.data.alias = "smallint";
1144
- }
1145
- toCode(ctx, key) {
1146
- return intToCode(this, ctx, key, "smallint");
1147
- }
1148
- identity(options = {}) {
1149
- return setColumnData(this, "identity", options);
1150
- }
1151
- }
1152
- class IntegerColumn extends IntegerBaseColumn {
1153
- constructor(schema) {
1154
- super(schema);
1155
- this.dataType = "int4";
1156
- this.parseItem = parseInt;
1157
- this.data.alias = "integer";
1158
- }
1159
- toCode(ctx, key) {
1160
- return intToCode(this, ctx, key, "integer");
1161
- }
1162
- identity(options = {}) {
1163
- return setColumnData(this, "identity", options);
1164
- }
1165
- }
1166
- class BigIntColumn extends NumberAsStringBaseColumn {
1167
- constructor(schema) {
1168
- super(schema);
1169
- this.dataType = "int8";
1170
- this.data.alias = "bigint";
1171
- }
1172
- toCode(ctx, key) {
1173
- return intToCode(this, ctx, key, "bigint");
1174
- }
1175
- identity(options = {}) {
1176
- return setColumnData(this, "identity", options);
1177
- }
1178
- }
1179
- class RealColumn extends NumberBaseColumn {
1180
- constructor(schema) {
1181
- super(schema, schema.number());
1182
- this.dataType = "float4";
1183
- this.parseItem = parseFloat;
1184
- this.data.alias = "real";
1185
- }
1186
- toCode(ctx, key) {
1187
- return columnCode(
1188
- this,
1189
- ctx,
1190
- key,
1191
- `real()${numberDataToCode(this.data, ctx.migration)}`
1192
- );
1193
- }
1194
- }
1195
- class DoublePrecisionColumn extends NumberAsStringBaseColumn {
1196
- constructor(schema) {
1197
- super(schema);
1198
- this.dataType = "float8";
1199
- this.data.alias = "doublePrecision";
1200
- }
1201
- toCode(ctx, key) {
1202
- return columnCode(this, ctx, key, `doublePrecision()`);
1203
- }
1204
- }
1205
- class SmallSerialColumn extends IntegerBaseColumn {
1206
- constructor(schema) {
1207
- super(schema);
1208
- this.dataType = "int2";
1209
- this.parseItem = parseInt;
1210
- this.data.int = true;
1211
- this.data.alias = "smallSerial";
1212
- }
1213
- toSQL() {
1214
- return "smallserial";
1215
- }
1216
- toCode(ctx, key) {
1217
- return columnCode(
1218
- this,
1219
- ctx,
1220
- key,
1221
- `smallSerial()${numberDataToCode(
1222
- this.data,
1223
- ctx.migration,
1224
- skipNumberMethods
1225
- )}`
1226
- );
1227
- }
1228
- }
1229
- class SerialColumn extends IntegerBaseColumn {
1230
- constructor(schema) {
1231
- super(schema);
1232
- this.dataType = "int4";
1233
- this.parseItem = parseInt;
1234
- this.data.int = true;
1235
- this.data.alias = "serial";
1236
- }
1237
- toSQL() {
1238
- return "serial";
1239
- }
1240
- toCode(ctx, key) {
1241
- return columnCode(
1242
- this,
1243
- ctx,
1244
- key,
1245
- `serial()${numberDataToCode(
1246
- this.data,
1247
- ctx.migration,
1248
- skipNumberMethods
1249
- )}`
1250
- );
1251
- }
1252
- }
1253
- class BigSerialColumn extends NumberAsStringBaseColumn {
1254
- constructor(schema) {
1255
- super(schema);
1256
- this.dataType = "int8";
1257
- this.data.alias = "bigint";
1258
- }
1259
- toSQL() {
1260
- return "bigserial";
1261
- }
1262
- toCode(ctx, key) {
1263
- return columnCode(this, ctx, key, `bigSerial()`);
1264
- }
1265
- }
1266
-
1267
1080
  var __defProp$j = Object.defineProperty;
1268
1081
  var __defProps$a = Object.defineProperties;
1269
1082
  var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
@@ -1447,13 +1260,14 @@ class CircleColumn extends ColumnType {
1447
1260
  return columnCode(this, ctx, key, `circle()`);
1448
1261
  }
1449
1262
  }
1450
- class MoneyColumn extends NumberBaseColumn {
1263
+ class MoneyColumn extends ColumnType {
1451
1264
  constructor(schema) {
1452
1265
  super(schema, schema.stringSchema());
1453
1266
  this.dataType = "money";
1267
+ this.operators = Operators.number;
1454
1268
  this.parseFn = Object.assign(
1455
1269
  function(input) {
1456
- return parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
1270
+ return input === null ? input : parseFloat(input.replace(/,/g, "").replace(/\$/g, ""));
1457
1271
  },
1458
1272
  {
1459
1273
  hideFromCode: true
@@ -3019,6 +2833,8 @@ class ArrayColumn extends ColumnType {
3019
2833
  this.operators = Operators.array;
3020
2834
  this.parseFn = Object.assign(
3021
2835
  (source) => {
2836
+ if (!source)
2837
+ return source;
3022
2838
  const entries = [];
3023
2839
  parsePostgresArray(source, entries, this.data.item.parseItem);
3024
2840
  return entries;
@@ -3107,6 +2923,193 @@ const parsePostgresArray = (source, entries, transform) => {
3107
2923
  return pos;
3108
2924
  };
3109
2925
 
2926
+ class NumberBaseColumn extends ColumnType {
2927
+ constructor() {
2928
+ super(...arguments);
2929
+ this.operators = Operators.number;
2930
+ }
2931
+ }
2932
+ class IntegerBaseColumn extends NumberBaseColumn {
2933
+ constructor(schema) {
2934
+ super(schema, schema.int());
2935
+ this.data.int = true;
2936
+ }
2937
+ }
2938
+ class NumberAsStringBaseColumn extends ColumnType {
2939
+ constructor(schema) {
2940
+ super(schema, schema.stringSchema());
2941
+ this.operators = Operators.number;
2942
+ }
2943
+ }
2944
+ class DecimalColumn extends NumberAsStringBaseColumn {
2945
+ constructor(schema, numericPrecision, numericScale) {
2946
+ super(schema);
2947
+ this.operators = Operators.number;
2948
+ this.dataType = "numeric";
2949
+ this.data.numericPrecision = numericPrecision;
2950
+ this.data.numericScale = numericScale;
2951
+ this.data.alias = "decimal";
2952
+ }
2953
+ toCode(ctx, key) {
2954
+ const { numericPrecision, numericScale } = this.data;
2955
+ return columnCode(
2956
+ this,
2957
+ ctx,
2958
+ key,
2959
+ `decimal(${numericPrecision || ""}${numericScale ? `, ${numericScale}` : ""})`
2960
+ );
2961
+ }
2962
+ toSQL() {
2963
+ const { numericPrecision, numericScale } = this.data;
2964
+ return joinTruthy(
2965
+ this.dataType,
2966
+ numericPrecision ? numericScale ? `(${numericPrecision}, ${numericScale})` : `(${numericPrecision})` : void 0
2967
+ );
2968
+ }
2969
+ }
2970
+ const skipNumberMethods = { int: true };
2971
+ const intToCode = (column, ctx, key, alias) => {
2972
+ let code;
2973
+ if (column.data.identity) {
2974
+ code = identityToCode(column.data.identity, alias);
2975
+ } else {
2976
+ code = [`${alias}()`];
2977
+ }
2978
+ addCode(
2979
+ code,
2980
+ numberDataToCode(column.data, ctx.migration, skipNumberMethods)
2981
+ );
2982
+ return columnCode(column, ctx, key, code);
2983
+ };
2984
+ class SmallIntColumn extends IntegerBaseColumn {
2985
+ constructor(schema) {
2986
+ super(schema);
2987
+ this.dataType = "int2";
2988
+ this.parseItem = parseInt;
2989
+ this.data.alias = "smallint";
2990
+ }
2991
+ toCode(ctx, key) {
2992
+ return intToCode(this, ctx, key, "smallint");
2993
+ }
2994
+ identity(options = {}) {
2995
+ return setColumnData(this, "identity", options);
2996
+ }
2997
+ }
2998
+ class IntegerColumn extends IntegerBaseColumn {
2999
+ constructor(schema) {
3000
+ super(schema);
3001
+ this.dataType = "int4";
3002
+ this.parseItem = parseInt;
3003
+ this.data.alias = "integer";
3004
+ }
3005
+ toCode(ctx, key) {
3006
+ return intToCode(this, ctx, key, "integer");
3007
+ }
3008
+ identity(options = {}) {
3009
+ return setColumnData(this, "identity", options);
3010
+ }
3011
+ }
3012
+ class BigIntColumn extends NumberAsStringBaseColumn {
3013
+ constructor(schema) {
3014
+ super(schema);
3015
+ this.dataType = "int8";
3016
+ this.data.alias = "bigint";
3017
+ }
3018
+ toCode(ctx, key) {
3019
+ return intToCode(this, ctx, key, "bigint");
3020
+ }
3021
+ identity(options = {}) {
3022
+ return setColumnData(this, "identity", options);
3023
+ }
3024
+ }
3025
+ class RealColumn extends NumberBaseColumn {
3026
+ constructor(schema) {
3027
+ super(schema, schema.number());
3028
+ this.dataType = "float4";
3029
+ this.parseItem = parseFloat;
3030
+ this.data.alias = "real";
3031
+ }
3032
+ toCode(ctx, key) {
3033
+ return columnCode(
3034
+ this,
3035
+ ctx,
3036
+ key,
3037
+ `real()${numberDataToCode(this.data, ctx.migration)}`
3038
+ );
3039
+ }
3040
+ }
3041
+ class DoublePrecisionColumn extends NumberAsStringBaseColumn {
3042
+ constructor(schema) {
3043
+ super(schema);
3044
+ this.dataType = "float8";
3045
+ this.data.alias = "doublePrecision";
3046
+ }
3047
+ toCode(ctx, key) {
3048
+ return columnCode(this, ctx, key, `doublePrecision()`);
3049
+ }
3050
+ }
3051
+ class SmallSerialColumn extends IntegerBaseColumn {
3052
+ constructor(schema) {
3053
+ super(schema);
3054
+ this.dataType = "int2";
3055
+ this.parseItem = parseInt;
3056
+ this.data.int = true;
3057
+ this.data.alias = "smallSerial";
3058
+ }
3059
+ toSQL() {
3060
+ return "smallserial";
3061
+ }
3062
+ toCode(ctx, key) {
3063
+ return columnCode(
3064
+ this,
3065
+ ctx,
3066
+ key,
3067
+ `smallSerial()${numberDataToCode(
3068
+ this.data,
3069
+ ctx.migration,
3070
+ skipNumberMethods
3071
+ )}`
3072
+ );
3073
+ }
3074
+ }
3075
+ class SerialColumn extends IntegerBaseColumn {
3076
+ constructor(schema) {
3077
+ super(schema);
3078
+ this.dataType = "int4";
3079
+ this.parseItem = parseInt;
3080
+ this.data.int = true;
3081
+ this.data.alias = "serial";
3082
+ }
3083
+ toSQL() {
3084
+ return "serial";
3085
+ }
3086
+ toCode(ctx, key) {
3087
+ return columnCode(
3088
+ this,
3089
+ ctx,
3090
+ key,
3091
+ `serial()${numberDataToCode(
3092
+ this.data,
3093
+ ctx.migration,
3094
+ skipNumberMethods
3095
+ )}`
3096
+ );
3097
+ }
3098
+ }
3099
+ class BigSerialColumn extends NumberAsStringBaseColumn {
3100
+ constructor(schema) {
3101
+ super(schema);
3102
+ this.dataType = "int8";
3103
+ this.data.alias = "bigint";
3104
+ }
3105
+ toSQL() {
3106
+ return "bigserial";
3107
+ }
3108
+ toCode(ctx, key) {
3109
+ return columnCode(this, ctx, key, `bigSerial()`);
3110
+ }
3111
+ }
3112
+
3110
3113
  const parseDateToNumber = (value) => value ? Date.parse(value) : value;
3111
3114
  const parseDateToDate = (value) => value ? new Date(value) : value;
3112
3115
  parseDateToNumber.hideFromCode = parseDateToDate.hideFromCode = true;