@inflector/optima-pg 1.0.5 → 1.0.7
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 +3 -0
- package/dist/index.js +47 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -354,9 +354,12 @@ 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 serializeDateInWhereNodes;
|
|
357
358
|
private serializeDates;
|
|
358
359
|
private getVectorCols;
|
|
359
360
|
private deserializeRow;
|
|
361
|
+
private isPostgresTimestamp;
|
|
362
|
+
private isISOTimestamp;
|
|
360
363
|
Get<TCols extends keyof InferSchema<T> = keyof InferSchema<T>>(cols?: TCols[]): {
|
|
361
364
|
limit: (arg: number) => {
|
|
362
365
|
offset: (arg: number) => {
|
package/dist/index.js
CHANGED
|
@@ -425,10 +425,42 @@ var Table = class {
|
|
|
425
425
|
this.schema = schema;
|
|
426
426
|
this.listenFn = listenFn;
|
|
427
427
|
}
|
|
428
|
+
serializeDateInWhereNodes(nodes) {
|
|
429
|
+
return nodes.map((node) => {
|
|
430
|
+
if ("and" in node) {
|
|
431
|
+
return { and: this.serializeDateInWhereNodes(node.and) };
|
|
432
|
+
}
|
|
433
|
+
if ("or" in node) {
|
|
434
|
+
return { or: this.serializeDateInWhereNodes(node.or) };
|
|
435
|
+
}
|
|
436
|
+
if ("val" in node && node.val instanceof Date) {
|
|
437
|
+
return {
|
|
438
|
+
...node,
|
|
439
|
+
val: node.val.toISOString().replace("T", " ").replace("Z", "+00")
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if ("low" in node) {
|
|
443
|
+
return {
|
|
444
|
+
...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
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
return node;
|
|
450
|
+
});
|
|
451
|
+
}
|
|
428
452
|
serializeDates(row) {
|
|
429
453
|
return Object.fromEntries(
|
|
430
454
|
Object.entries(row).map(([k, v]) => {
|
|
431
|
-
if (v instanceof Date)
|
|
455
|
+
if (v instanceof Date) {
|
|
456
|
+
return [k, v.toISOString().replace("T", " ").replace("Z", "+00")];
|
|
457
|
+
}
|
|
458
|
+
if (typeof v === "string" && this.isPostgresTimestamp(v)) {
|
|
459
|
+
return [k, v];
|
|
460
|
+
}
|
|
461
|
+
if (typeof v === "string" && this.isISOTimestamp(v)) {
|
|
462
|
+
return [k, v.replace("T", " ").replace("Z", "+00")];
|
|
463
|
+
}
|
|
432
464
|
if (Array.isArray(v) && v.every((i) => typeof i === "number")) {
|
|
433
465
|
return [k, `[${v.join(",")}]`];
|
|
434
466
|
}
|
|
@@ -455,6 +487,14 @@ var Table = class {
|
|
|
455
487
|
})
|
|
456
488
|
);
|
|
457
489
|
}
|
|
490
|
+
// 2026-02-18 23:09:43.766654+00
|
|
491
|
+
isPostgresTimestamp(v) {
|
|
492
|
+
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(v);
|
|
493
|
+
}
|
|
494
|
+
// 2026-02-18T23:09:43.766Z
|
|
495
|
+
isISOTimestamp(v) {
|
|
496
|
+
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(v);
|
|
497
|
+
}
|
|
458
498
|
// ── CRUD ────────────────────────────────────────────────────────────────────
|
|
459
499
|
Get(cols) {
|
|
460
500
|
return createFluentBuilder2(async (data) => {
|
|
@@ -465,7 +505,7 @@ var Table = class {
|
|
|
465
505
|
query = query.selectAll();
|
|
466
506
|
}
|
|
467
507
|
if (data.where) {
|
|
468
|
-
query = applyWhere(query, resolveWhere(data.where));
|
|
508
|
+
query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
|
|
469
509
|
}
|
|
470
510
|
if (data.distinct) {
|
|
471
511
|
query = query.distinct();
|
|
@@ -487,7 +527,7 @@ var Table = class {
|
|
|
487
527
|
return createFluentBuilder2(async (data) => {
|
|
488
528
|
let query = this.db.selectFrom(this.name);
|
|
489
529
|
if (data.where) {
|
|
490
|
-
query = applyWhere(query, resolveWhere(data.where));
|
|
530
|
+
query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
|
|
491
531
|
}
|
|
492
532
|
query = query.limit(1);
|
|
493
533
|
const rows = await query.execute();
|
|
@@ -521,7 +561,7 @@ var Table = class {
|
|
|
521
561
|
return createFluentBuilder2(async (data) => {
|
|
522
562
|
let query = this.db.deleteFrom(this.name);
|
|
523
563
|
if (data.where) {
|
|
524
|
-
query = applyWhere(query, resolveWhere(data.where));
|
|
564
|
+
query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
|
|
525
565
|
}
|
|
526
566
|
if (data.returning) {
|
|
527
567
|
return await query.returningAll().execute();
|
|
@@ -534,7 +574,7 @@ var Table = class {
|
|
|
534
574
|
return createFluentBuilder2(async (data) => {
|
|
535
575
|
let query = this.db.updateTable(this.name).set(this.serializeDates(set));
|
|
536
576
|
if (data.where) {
|
|
537
|
-
query = applyWhere(query, resolveWhere(data.where));
|
|
577
|
+
query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
|
|
538
578
|
}
|
|
539
579
|
if (data.returning) {
|
|
540
580
|
return await query.returningAll().execute();
|
|
@@ -547,7 +587,7 @@ var Table = class {
|
|
|
547
587
|
return createFluentBuilder2(async (data) => {
|
|
548
588
|
let query = this.db.selectFrom(this.name);
|
|
549
589
|
if (data.where) {
|
|
550
|
-
query = applyWhere(query, resolveWhere(data.where));
|
|
590
|
+
query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
|
|
551
591
|
}
|
|
552
592
|
const result = await query.select(this.db.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
553
593
|
return Number(result.count);
|
|
@@ -557,7 +597,7 @@ var Table = class {
|
|
|
557
597
|
return createFluentBuilder2(async (data) => {
|
|
558
598
|
let query = this.db.selectFrom(this.name);
|
|
559
599
|
if (data.where) {
|
|
560
|
-
query = applyWhere(query, resolveWhere(data.where));
|
|
600
|
+
query = applyWhere(query, this.serializeDateInWhereNodes(resolveWhere(data.where)));
|
|
561
601
|
}
|
|
562
602
|
const result = await query.selectAll().limit(1).execute();
|
|
563
603
|
return result.length > 0;
|