turbine-orm 0.19.2 → 0.22.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 +99 -18
- package/dist/adapters/cockroachdb.js +4 -9
- package/dist/cjs/adapters/cockroachdb.js +4 -9
- package/dist/cjs/cli/index.js +6 -3
- package/dist/cjs/cli/observe-ui.js +12 -2
- package/dist/cjs/cli/observe.js +6 -7
- package/dist/cjs/cli/studio.js +6 -7
- package/dist/cjs/client.js +44 -22
- package/dist/cjs/dialect.js +116 -0
- package/dist/cjs/errors.js +19 -1
- package/dist/cjs/generate.js +4 -0
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/introspect.js +20 -0
- package/dist/cjs/mssql.js +1338 -0
- package/dist/cjs/mysql.js +1052 -0
- package/dist/cjs/powdb.js +851 -0
- package/dist/cjs/powql.js +903 -0
- package/dist/cjs/query/builder.js +293 -73
- package/dist/cjs/sqlite.js +849 -0
- package/dist/cjs/typed-sql.js +9 -7
- package/dist/cli/index.js +6 -3
- package/dist/cli/observe-ui.d.ts +1 -1
- package/dist/cli/observe-ui.js +12 -2
- package/dist/cli/observe.js +7 -8
- package/dist/cli/studio.js +7 -8
- package/dist/cli/ui.d.ts +1 -1
- package/dist/client.d.ts +23 -1
- package/dist/client.js +45 -23
- package/dist/dialect.d.ts +258 -1
- package/dist/dialect.js +83 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +17 -0
- package/dist/generate.js +4 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/introspect.d.ts +18 -0
- package/dist/introspect.js +19 -0
- package/dist/mssql.d.ts +233 -0
- package/dist/mssql.js +1298 -0
- package/dist/mysql.d.ts +174 -0
- package/dist/mysql.js +1012 -0
- package/dist/powdb.d.ts +338 -0
- package/dist/powdb.js +802 -0
- package/dist/powql.d.ts +153 -0
- package/dist/powql.js +900 -0
- package/dist/query/builder.d.ts +105 -0
- package/dist/query/builder.js +294 -74
- package/dist/query/index.d.ts +1 -1
- package/dist/sqlite.d.ts +144 -0
- package/dist/sqlite.js +842 -0
- package/dist/typed-sql.d.ts +7 -5
- package/dist/typed-sql.js +9 -7
- package/package.json +45 -1
package/dist/query/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export type { BuiltStatement, BulkInsertStatementInput, ColumnDefinitionInput, C
|
|
|
10
10
|
export { postgresDialect } from '../dialect.js';
|
|
11
11
|
export type { SqlCacheEntry } from './utils.js';
|
|
12
12
|
export { buildCorrelation, escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
|
|
13
|
-
export type { DeferredQuery, MiddlewareFn, QueryEvent, QueryEventListener, QueryInterfaceOptions } from './builder.js';
|
|
13
|
+
export type { DeferredQuery, MiddlewareFn, QueryEvent, QueryEventListener, QueryInterfaceOptions, ReselectExecutor, } from './builder.js';
|
|
14
14
|
export { QueryInterface } from './builder.js';
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/sqlite.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* turbine-orm/sqlite — zero-dependency SQLite engine
|
|
3
|
+
*
|
|
4
|
+
* Binds Turbine to SQLite via Node's built-in `node:sqlite` driver
|
|
5
|
+
* (`DatabaseSync`), so SQLite is a **zero new dependency** engine: the root
|
|
6
|
+
* package's runtime dependency stays exactly `pg`. This is the in-process
|
|
7
|
+
* test / edge / "try it in 10 seconds" engine — `:memory:` databases run
|
|
8
|
+
* entirely in-process with no service container.
|
|
9
|
+
*
|
|
10
|
+
* ## Driver
|
|
11
|
+
*
|
|
12
|
+
* - **Primary:** `node:sqlite` `DatabaseSync` (Node ≥ 22.5, experimental). Emits
|
|
13
|
+
* an `ExperimentalWarning` — harmless. No native build, no extra dependency.
|
|
14
|
+
* - **Fallback:** `better-sqlite3` for Node < 22.5. Not bundled and not required;
|
|
15
|
+
* wrap a `better-sqlite3` handle in the same `PgCompatPool` shape if needed.
|
|
16
|
+
*
|
|
17
|
+
* ## Capabilities & limits (vs PostgreSQL)
|
|
18
|
+
*
|
|
19
|
+
* - `RETURNING` + `ON CONFLICT … DO UPDATE` (SQLite ≥ 3.35) → create / upsert /
|
|
20
|
+
* update / delete return real rows in a single statement (`resultStrategy =
|
|
21
|
+
* 'returning'`, same as Postgres).
|
|
22
|
+
* - **Single-writer:** one connection / one write transaction at a time;
|
|
23
|
+
* concurrent writers get `SQLITE_BUSY` (treated as retryable). `journal_mode =
|
|
24
|
+
* WAL` is enabled for file databases to allow concurrent readers.
|
|
25
|
+
* - **Unsupported (throw `UnsupportedFeatureError`):** pgvector distance ops,
|
|
26
|
+
* LISTEN/NOTIFY (`$listen` / `$notify`), RLS `sessionContext`. Advisory-lock
|
|
27
|
+
* migration locking is unavailable — SQLite is single-writer, so migrations
|
|
28
|
+
* serialize naturally.
|
|
29
|
+
* - **Type affinity caveats:** SQLite has no native `BOOLEAN` (0/1 integers) or
|
|
30
|
+
* `DATE` (TEXT/INTEGER). Booleans bind as 1/0; `Date` values bind as ISO-8601
|
|
31
|
+
* text; columns declared `TIMESTAMP`/`DATETIME`/`DATE` are coerced back to
|
|
32
|
+
* `Date`. Integers wider than `Number.MAX_SAFE_INTEGER` come back as strings
|
|
33
|
+
* (the same safe-int policy Turbine uses for Postgres `int8`).
|
|
34
|
+
* - **Case-insensitive matching** uses `COLLATE NOCASE`, which is **ASCII-only**
|
|
35
|
+
* (no Unicode case folding).
|
|
36
|
+
*
|
|
37
|
+
* ## Example — `:memory:` database
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { turbineSqlite } from 'turbine-orm/sqlite';
|
|
41
|
+
* import { SCHEMA } from './generated/turbine/metadata.js';
|
|
42
|
+
*
|
|
43
|
+
* const db = turbineSqlite(':memory:', SCHEMA);
|
|
44
|
+
* const users = await db.users.findMany({ with: { posts: true }, limit: 10 });
|
|
45
|
+
* await db.disconnect();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
49
|
+
import { type PgCompatPool, type PgCompatPoolClient, TurbineClient, type TurbineConfig } from './client.js';
|
|
50
|
+
import { type Dialect, type IntrospectOptions } from './dialect.js';
|
|
51
|
+
import { type SchemaMetadata, type TableMetadata } from './schema.js';
|
|
52
|
+
/** pg-style query argument: a SQL string or a `{ text, values }` config object. */
|
|
53
|
+
type QueryArg = string | {
|
|
54
|
+
name?: string;
|
|
55
|
+
text: string;
|
|
56
|
+
values?: unknown[];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* A `PgCompatPool` backed by a single `node:sqlite` `DatabaseSync` connection.
|
|
60
|
+
* SQLite is single-connection by nature (a `:memory:` database is per-handle),
|
|
61
|
+
* so `connect()` hands back a client over the **same** handle — transactions
|
|
62
|
+
* (`BEGIN`/`COMMIT`/`ROLLBACK`, `SAVEPOINT` nesting) just run on it. Queries are
|
|
63
|
+
* serialized; this is the documented single-writer model.
|
|
64
|
+
*/
|
|
65
|
+
export declare class SqlitePool implements PgCompatPool {
|
|
66
|
+
/** The underlying `node:sqlite` handle — exposed as an escape hatch (seed/DDL). */
|
|
67
|
+
readonly db: DatabaseSync;
|
|
68
|
+
private closed;
|
|
69
|
+
constructor(db: DatabaseSync);
|
|
70
|
+
query(text: QueryArg, values?: unknown[]): Promise<any>;
|
|
71
|
+
connect(): Promise<PgCompatPoolClient>;
|
|
72
|
+
end(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Map a SQLite declared column type (type affinity) to a TypeScript type.
|
|
76
|
+
* SQLite is dynamically typed; we read the declared `PRAGMA table_info` type.
|
|
77
|
+
*/
|
|
78
|
+
export declare function sqliteTypeToTs(declaredType: string, nullable: boolean): string;
|
|
79
|
+
/**
|
|
80
|
+
* SQLite implementation of the {@link Dialect} contract. Standardizes on `"…"`
|
|
81
|
+
* identifier quoting and positional `?` placeholders, uses `json_object` /
|
|
82
|
+
* `json_group_array` for the single-query nested-relation engine (with the
|
|
83
|
+
* critical `json(...)` subresult wrap so nested objects are real JSON, not
|
|
84
|
+
* SQLite's strings-of-strings double-encoding), keeps `RETURNING` + `ON CONFLICT`
|
|
85
|
+
* (SQLite ≥ 3.35), and disables the Postgres-only capabilities (vector,
|
|
86
|
+
* LISTEN/NOTIFY, RLS, advisory locks).
|
|
87
|
+
*/
|
|
88
|
+
export declare const sqliteDialect: Dialect;
|
|
89
|
+
/**
|
|
90
|
+
* Read a live SQLite database (an open `DatabaseSync` handle) into the same
|
|
91
|
+
* {@link SchemaMetadata} shape the Postgres catalog introspector produces.
|
|
92
|
+
* Exposed directly so callers (and tests) can introspect an in-process
|
|
93
|
+
* `:memory:` database without round-tripping through a file path.
|
|
94
|
+
*/
|
|
95
|
+
export declare function introspectSqliteDatabase(db: DatabaseSync, options?: {
|
|
96
|
+
include?: string[];
|
|
97
|
+
exclude?: string[];
|
|
98
|
+
}): {
|
|
99
|
+
tables: Record<string, TableMetadata>;
|
|
100
|
+
enums: {};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Open the SQLite database named by `options.connectionString` (a file path or
|
|
104
|
+
* `':memory:'`), introspect it, and close it. Wraps
|
|
105
|
+
* {@link introspectSqliteDatabase} for the {@link DialectIntrospector} seam used
|
|
106
|
+
* by `introspect()` / `npx turbine generate`.
|
|
107
|
+
*
|
|
108
|
+
* Note: introspecting `':memory:'` opens a *fresh, empty* database (memory DBs
|
|
109
|
+
* are per-handle), so codegen should target a real file.
|
|
110
|
+
*/
|
|
111
|
+
export declare function introspectSqlite(options: IntrospectOptions): Promise<SchemaMetadata>;
|
|
112
|
+
/** Options for {@link turbineSqlite}. Mirrors the relevant {@link TurbineConfig} fields. */
|
|
113
|
+
export interface TurbineSqliteOptions extends Pick<TurbineConfig, 'logging' | 'defaultLimit' | 'warnOnUnlimited'> {
|
|
114
|
+
/**
|
|
115
|
+
* Enable WAL journal mode for file databases (better read concurrency).
|
|
116
|
+
* Ignored for `':memory:'`. Default: `true`.
|
|
117
|
+
*/
|
|
118
|
+
wal?: boolean;
|
|
119
|
+
/** `PRAGMA busy_timeout` in ms — how long a writer waits on `SQLITE_BUSY`. Default: 5000. */
|
|
120
|
+
busyTimeoutMs?: number;
|
|
121
|
+
/** Enable `PRAGMA foreign_keys` enforcement. Default: `true`. */
|
|
122
|
+
foreignKeys?: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a {@link TurbineClient} bound to SQLite via `node:sqlite`.
|
|
126
|
+
*
|
|
127
|
+
* Pass a file path, `':memory:'`, or an already-open `DatabaseSync` handle (so
|
|
128
|
+
* you can seed / introspect it first and reuse the same connection). The
|
|
129
|
+
* returned client uses {@link sqliteDialect} and disables prepared-statement
|
|
130
|
+
* names (SQLite caches plans internally).
|
|
131
|
+
*
|
|
132
|
+
* @param target A SQLite file path, `':memory:'`, or an open `DatabaseSync`.
|
|
133
|
+
* @param schema Introspected or hand-written {@link SchemaMetadata}.
|
|
134
|
+
* @param options Optional pragmas + logging / defaultLimit / warnOnUnlimited.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { turbineSqlite } from 'turbine-orm/sqlite';
|
|
139
|
+
* const db = turbineSqlite(':memory:', SCHEMA);
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare function turbineSqlite(target: string | DatabaseSync, schema: SchemaMetadata, options?: TurbineSqliteOptions): TurbineClient;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=sqlite.d.ts.map
|