turbine-orm 0.3.1 → 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.
- package/README.md +51 -2
- package/dist/cjs/cli/config.js +161 -0
- package/dist/cjs/cli/index.js +977 -0
- package/dist/cjs/cli/migrate.js +421 -0
- package/dist/cjs/cli/ui.js +237 -0
- package/dist/cjs/client.js +449 -0
- package/dist/cjs/generate.js +301 -0
- package/dist/cjs/index.js +75 -0
- package/dist/cjs/introspect.js +289 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pipeline.js +71 -0
- package/dist/cjs/query.js +1558 -0
- package/dist/cjs/schema-builder.js +169 -0
- package/dist/cjs/schema-sql.js +371 -0
- package/dist/cjs/schema.js +137 -0
- package/dist/cjs/serverless.js +199 -0
- package/dist/cli/index.js +14 -6
- package/dist/cli/migrate.d.ts +29 -5
- package/dist/cli/migrate.js +58 -35
- package/dist/client.d.ts +13 -2
- package/dist/client.js +26 -13
- package/dist/generate.js +7 -1
- package/dist/query.d.ts +54 -2
- package/dist/query.js +126 -35
- package/dist/schema-sql.js +30 -14
- package/package.json +14 -9
- package/dist/cli/config.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/migrate.d.ts.map +0 -1
- package/dist/cli/ui.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/generate.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/introspect.d.ts.map +0 -1
- package/dist/pipeline.d.ts.map +0 -1
- package/dist/query.d.ts.map +0 -1
- package/dist/schema-builder.d.ts.map +0 -1
- package/dist/schema-sql.d.ts.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/serverless.d.ts.map +0 -1
- 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
|
+
}
|