@fragno-dev/db 0.1.11 → 0.1.13

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.
Files changed (71) hide show
  1. package/.turbo/turbo-build.log +41 -39
  2. package/CHANGELOG.md +19 -0
  3. package/dist/adapters/drizzle/drizzle-adapter.d.ts.map +1 -1
  4. package/dist/adapters/drizzle/drizzle-adapter.js +1 -1
  5. package/dist/adapters/drizzle/drizzle-query.d.ts.map +1 -1
  6. package/dist/adapters/drizzle/drizzle-query.js +42 -34
  7. package/dist/adapters/drizzle/drizzle-query.js.map +1 -1
  8. package/dist/adapters/drizzle/drizzle-uow-compiler.js +2 -1
  9. package/dist/adapters/drizzle/drizzle-uow-compiler.js.map +1 -1
  10. package/dist/adapters/drizzle/drizzle-uow-decoder.js +25 -1
  11. package/dist/adapters/drizzle/drizzle-uow-decoder.js.map +1 -1
  12. package/dist/adapters/drizzle/generate.js +1 -1
  13. package/dist/adapters/kysely/kysely-adapter.d.ts +4 -3
  14. package/dist/adapters/kysely/kysely-adapter.d.ts.map +1 -1
  15. package/dist/adapters/kysely/kysely-adapter.js.map +1 -1
  16. package/dist/adapters/kysely/kysely-query.d.ts +22 -0
  17. package/dist/adapters/kysely/kysely-query.d.ts.map +1 -0
  18. package/dist/adapters/kysely/kysely-query.js +101 -51
  19. package/dist/adapters/kysely/kysely-query.js.map +1 -1
  20. package/dist/adapters/kysely/kysely-uow-compiler.js +2 -1
  21. package/dist/adapters/kysely/kysely-uow-compiler.js.map +1 -1
  22. package/dist/adapters/kysely/kysely-uow-executor.js +2 -2
  23. package/dist/adapters/kysely/kysely-uow-executor.js.map +1 -1
  24. package/dist/adapters/kysely/migration/execute-base.js +1 -1
  25. package/dist/migration-engine/generation-engine.d.ts +1 -1
  26. package/dist/migration-engine/generation-engine.d.ts.map +1 -1
  27. package/dist/migration-engine/generation-engine.js.map +1 -1
  28. package/dist/mod.d.ts +7 -6
  29. package/dist/mod.d.ts.map +1 -1
  30. package/dist/mod.js +2 -1
  31. package/dist/mod.js.map +1 -1
  32. package/dist/query/cursor.d.ts +67 -32
  33. package/dist/query/cursor.d.ts.map +1 -1
  34. package/dist/query/cursor.js +84 -31
  35. package/dist/query/cursor.js.map +1 -1
  36. package/dist/query/query.d.ts +29 -8
  37. package/dist/query/query.d.ts.map +1 -1
  38. package/dist/query/result-transform.js +17 -5
  39. package/dist/query/result-transform.js.map +1 -1
  40. package/dist/query/unit-of-work.d.ts +19 -8
  41. package/dist/query/unit-of-work.d.ts.map +1 -1
  42. package/dist/query/unit-of-work.js +54 -12
  43. package/dist/query/unit-of-work.js.map +1 -1
  44. package/dist/schema/serialize.js +2 -0
  45. package/dist/schema/serialize.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +242 -55
  48. package/src/adapters/drizzle/drizzle-adapter-sqlite.test.ts +95 -39
  49. package/src/adapters/drizzle/drizzle-query.test.ts +54 -4
  50. package/src/adapters/drizzle/drizzle-query.ts +74 -60
  51. package/src/adapters/drizzle/drizzle-uow-compiler.test.ts +82 -6
  52. package/src/adapters/drizzle/drizzle-uow-compiler.ts +3 -2
  53. package/src/adapters/drizzle/drizzle-uow-decoder.ts +40 -1
  54. package/src/adapters/kysely/kysely-adapter-pglite.test.ts +190 -4
  55. package/src/adapters/kysely/kysely-adapter.ts +6 -3
  56. package/src/adapters/kysely/kysely-query.test.ts +498 -0
  57. package/src/adapters/kysely/kysely-query.ts +187 -83
  58. package/src/adapters/kysely/kysely-uow-compiler.test.ts +85 -3
  59. package/src/adapters/kysely/kysely-uow-compiler.ts +3 -2
  60. package/src/adapters/kysely/kysely-uow-executor.ts +5 -9
  61. package/src/migration-engine/generation-engine.ts +2 -1
  62. package/src/mod.ts +12 -7
  63. package/src/query/cursor.test.ts +113 -68
  64. package/src/query/cursor.ts +127 -36
  65. package/src/query/query-type.test.ts +34 -14
  66. package/src/query/query.ts +94 -34
  67. package/src/query/result-transform.test.ts +5 -5
  68. package/src/query/result-transform.ts +29 -11
  69. package/src/query/unit-of-work.ts +141 -26
  70. package/src/schema/serialize.test.ts +223 -0
  71. package/src/schema/serialize.ts +16 -0
@@ -342,6 +342,229 @@ describe("serialize", () => {
342
342
  const time = Date.now();
343
343
  expect(deserialize(time, dateCol, "sqlite")).toEqual(new Date(time));
344
344
  });
345
+
346
+ it("should handle ISO string timestamps with positive timezone offset", () => {
347
+ const timestampCol = column("timestamp");
348
+ const time = "2024-06-15T14:30:00+05:30"; // India Standard Time
349
+ const result = deserialize(time, timestampCol, "sqlite");
350
+ expect(result).toBeInstanceOf(Date);
351
+ expect(result.toISOString()).toBe("2024-06-15T09:00:00.000Z");
352
+ });
353
+
354
+ it("should handle ISO string timestamps with negative timezone offset", () => {
355
+ const timestampCol = column("timestamp");
356
+ const time = "2024-06-15T14:30:00-08:00"; // Pacific Time
357
+ const result = deserialize(time, timestampCol, "sqlite");
358
+ expect(result).toBeInstanceOf(Date);
359
+ expect(result.toISOString()).toBe("2024-06-15T22:30:00.000Z");
360
+ });
361
+
362
+ it("should preserve absolute time when deserializing numeric timestamps", () => {
363
+ const timestampCol = column("timestamp");
364
+ // Create a specific date and get its numeric representation
365
+ const specificDate = new Date("2024-06-15T12:00:00Z");
366
+ const numericTimestamp = specificDate.getTime();
367
+
368
+ const result = deserialize(numericTimestamp, timestampCol, "sqlite");
369
+ expect(result).toBeInstanceOf(Date);
370
+ expect(result.getTime()).toBe(numericTimestamp);
371
+ expect(result.toISOString()).toBe("2024-06-15T12:00:00.000Z");
372
+ });
373
+
374
+ it("should handle round-trip serialization/deserialization with timezones", () => {
375
+ const timestampCol = column("timestamp");
376
+ // Start with a date with timezone info
377
+ const originalTime = "2024-06-15T14:30:00+02:00";
378
+ const deserialized = deserialize(originalTime, timestampCol, "sqlite");
379
+
380
+ // SQLite would store this as a number
381
+ const numericValue = deserialized.getTime();
382
+
383
+ // Deserialize the numeric value back
384
+ const roundTrip = deserialize(numericValue, timestampCol, "sqlite");
385
+
386
+ expect(roundTrip).toBeInstanceOf(Date);
387
+ expect(roundTrip.getTime()).toBe(deserialized.getTime());
388
+ expect(roundTrip.toISOString()).toBe(deserialized.toISOString());
389
+ });
390
+ });
391
+
392
+ describe("postgresql date handling", () => {
393
+ it("should convert string timestamps to Date", () => {
394
+ const timestampCol = column("timestamp");
395
+ const time = "2024-01-01 12:30:45.123";
396
+ expect(deserialize(time, timestampCol, "postgresql")).toEqual(new Date(time));
397
+ });
398
+
399
+ it("should convert ISO string timestamps to Date", () => {
400
+ const timestampCol = column("timestamp");
401
+ const time = "2024-01-01T00:00:00.000Z";
402
+ expect(deserialize(time, timestampCol, "postgresql")).toEqual(new Date(time));
403
+ });
404
+
405
+ it("should convert date strings to Date", () => {
406
+ const dateCol = column("date");
407
+ const time = "2024-01-01";
408
+ expect(deserialize(time, dateCol, "postgresql")).toEqual(new Date(time));
409
+ });
410
+
411
+ it("should handle timestamps with positive timezone offset", () => {
412
+ const timestampCol = column("timestamp");
413
+ const time = "2024-06-15T14:30:00+05:30"; // India Standard Time
414
+ const result = deserialize(time, timestampCol, "postgresql");
415
+ expect(result).toBeInstanceOf(Date);
416
+ expect(result.toISOString()).toBe("2024-06-15T09:00:00.000Z");
417
+ });
418
+
419
+ it("should handle timestamps with negative timezone offset", () => {
420
+ const timestampCol = column("timestamp");
421
+ const time = "2024-06-15T14:30:00-08:00"; // Pacific Time
422
+ const result = deserialize(time, timestampCol, "postgresql");
423
+ expect(result).toBeInstanceOf(Date);
424
+ expect(result.toISOString()).toBe("2024-06-15T22:30:00.000Z");
425
+ });
426
+
427
+ it("should handle timestamps with fractional seconds and timezone", () => {
428
+ const timestampCol = column("timestamp");
429
+ const time = "2024-06-15T14:30:45.123+01:00"; // Central European Time
430
+ const result = deserialize(time, timestampCol, "postgresql");
431
+ expect(result).toBeInstanceOf(Date);
432
+ expect(result.toISOString()).toBe("2024-06-15T13:30:45.123Z");
433
+ expect(result.getTime()).toBe(new Date("2024-06-15T13:30:45.123Z").getTime());
434
+ });
435
+
436
+ it("should preserve absolute time across timezone conversions", () => {
437
+ const timestampCol = column("timestamp");
438
+ // Same absolute time in different timezones
439
+ const utcTime = "2024-06-15T12:00:00Z";
440
+ const estTime = "2024-06-15T08:00:00-04:00";
441
+ const jstTime = "2024-06-15T21:00:00+09:00";
442
+
443
+ const utcResult = deserialize(utcTime, timestampCol, "postgresql");
444
+ const estResult = deserialize(estTime, timestampCol, "postgresql");
445
+ const jstResult = deserialize(jstTime, timestampCol, "postgresql");
446
+
447
+ // All should represent the same absolute time
448
+ expect(utcResult.getTime()).toBe(estResult.getTime());
449
+ expect(utcResult.getTime()).toBe(jstResult.getTime());
450
+ expect(estResult.getTime()).toBe(jstResult.getTime());
451
+ });
452
+ });
453
+
454
+ describe("mysql date handling", () => {
455
+ it("should convert string timestamps to Date", () => {
456
+ const timestampCol = column("timestamp");
457
+ const time = "2024-01-01 12:30:45";
458
+ expect(deserialize(time, timestampCol, "mysql")).toEqual(new Date(time));
459
+ });
460
+
461
+ it("should convert ISO string timestamps to Date", () => {
462
+ const timestampCol = column("timestamp");
463
+ const time = "2024-01-01T00:00:00.000Z";
464
+ expect(deserialize(time, timestampCol, "mysql")).toEqual(new Date(time));
465
+ });
466
+
467
+ it("should convert date strings to Date", () => {
468
+ const dateCol = column("date");
469
+ const time = "2024-01-01";
470
+ expect(deserialize(time, dateCol, "mysql")).toEqual(new Date(time));
471
+ });
472
+
473
+ it("should handle timestamps with positive timezone offset", () => {
474
+ const timestampCol = column("timestamp");
475
+ const time = "2024-06-15T14:30:00+05:30"; // India Standard Time
476
+ const result = deserialize(time, timestampCol, "mysql");
477
+ expect(result).toBeInstanceOf(Date);
478
+ expect(result.toISOString()).toBe("2024-06-15T09:00:00.000Z");
479
+ });
480
+
481
+ it("should handle timestamps with negative timezone offset", () => {
482
+ const timestampCol = column("timestamp");
483
+ const time = "2024-06-15T14:30:00-08:00"; // Pacific Time
484
+ const result = deserialize(time, timestampCol, "mysql");
485
+ expect(result).toBeInstanceOf(Date);
486
+ expect(result.toISOString()).toBe("2024-06-15T22:30:00.000Z");
487
+ });
488
+
489
+ it("should handle timestamps with fractional seconds and timezone", () => {
490
+ const timestampCol = column("timestamp");
491
+ const time = "2024-06-15T14:30:45.123+01:00"; // Central European Time
492
+ const result = deserialize(time, timestampCol, "mysql");
493
+ expect(result).toBeInstanceOf(Date);
494
+ expect(result.toISOString()).toBe("2024-06-15T13:30:45.123Z");
495
+ });
496
+
497
+ it("should preserve absolute time across timezone conversions", () => {
498
+ const timestampCol = column("timestamp");
499
+ // Same absolute time in different timezones
500
+ const utcTime = "2024-06-15T12:00:00Z";
501
+ const cstTime = "2024-06-15T20:00:00+08:00"; // China Standard Time
502
+ const pstTime = "2024-06-15T04:00:00-08:00"; // Pacific Time
503
+
504
+ const utcResult = deserialize(utcTime, timestampCol, "mysql");
505
+ const cstResult = deserialize(cstTime, timestampCol, "mysql");
506
+ const pstResult = deserialize(pstTime, timestampCol, "mysql");
507
+
508
+ // All should represent the same absolute time
509
+ expect(utcResult.getTime()).toBe(cstResult.getTime());
510
+ expect(utcResult.getTime()).toBe(pstResult.getTime());
511
+ expect(cstResult.getTime()).toBe(pstResult.getTime());
512
+ });
513
+ });
514
+
515
+ describe("cockroachdb date handling", () => {
516
+ it("should convert string timestamps to Date", () => {
517
+ const timestampCol = column("timestamp");
518
+ const time = "2024-01-01 12:30:45.123";
519
+ expect(deserialize(time, timestampCol, "cockroachdb")).toEqual(new Date(time));
520
+ });
521
+
522
+ it("should convert date strings to Date", () => {
523
+ const dateCol = column("date");
524
+ const time = "2024-01-01";
525
+ expect(deserialize(time, dateCol, "cockroachdb")).toEqual(new Date(time));
526
+ });
527
+
528
+ it("should handle timestamps with positive timezone offset", () => {
529
+ const timestampCol = column("timestamp");
530
+ const time = "2024-06-15T14:30:00+05:30"; // India Standard Time
531
+ const result = deserialize(time, timestampCol, "cockroachdb");
532
+ expect(result).toBeInstanceOf(Date);
533
+ expect(result.toISOString()).toBe("2024-06-15T09:00:00.000Z");
534
+ });
535
+
536
+ it("should handle timestamps with negative timezone offset", () => {
537
+ const timestampCol = column("timestamp");
538
+ const time = "2024-06-15T14:30:00-08:00"; // Pacific Time
539
+ const result = deserialize(time, timestampCol, "cockroachdb");
540
+ expect(result).toBeInstanceOf(Date);
541
+ expect(result.toISOString()).toBe("2024-06-15T22:30:00.000Z");
542
+ });
543
+
544
+ it("should handle timestamps with fractional seconds and timezone", () => {
545
+ const timestampCol = column("timestamp");
546
+ const time = "2024-06-15T14:30:45.123+01:00"; // Central European Time
547
+ const result = deserialize(time, timestampCol, "cockroachdb");
548
+ expect(result).toBeInstanceOf(Date);
549
+ expect(result.toISOString()).toBe("2024-06-15T13:30:45.123Z");
550
+ });
551
+
552
+ it("should preserve absolute time across timezone conversions", () => {
553
+ const timestampCol = column("timestamp");
554
+ // Same absolute time in different timezones
555
+ const utcTime = "2024-06-15T12:00:00Z";
556
+ const aestTime = "2024-06-15T22:00:00+10:00"; // Australian Eastern Standard Time
557
+ const brtTime = "2024-06-15T09:00:00-03:00"; // Brasilia Time
558
+
559
+ const utcResult = deserialize(utcTime, timestampCol, "cockroachdb");
560
+ const aestResult = deserialize(aestTime, timestampCol, "cockroachdb");
561
+ const brtResult = deserialize(brtTime, timestampCol, "cockroachdb");
562
+
563
+ // All should represent the same absolute time
564
+ expect(utcResult.getTime()).toBe(aestResult.getTime());
565
+ expect(utcResult.getTime()).toBe(brtResult.getTime());
566
+ expect(aestResult.getTime()).toBe(brtResult.getTime());
567
+ });
345
568
  });
346
569
 
347
570
  describe("boolean handling", () => {
@@ -300,6 +300,22 @@ export function deserialize(value: unknown, col: AnyColumn, provider: SQLProvide
300
300
  return new Date(value);
301
301
  }
302
302
 
303
+ if (
304
+ (provider === "postgresql" || provider === "cockroachdb") &&
305
+ (col.type === "timestamp" || col.type === "date") &&
306
+ typeof value === "string"
307
+ ) {
308
+ return new Date(value);
309
+ }
310
+
311
+ if (
312
+ provider === "mysql" &&
313
+ (col.type === "timestamp" || col.type === "date") &&
314
+ typeof value === "string"
315
+ ) {
316
+ return new Date(value);
317
+ }
318
+
303
319
  if (col.type === "bool" && typeof value === "number") {
304
320
  return value === 1;
305
321
  }