pqb 0.61.0 → 0.61.2

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.js CHANGED
@@ -401,7 +401,7 @@ RawSql.prototype.type = ExpressionTypeMethod.prototype.type;
401
401
  const rawSqlToCode = (rawSql, t) => {
402
402
  const { _sql: sql, _values: values } = rawSql;
403
403
  let code = `${t}.sql`;
404
- code += typeof sql === "string" ? `({ raw: '${sql.replace(/'/g, "\\'")}' })` : templateLiteralSQLToCode(sql);
404
+ code += typeof sql === "string" ? values ? `({ raw: '${sql.replace(/'/g, "\\'")}' })` : `\`${sql.replace(/`/g, "\\`")}\`` : templateLiteralSQLToCode(sql);
405
405
  if (values) {
406
406
  code += `.values(${JSON.stringify(values)})`;
407
407
  }
@@ -501,7 +501,7 @@ const consumeColumnName = () => {
501
501
  const defaultNowFn = "now()";
502
502
  let currentNowFn = defaultNowFn;
503
503
  const setDefaultNowFn = (sql) => {
504
- currentNowFn = `(${sql})`;
504
+ currentNowFn = sql;
505
505
  };
506
506
  const getDefaultNowFn = () => currentNowFn;
507
507
  const resetDefaultNowFn = () => {
@@ -1261,10 +1261,13 @@ const combineCodeElements = (input) => {
1261
1261
  return output;
1262
1262
  };
1263
1263
  const columnsShapeToCode = (ctx, shape) => {
1264
- const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(
1265
- shape.createdAt
1266
- ) && "updatedAt" in shape && isDefaultTimeStamp(
1267
- shape.updatedAt
1264
+ const hasTimestamps = (
1265
+ // migration should capture the current `nowSQL`, it can be changed later by user
1266
+ !ctx.migration && "createdAt" in shape && isDefaultTimeStamp(
1267
+ shape.createdAt
1268
+ ) && "updatedAt" in shape && isDefaultTimeStamp(
1269
+ shape.updatedAt
1270
+ )
1268
1271
  );
1269
1272
  const code = [];
1270
1273
  for (const key in shape) {
@@ -1688,7 +1691,7 @@ const columnCode = (type, ctx, key, code) => {
1688
1691
  if (data.compression)
1689
1692
  addCode(code, `.compression(${singleQuote(data.compression)})`);
1690
1693
  if (data.collate) addCode(code, `.collate(${singleQuote(data.collate)})`);
1691
- if (data.modifyQuery)
1694
+ if (data.modifyQuery && !ctx.migration)
1692
1695
  addCode(code, `.modifyQuery(${data.modifyQuery.toString()})`);
1693
1696
  return code.length === 1 && typeof code[0] === "string" ? code[0] : code;
1694
1697
  };
@@ -2151,7 +2154,7 @@ class DateTimeTzBaseClass extends DateTimeBaseClass {
2151
2154
  const timestampToCode = (self, ctx, key) => {
2152
2155
  const { dateTimePrecision: p } = self.data;
2153
2156
  const { defaultTimestamp } = self.data;
2154
- if (defaultTimestamp) {
2157
+ if (!ctx.migration && defaultTimestamp) {
2155
2158
  const noTz = self instanceof TimestampColumn ? "NoTZ" : "";
2156
2159
  const def = self.data.default;
2157
2160
  const modifyQuery = self.data.modifyQuery;