@inflector/optima-pg 1.0.7 → 1.0.9

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.d.ts CHANGED
@@ -292,7 +292,7 @@ declare const time: (withTimezone?: boolean) => FluentStep<{
292
292
  unique: boolean;
293
293
  defaultNow: boolean;
294
294
  }>;
295
- declare const timestamp: (withTimezone?: boolean) => FluentStep<{
295
+ declare const timestamp: (withTimezone?: boolean, noms?: boolean) => FluentStep<{
296
296
  default: Date;
297
297
  SQlType: string;
298
298
  notnull: boolean;
@@ -354,6 +354,7 @@ declare class Table<T extends Record<string, AnyColumn>> {
354
354
  private db;
355
355
  private listenFn;
356
356
  constructor(name: string, schema: T, db: Kysely<any>, listenFn: ListenFn);
357
+ private serializeDateVal;
357
358
  private serializeDateInWhereNodes;
358
359
  private serializeDates;
359
360
  private getVectorCols;
package/dist/index.js CHANGED
@@ -270,11 +270,15 @@ var bool = () => {
270
270
  };
271
271
  var time = (withTimezone = false) => {
272
272
  const type = withTimezone ? "time with time zone" : "time";
273
- return Column().SQlType(type);
273
+ return Column().SQlType(
274
+ type
275
+ );
274
276
  };
275
- var timestamp = (withTimezone = true) => {
276
- const type = withTimezone ? "timestamp with time zone" : "timestamp";
277
- return Column().SQlType(type);
277
+ var timestamp = (withTimezone = true, noms = true) => {
278
+ const type = withTimezone ? "timestamp(0) with time zone" : "timestamp(0)";
279
+ return Column().SQlType(
280
+ type
281
+ );
278
282
  };
279
283
  var bytea = () => {
280
284
  return Column().SQlType("bytea");
@@ -425,6 +429,15 @@ var Table = class {
425
429
  this.schema = schema;
426
430
  this.listenFn = listenFn;
427
431
  }
432
+ serializeDateVal(v) {
433
+ if (v instanceof Date) {
434
+ return v.toISOString().replace("T", " ").replace("Z", "+00");
435
+ }
436
+ if (typeof v === "string" && this.isISOTimestamp(v)) {
437
+ return v.replace("T", " ").replace("Z", "+00");
438
+ }
439
+ return v;
440
+ }
428
441
  serializeDateInWhereNodes(nodes) {
429
442
  return nodes.map((node) => {
430
443
  if ("and" in node) {
@@ -433,17 +446,14 @@ var Table = class {
433
446
  if ("or" in node) {
434
447
  return { or: this.serializeDateInWhereNodes(node.or) };
435
448
  }
436
- if ("val" in node && node.val instanceof Date) {
437
- return {
438
- ...node,
439
- val: node.val.toISOString().replace("T", " ").replace("Z", "+00")
440
- };
449
+ if ("val" in node) {
450
+ return { ...node, val: this.serializeDateVal(node.val) };
441
451
  }
442
452
  if ("low" in node) {
443
453
  return {
444
454
  ...node,
445
- low: node.low instanceof Date ? node.low.toISOString().replace("T", " ").replace("Z", "+00") : node.low,
446
- high: node.high instanceof Date ? node.high.toISOString().replace("T", " ").replace("Z", "+00") : node.high
455
+ low: this.serializeDateVal(node.low),
456
+ high: this.serializeDateVal(node.high)
447
457
  };
448
458
  }
449
459
  return node;
@@ -483,6 +493,9 @@ var Table = class {
483
493
  if (vectorCols.has(k) && typeof v === "string") {
484
494
  return [k, JSON.parse(v)];
485
495
  }
496
+ if (typeof v === "string" && this.isPostgresTimestamp(v)) {
497
+ return [k, v.replace(" ", "T").replace(/\+\d+(:\d+)?$/, "Z")];
498
+ }
486
499
  return [k, v];
487
500
  })
488
501
  );
@@ -505,7 +518,10 @@ var Table = class {
505
518
  query = query.selectAll();
506
519
  }
507
520
  if (data.where) {
508
- query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
521
+ query = applyWhere(
522
+ query,
523
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
524
+ );
509
525
  }
510
526
  if (data.distinct) {
511
527
  query = query.distinct();
@@ -527,7 +543,10 @@ var Table = class {
527
543
  return createFluentBuilder2(async (data) => {
528
544
  let query = this.db.selectFrom(this.name);
529
545
  if (data.where) {
530
- query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
546
+ query = applyWhere(
547
+ query,
548
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
549
+ );
531
550
  }
532
551
  query = query.limit(1);
533
552
  const rows = await query.execute();
@@ -561,7 +580,10 @@ var Table = class {
561
580
  return createFluentBuilder2(async (data) => {
562
581
  let query = this.db.deleteFrom(this.name);
563
582
  if (data.where) {
564
- query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
583
+ query = applyWhere(
584
+ query,
585
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
586
+ );
565
587
  }
566
588
  if (data.returning) {
567
589
  return await query.returningAll().execute();
@@ -574,7 +596,10 @@ var Table = class {
574
596
  return createFluentBuilder2(async (data) => {
575
597
  let query = this.db.updateTable(this.name).set(this.serializeDates(set));
576
598
  if (data.where) {
577
- query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
599
+ query = applyWhere(
600
+ query,
601
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
602
+ );
578
603
  }
579
604
  if (data.returning) {
580
605
  return await query.returningAll().execute();
@@ -587,7 +612,10 @@ var Table = class {
587
612
  return createFluentBuilder2(async (data) => {
588
613
  let query = this.db.selectFrom(this.name);
589
614
  if (data.where) {
590
- query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
615
+ query = applyWhere(
616
+ query,
617
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
618
+ );
591
619
  }
592
620
  const result = await query.select(this.db.fn.countAll().as("count")).executeTakeFirstOrThrow();
593
621
  return Number(result.count);
@@ -597,7 +625,10 @@ var Table = class {
597
625
  return createFluentBuilder2(async (data) => {
598
626
  let query = this.db.selectFrom(this.name);
599
627
  if (data.where) {
600
- query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
628
+ query = applyWhere(
629
+ query,
630
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
631
+ );
601
632
  }
602
633
  const result = await query.selectAll().limit(1).execute();
603
634
  return result.length > 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/optima-pg",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "author": "Inflector",
6
6
  "main": "./dist/index.js",