@inflector/optima-pg 1.0.7 → 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 +2 -1
- package/dist/index.js +45 -17
- package/package.json +1 -1
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(
|
|
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(
|
|
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
|
|
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:
|
|
446
|
-
high:
|
|
455
|
+
low: this.serializeDateVal(node.low),
|
|
456
|
+
high: this.serializeDateVal(node.high)
|
|
447
457
|
};
|
|
448
458
|
}
|
|
449
459
|
return node;
|
|
@@ -505,7 +515,10 @@ var Table = class {
|
|
|
505
515
|
query = query.selectAll();
|
|
506
516
|
}
|
|
507
517
|
if (data.where) {
|
|
508
|
-
query = applyWhere(
|
|
518
|
+
query = applyWhere(
|
|
519
|
+
query,
|
|
520
|
+
this.serializeDateInWhereNodes(resolveWhere(data.where))
|
|
521
|
+
);
|
|
509
522
|
}
|
|
510
523
|
if (data.distinct) {
|
|
511
524
|
query = query.distinct();
|
|
@@ -527,7 +540,10 @@ var Table = class {
|
|
|
527
540
|
return createFluentBuilder2(async (data) => {
|
|
528
541
|
let query = this.db.selectFrom(this.name);
|
|
529
542
|
if (data.where) {
|
|
530
|
-
query = applyWhere(
|
|
543
|
+
query = applyWhere(
|
|
544
|
+
query,
|
|
545
|
+
this.serializeDateInWhereNodes(resolveWhere(data.where))
|
|
546
|
+
);
|
|
531
547
|
}
|
|
532
548
|
query = query.limit(1);
|
|
533
549
|
const rows = await query.execute();
|
|
@@ -561,7 +577,10 @@ var Table = class {
|
|
|
561
577
|
return createFluentBuilder2(async (data) => {
|
|
562
578
|
let query = this.db.deleteFrom(this.name);
|
|
563
579
|
if (data.where) {
|
|
564
|
-
query = applyWhere(
|
|
580
|
+
query = applyWhere(
|
|
581
|
+
query,
|
|
582
|
+
this.serializeDateInWhereNodes(resolveWhere(data.where))
|
|
583
|
+
);
|
|
565
584
|
}
|
|
566
585
|
if (data.returning) {
|
|
567
586
|
return await query.returningAll().execute();
|
|
@@ -574,7 +593,10 @@ var Table = class {
|
|
|
574
593
|
return createFluentBuilder2(async (data) => {
|
|
575
594
|
let query = this.db.updateTable(this.name).set(this.serializeDates(set));
|
|
576
595
|
if (data.where) {
|
|
577
|
-
query = applyWhere(
|
|
596
|
+
query = applyWhere(
|
|
597
|
+
query,
|
|
598
|
+
this.serializeDateInWhereNodes(resolveWhere(data.where))
|
|
599
|
+
);
|
|
578
600
|
}
|
|
579
601
|
if (data.returning) {
|
|
580
602
|
return await query.returningAll().execute();
|
|
@@ -587,7 +609,10 @@ var Table = class {
|
|
|
587
609
|
return createFluentBuilder2(async (data) => {
|
|
588
610
|
let query = this.db.selectFrom(this.name);
|
|
589
611
|
if (data.where) {
|
|
590
|
-
query = applyWhere(
|
|
612
|
+
query = applyWhere(
|
|
613
|
+
query,
|
|
614
|
+
this.serializeDateInWhereNodes(resolveWhere(data.where))
|
|
615
|
+
);
|
|
591
616
|
}
|
|
592
617
|
const result = await query.select(this.db.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
593
618
|
return Number(result.count);
|
|
@@ -597,7 +622,10 @@ var Table = class {
|
|
|
597
622
|
return createFluentBuilder2(async (data) => {
|
|
598
623
|
let query = this.db.selectFrom(this.name);
|
|
599
624
|
if (data.where) {
|
|
600
|
-
query = applyWhere(
|
|
625
|
+
query = applyWhere(
|
|
626
|
+
query,
|
|
627
|
+
this.serializeDateInWhereNodes(resolveWhere(data.where))
|
|
628
|
+
);
|
|
601
629
|
}
|
|
602
630
|
const result = await query.selectAll().limit(1).execute();
|
|
603
631
|
return result.length > 0;
|