turbine-orm 0.4.0 → 0.5.0

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 (59) hide show
  1. package/README.md +51 -2
  2. package/dist/cjs/cli/config.js +161 -0
  3. package/dist/cjs/cli/index.js +977 -0
  4. package/dist/cjs/cli/migrate.js +421 -0
  5. package/dist/cjs/cli/ui.js +237 -0
  6. package/dist/cjs/client.js +449 -0
  7. package/dist/cjs/generate.js +301 -0
  8. package/dist/cjs/index.js +75 -0
  9. package/dist/cjs/introspect.js +289 -0
  10. package/dist/cjs/package.json +1 -0
  11. package/dist/cjs/pipeline.js +71 -0
  12. package/dist/cjs/query.js +1558 -0
  13. package/dist/cjs/schema-builder.js +169 -0
  14. package/dist/cjs/schema-sql.js +371 -0
  15. package/dist/cjs/schema.js +137 -0
  16. package/dist/cjs/serverless.js +199 -0
  17. package/dist/cli/config.js +1 -1
  18. package/dist/cli/index.js +16 -8
  19. package/dist/cli/migrate.d.ts +29 -5
  20. package/dist/cli/migrate.js +58 -35
  21. package/dist/cli/ui.js +1 -1
  22. package/dist/client.d.ts +15 -4
  23. package/dist/client.js +28 -15
  24. package/dist/generate.d.ts +1 -1
  25. package/dist/generate.js +13 -7
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/introspect.d.ts +1 -1
  29. package/dist/introspect.js +1 -1
  30. package/dist/pipeline.d.ts +1 -1
  31. package/dist/pipeline.js +1 -1
  32. package/dist/query.d.ts +55 -11
  33. package/dist/query.js +135 -140
  34. package/dist/schema-builder.d.ts +2 -2
  35. package/dist/schema-builder.js +2 -2
  36. package/dist/schema-sql.d.ts +1 -1
  37. package/dist/schema-sql.js +31 -15
  38. package/dist/schema.d.ts +1 -1
  39. package/dist/schema.js +1 -1
  40. package/dist/serverless.d.ts +3 -3
  41. package/dist/serverless.js +4 -4
  42. package/dist/types.d.ts +1 -1
  43. package/dist/types.js +1 -1
  44. package/package.json +17 -11
  45. package/dist/cli/config.d.ts.map +0 -1
  46. package/dist/cli/index.d.ts.map +0 -1
  47. package/dist/cli/migrate.d.ts.map +0 -1
  48. package/dist/cli/ui.d.ts.map +0 -1
  49. package/dist/client.d.ts.map +0 -1
  50. package/dist/generate.d.ts.map +0 -1
  51. package/dist/index.d.ts.map +0 -1
  52. package/dist/introspect.d.ts.map +0 -1
  53. package/dist/pipeline.d.ts.map +0 -1
  54. package/dist/query.d.ts.map +0 -1
  55. package/dist/schema-builder.d.ts.map +0 -1
  56. package/dist/schema-sql.d.ts.map +0 -1
  57. package/dist/schema.d.ts.map +0 -1
  58. package/dist/serverless.d.ts.map +0 -1
  59. package/dist/types.d.ts.map +0 -1
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * @batadata/turbine — Pipeline execution
4
+ *
5
+ * Pipelines batch multiple independent queries into a single database round-trip.
6
+ * Instead of N sequential awaits (N round-trips), you get 1 round-trip for all N queries.
7
+ *
8
+ * How it works:
9
+ * 1. Each query method (findUnique, count, etc.) can produce a DeferredQuery descriptor
10
+ * containing the SQL, params, and a transform function.
11
+ * 2. pipeline() collects these descriptors, executes them in a single Postgres
12
+ * pipeline/transaction, and maps each result through its transform.
13
+ *
14
+ * In the production Turbine engine, this would go through the Rust proxy which uses
15
+ * actual Postgres pipeline protocol (libpq PQpipelineEnter). For the TS SDK prototype,
16
+ * we simulate it by running queries concurrently on a single connection or via
17
+ * a multi-statement batch.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.executePipeline = executePipeline;
21
+ // ---------------------------------------------------------------------------
22
+ // Pipeline executor
23
+ // ---------------------------------------------------------------------------
24
+ /**
25
+ * Execute multiple deferred queries in a single batch.
26
+ *
27
+ * Uses a single connection from the pool and runs all queries within
28
+ * a transaction to guarantee consistency and minimize round-trips.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const [user, count, posts] = await executePipeline(pool, [
33
+ * db.users.buildFindUnique({ where: { id: 1 } }),
34
+ * db.posts.buildCount({ where: { orgId: 1 } }),
35
+ * db.posts.buildFindMany({ where: { userId: 1 }, limit: 10 }),
36
+ * ]);
37
+ * ```
38
+ */
39
+ async function executePipeline(pool, queries) {
40
+ if (queries.length === 0) {
41
+ return [];
42
+ }
43
+ // Acquire a single connection for the entire batch
44
+ const client = await pool.connect();
45
+ try {
46
+ // Wrap in a transaction for consistency
47
+ await client.query('BEGIN');
48
+ // Execute all queries on the same connection — in sequence on a single
49
+ // connection this avoids pool checkout overhead, and the Postgres server
50
+ // processes them as a tight batch.
51
+ //
52
+ // Execute queries sequentially on the same connection to avoid the
53
+ // "already executing a query" deprecation in pg@8. This is still faster
54
+ // than separate pool checkouts because we skip N-1 acquire/release cycles.
55
+ // Future: use actual Postgres pipeline protocol for true pipelining.
56
+ const results = [];
57
+ for (const q of queries) {
58
+ const raw = await client.query(q.sql, q.params);
59
+ results.push(q.transform(raw));
60
+ }
61
+ await client.query('COMMIT');
62
+ return results;
63
+ }
64
+ catch (err) {
65
+ await client.query('ROLLBACK');
66
+ throw err;
67
+ }
68
+ finally {
69
+ client.release();
70
+ }
71
+ }