@inflector/optima-pg 1.0.6 → 1.0.8

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,8 @@ 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;
358
+ private serializeDateInWhereNodes;
357
359
  private serializeDates;
358
360
  private getVectorCols;
359
361
  private deserializeRow;
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,36 @@ 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
+ }
441
+ serializeDateInWhereNodes(nodes) {
442
+ return nodes.map((node) => {
443
+ if ("and" in node) {
444
+ return { and: this.serializeDateInWhereNodes(node.and) };
445
+ }
446
+ if ("or" in node) {
447
+ return { or: this.serializeDateInWhereNodes(node.or) };
448
+ }
449
+ if ("val" in node) {
450
+ return { ...node, val: this.serializeDateVal(node.val) };
451
+ }
452
+ if ("low" in node) {
453
+ return {
454
+ ...node,
455
+ low: this.serializeDateVal(node.low),
456
+ high: this.serializeDateVal(node.high)
457
+ };
458
+ }
459
+ return node;
460
+ });
461
+ }
428
462
  serializeDates(row) {
429
463
  return Object.fromEntries(
430
464
  Object.entries(row).map(([k, v]) => {
@@ -481,7 +515,10 @@ var Table = class {
481
515
  query = query.selectAll();
482
516
  }
483
517
  if (data.where) {
484
- query = applyWhere(query, resolveWhere(data.where));
518
+ query = applyWhere(
519
+ query,
520
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
521
+ );
485
522
  }
486
523
  if (data.distinct) {
487
524
  query = query.distinct();
@@ -503,7 +540,10 @@ var Table = class {
503
540
  return createFluentBuilder2(async (data) => {
504
541
  let query = this.db.selectFrom(this.name);
505
542
  if (data.where) {
506
- query = applyWhere(query, resolveWhere(data.where));
543
+ query = applyWhere(
544
+ query,
545
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
546
+ );
507
547
  }
508
548
  query = query.limit(1);
509
549
  const rows = await query.execute();
@@ -537,7 +577,10 @@ var Table = class {
537
577
  return createFluentBuilder2(async (data) => {
538
578
  let query = this.db.deleteFrom(this.name);
539
579
  if (data.where) {
540
- query = applyWhere(query, resolveWhere(data.where));
580
+ query = applyWhere(
581
+ query,
582
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
583
+ );
541
584
  }
542
585
  if (data.returning) {
543
586
  return await query.returningAll().execute();
@@ -550,7 +593,10 @@ var Table = class {
550
593
  return createFluentBuilder2(async (data) => {
551
594
  let query = this.db.updateTable(this.name).set(this.serializeDates(set));
552
595
  if (data.where) {
553
- query = applyWhere(query, resolveWhere(data.where));
596
+ query = applyWhere(
597
+ query,
598
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
599
+ );
554
600
  }
555
601
  if (data.returning) {
556
602
  return await query.returningAll().execute();
@@ -563,7 +609,10 @@ var Table = class {
563
609
  return createFluentBuilder2(async (data) => {
564
610
  let query = this.db.selectFrom(this.name);
565
611
  if (data.where) {
566
- query = applyWhere(query, resolveWhere(data.where));
612
+ query = applyWhere(
613
+ query,
614
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
615
+ );
567
616
  }
568
617
  const result = await query.select(this.db.fn.countAll().as("count")).executeTakeFirstOrThrow();
569
618
  return Number(result.count);
@@ -573,7 +622,10 @@ var Table = class {
573
622
  return createFluentBuilder2(async (data) => {
574
623
  let query = this.db.selectFrom(this.name);
575
624
  if (data.where) {
576
- query = applyWhere(query, resolveWhere(data.where));
625
+ query = applyWhere(
626
+ query,
627
+ this.serializeDateInWhereNodes(resolveWhere(data.where))
628
+ );
577
629
  }
578
630
  const result = await query.selectAll().limit(1).execute();
579
631
  return result.length > 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/optima-pg",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "author": "Inflector",
6
6
  "main": "./dist/index.js",