@effect/sql-sqlite-bun 4.0.0-beta.99 → 4.0.0-rc.109
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/AGENTS.md +395 -0
- package/CLAUDE.md +395 -0
- package/README.md +10 -3
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +5 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +165 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/40_sql/10_basics.ts +175 -0
- package/ai-docs/src/40_sql/index.md +6 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +118 -0
- package/ai-docs/src/51_http-server/20_testing.ts +100 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +160 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +24 -0
- package/dist/SqliteClient.d.ts +10 -3
- package/dist/SqliteClient.d.ts.map +1 -1
- package/dist/SqliteClient.js +18 -7
- package/dist/SqliteClient.js.map +1 -1
- package/dist/SqliteMigrator.d.ts +2 -2
- package/dist/SqliteMigrator.js +2 -2
- package/dist/SqliteMigrator.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
- package/src/SqliteClient.ts +29 -9
- package/src/SqliteMigrator.ts +2 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "../tsconfig.base.json",
|
|
4
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"rootDir": ".",
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"declaration": false,
|
|
9
|
+
"declarationMap": false,
|
|
10
|
+
"composite": false,
|
|
11
|
+
"incremental": false,
|
|
12
|
+
"types": ["node"],
|
|
13
|
+
"plugins": [
|
|
14
|
+
{
|
|
15
|
+
"name": "@effect/language-service",
|
|
16
|
+
"namespaceImportPackages": [],
|
|
17
|
+
"diagnosticSeverity": {
|
|
18
|
+
"floatingEffect": "off",
|
|
19
|
+
"preferSchemaOverJson": "off"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/SqliteClient.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Config from "effect/Config";
|
|
2
2
|
import * as Context from "effect/Context";
|
|
3
|
+
import * as Duration from "effect/Duration";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
4
5
|
import * as Layer from "effect/Layer";
|
|
5
6
|
import * as Scope from "effect/Scope";
|
|
@@ -23,7 +24,7 @@ export type TypeId = "~@effect/sql-sqlite-bun/SqliteClient";
|
|
|
23
24
|
/**
|
|
24
25
|
* Bun SQLite client service, extending `SqlClient` with database export and extension loading helpers. `updateValues` is not supported.
|
|
25
26
|
*
|
|
26
|
-
* @category
|
|
27
|
+
* @category services
|
|
27
28
|
* @since 4.0.0
|
|
28
29
|
*/
|
|
29
30
|
export interface SqliteClient extends Client.SqlClient {
|
|
@@ -46,7 +47,7 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
46
47
|
*/
|
|
47
48
|
export declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>;
|
|
48
49
|
/**
|
|
49
|
-
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL behavior, span attributes, and query/result name transforms.
|
|
50
|
+
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL and busy timeout behavior, span attributes, and query/result name transforms.
|
|
50
51
|
*
|
|
51
52
|
* @category models
|
|
52
53
|
* @since 4.0.0
|
|
@@ -57,12 +58,18 @@ export interface SqliteClientConfig {
|
|
|
57
58
|
readonly create?: boolean | undefined;
|
|
58
59
|
readonly readwrite?: boolean | undefined;
|
|
59
60
|
readonly disableWAL?: boolean | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* How long SQLite waits when the database is busy. Defaults to 5 seconds.
|
|
63
|
+
* `Duration.infinity` is clamped to SQLite's maximum timeout.
|
|
64
|
+
* Waiting blocks the event loop because `bun:sqlite` is synchronous.
|
|
65
|
+
*/
|
|
66
|
+
readonly busyTimeout?: Duration.Input | undefined;
|
|
60
67
|
readonly spanAttributes?: Record<string, unknown> | undefined;
|
|
61
68
|
readonly transformResultNames?: ((str: string) => string) | undefined;
|
|
62
69
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
63
70
|
}
|
|
64
71
|
/**
|
|
65
|
-
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default
|
|
72
|
+
* Creates a scoped Bun SQLite client for a database file, enabling WAL and a 5-second busy timeout by default. Explicit transactions on writable connections take the write lock for their duration, even when they only read; clients opened with `readonly: true` are unaffected. Streaming queries are not implemented.
|
|
66
73
|
*
|
|
67
74
|
* @category constructors
|
|
68
75
|
* @since 4.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAAuB,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAS5E;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,MAA+C,CAAA;A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AG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAOD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAmIrE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,KACtC,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAUzB,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,WACR,kBAAkB,KACzB,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAML,CAAA"}
|
package/dist/SqliteClient.js
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
5
5
|
* the generic Effect SQL client. It serializes access to the database, enables
|
|
6
|
-
* WAL mode unless disabled, and
|
|
7
|
-
*
|
|
6
|
+
* WAL mode unless disabled, and waits up to five seconds for busy databases by
|
|
7
|
+
* default. Explicit transactions on writable connections use `BEGIN IMMEDIATE`
|
|
8
|
+
* to avoid read-to-write lock upgrades, which serializes them behind other
|
|
9
|
+
* writers even when they only read. Clients opened with `readonly: true` are
|
|
10
|
+
* unaffected. Busy waits block the event loop because `bun:sqlite` is
|
|
11
|
+
* synchronous. Database export and extension loading are supported; streaming
|
|
12
|
+
* queries and `updateValues` are not.
|
|
8
13
|
*
|
|
9
14
|
* @since 4.0.0
|
|
10
15
|
*/
|
|
11
16
|
import { Database } from "bun:sqlite";
|
|
12
17
|
import * as Config from "effect/Config";
|
|
13
18
|
import * as Context from "effect/Context";
|
|
19
|
+
import * as Duration from "effect/Duration";
|
|
14
20
|
import * as Effect from "effect/Effect";
|
|
15
21
|
import * as Fiber from "effect/Fiber";
|
|
16
22
|
import { identity } from "effect/Function";
|
|
@@ -23,6 +29,7 @@ import * as Client from "effect/unstable/sql/SqlClient";
|
|
|
23
29
|
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
24
30
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
25
31
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
32
|
+
const MAX_BUSY_TIMEOUT = 2_147_483_647;
|
|
26
33
|
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
27
34
|
message,
|
|
28
35
|
operation
|
|
@@ -46,7 +53,7 @@ export const TypeId = "~@effect/sql-sqlite-bun/SqliteClient";
|
|
|
46
53
|
*/
|
|
47
54
|
export const SqliteClient = /*#__PURE__*/Context.Service("@effect/sql-sqlite-bun/Client");
|
|
48
55
|
/**
|
|
49
|
-
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default
|
|
56
|
+
* Creates a scoped Bun SQLite client for a database file, enabling WAL and a 5-second busy timeout by default. Explicit transactions on writable connections take the write lock for their duration, even when they only read; clients opened with `readonly: true` are unaffected. Streaming queries are not implemented.
|
|
50
57
|
*
|
|
51
58
|
* @category constructors
|
|
52
59
|
* @since 4.0.0
|
|
@@ -55,13 +62,16 @@ export const make = options => Effect.gen(function* () {
|
|
|
55
62
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
56
63
|
const transformRows = options.transformResultNames ? Statement.defaultTransforms(options.transformResultNames).array : undefined;
|
|
57
64
|
const makeConnection = Effect.gen(function* () {
|
|
65
|
+
const readonly = options.readonly === true;
|
|
58
66
|
const db = new Database(options.filename, {
|
|
59
|
-
readonly
|
|
60
|
-
readwrite: options.readwrite ?? true,
|
|
61
|
-
create: options.create ?? true
|
|
67
|
+
readonly,
|
|
68
|
+
readwrite: readonly ? false : options.readwrite ?? true,
|
|
69
|
+
create: readonly ? false : options.create ?? true
|
|
62
70
|
});
|
|
63
71
|
yield* Effect.addFinalizer(() => Effect.sync(() => db.close()));
|
|
64
|
-
|
|
72
|
+
const busyTimeout = Math.min(MAX_BUSY_TIMEOUT, Math.max(0, Math.round(Duration.toMillis(options.busyTimeout ?? Duration.seconds(5)))));
|
|
73
|
+
db.run(`PRAGMA busy_timeout = ${busyTimeout};`);
|
|
74
|
+
if (options.disableWAL !== true && !readonly) {
|
|
65
75
|
db.run("PRAGMA journal_mode = WAL;");
|
|
66
76
|
}
|
|
67
77
|
const prepare = (sql, useSafeIntegers) => {
|
|
@@ -135,6 +145,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
135
145
|
acquirer,
|
|
136
146
|
compiler,
|
|
137
147
|
transactionAcquirer,
|
|
148
|
+
beginTransaction: "BEGIN IMMEDIATE",
|
|
138
149
|
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [ATTR_DB_SYSTEM_NAME, "sqlite"]],
|
|
139
150
|
transformRows
|
|
140
151
|
}), {
|
package/dist/SqliteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.js","names":[
|
|
1
|
+
{"version":3,"file":"SqliteClient.js","names":[],"sources":["../src/SqliteClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;AAeA,SAAS,QAAQ,QAAQ,YAAY;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,SAAS,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,UAAU,MAAM,uCAAuC;AACnE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AI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC","ignoreList":[]}
|
package/dist/SqliteMigrator.d.ts
CHANGED
|
@@ -20,14 +20,14 @@ export * from "effect/unstable/sql/Migrator";
|
|
|
20
20
|
/**
|
|
21
21
|
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
22
22
|
*
|
|
23
|
-
* @category
|
|
23
|
+
* @category running
|
|
24
24
|
* @since 4.0.0
|
|
25
25
|
*/
|
|
26
26
|
export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
|
|
27
27
|
/**
|
|
28
28
|
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
29
29
|
*
|
|
30
|
-
* @category
|
|
30
|
+
* @category layers
|
|
31
31
|
* @since 4.0.0
|
|
32
32
|
*/
|
|
33
33
|
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, SqlError | Migrator.MigrationError, Client.SqlClient | R>;
|
package/dist/SqliteMigrator.js
CHANGED
|
@@ -7,7 +7,7 @@ export * from "effect/unstable/sql/Migrator";
|
|
|
7
7
|
/**
|
|
8
8
|
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
9
9
|
*
|
|
10
|
-
* @category
|
|
10
|
+
* @category running
|
|
11
11
|
* @since 4.0.0
|
|
12
12
|
*/
|
|
13
13
|
export const run = /*#__PURE__*/Migrator.make({
|
|
@@ -56,7 +56,7 @@ export const run = /*#__PURE__*/Migrator.make({
|
|
|
56
56
|
/**
|
|
57
57
|
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
58
58
|
*
|
|
59
|
-
* @category
|
|
59
|
+
* @category layers
|
|
60
60
|
* @since 4.0.0
|
|
61
61
|
*/
|
|
62
62
|
export const layer = options => Layer.effectDiscard(run(options));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteMigrator.js","names":[
|
|
1
|
+
{"version":3,"file":"SqliteMigrator.js","names":[],"sources":["../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"AAWA,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;;;AAMA,OAAO,MAAM,GAAG,gBAMZ,QAAQ,CAAC,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;;;AAMA,OAAO,MAAM,KAAK,GAChB,OAAoC,IAKjC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC","ignoreList":[]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAK,YAAY,MAAM,mBAAmB;AAEjD;;;AAGA,OAAO,KAAK,cAAc,MAAM,qBAAqB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-sqlite-bun",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.109",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A SQLite toolkit for Effect",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
".": "./dist/index.js",
|
|
30
30
|
"./*": "./dist/*.js",
|
|
31
31
|
"./internal/*": null,
|
|
32
|
+
"./index": null,
|
|
32
33
|
"./*/index": null
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
@@ -36,7 +37,10 @@
|
|
|
36
37
|
"dist/**/*.js",
|
|
37
38
|
"dist/**/*.js.map",
|
|
38
39
|
"dist/**/*.d.ts",
|
|
39
|
-
"dist/**/*.d.ts.map"
|
|
40
|
+
"dist/**/*.d.ts.map",
|
|
41
|
+
"AGENTS.md",
|
|
42
|
+
"CLAUDE.md",
|
|
43
|
+
"ai-docs/**/*"
|
|
40
44
|
],
|
|
41
45
|
"publishConfig": {
|
|
42
46
|
"access": "public",
|
|
@@ -44,18 +48,16 @@
|
|
|
44
48
|
},
|
|
45
49
|
"devDependencies": {
|
|
46
50
|
"@types/bun": "^1.3.14",
|
|
47
|
-
"@effect/platform-bun": "^4.0.0-
|
|
48
|
-
"effect": "^4.0.0-
|
|
51
|
+
"@effect/platform-bun": "^4.0.0-rc.109",
|
|
52
|
+
"effect": "^4.0.0-rc.109"
|
|
49
53
|
},
|
|
50
54
|
"peerDependencies": {
|
|
51
|
-
"effect": "^4.0.0-
|
|
55
|
+
"effect": "^4.0.0-rc.109"
|
|
52
56
|
},
|
|
53
57
|
"scripts": {
|
|
54
58
|
"codegen": "effect-utils codegen",
|
|
55
59
|
"build": "tsc -b tsconfig.json && pnpm babel",
|
|
56
60
|
"babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
|
|
57
|
-
"check": "tsc -b tsconfig.json"
|
|
58
|
-
"test": "vitest",
|
|
59
|
-
"coverage": "vitest --coverage"
|
|
61
|
+
"check": "tsc -b tsconfig.json"
|
|
60
62
|
}
|
|
61
63
|
}
|
package/src/SqliteClient.ts
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
5
5
|
* the generic Effect SQL client. It serializes access to the database, enables
|
|
6
|
-
* WAL mode unless disabled, and
|
|
7
|
-
*
|
|
6
|
+
* WAL mode unless disabled, and waits up to five seconds for busy databases by
|
|
7
|
+
* default. Explicit transactions on writable connections use `BEGIN IMMEDIATE`
|
|
8
|
+
* to avoid read-to-write lock upgrades, which serializes them behind other
|
|
9
|
+
* writers even when they only read. Clients opened with `readonly: true` are
|
|
10
|
+
* unaffected. Busy waits block the event loop because `bun:sqlite` is
|
|
11
|
+
* synchronous. Database export and extension loading are supported; streaming
|
|
12
|
+
* queries and `updateValues` are not.
|
|
8
13
|
*
|
|
9
14
|
* @since 4.0.0
|
|
10
15
|
*/
|
|
11
16
|
import { Database } from "bun:sqlite"
|
|
12
17
|
import * as Config from "effect/Config"
|
|
13
18
|
import * as Context from "effect/Context"
|
|
19
|
+
import * as Duration from "effect/Duration"
|
|
14
20
|
import * as Effect from "effect/Effect"
|
|
15
21
|
import * as Fiber from "effect/Fiber"
|
|
16
22
|
import { identity } from "effect/Function"
|
|
@@ -25,6 +31,7 @@ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
|
25
31
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
26
32
|
|
|
27
33
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
34
|
+
const MAX_BUSY_TIMEOUT = 2_147_483_647
|
|
28
35
|
|
|
29
36
|
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
30
37
|
classifySqliteError(cause, { message, operation })
|
|
@@ -48,7 +55,7 @@ export type TypeId = "~@effect/sql-sqlite-bun/SqliteClient"
|
|
|
48
55
|
/**
|
|
49
56
|
* Bun SQLite client service, extending `SqlClient` with database export and extension loading helpers. `updateValues` is not supported.
|
|
50
57
|
*
|
|
51
|
-
* @category
|
|
58
|
+
* @category services
|
|
52
59
|
* @since 4.0.0
|
|
53
60
|
*/
|
|
54
61
|
export interface SqliteClient extends Client.SqlClient {
|
|
@@ -74,7 +81,7 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
74
81
|
export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-bun/Client")
|
|
75
82
|
|
|
76
83
|
/**
|
|
77
|
-
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL behavior, span attributes, and query/result name transforms.
|
|
84
|
+
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL and busy timeout behavior, span attributes, and query/result name transforms.
|
|
78
85
|
*
|
|
79
86
|
* @category models
|
|
80
87
|
* @since 4.0.0
|
|
@@ -85,6 +92,12 @@ export interface SqliteClientConfig {
|
|
|
85
92
|
readonly create?: boolean | undefined
|
|
86
93
|
readonly readwrite?: boolean | undefined
|
|
87
94
|
readonly disableWAL?: boolean | undefined
|
|
95
|
+
/**
|
|
96
|
+
* How long SQLite waits when the database is busy. Defaults to 5 seconds.
|
|
97
|
+
* `Duration.infinity` is clamped to SQLite's maximum timeout.
|
|
98
|
+
* Waiting blocks the event loop because `bun:sqlite` is synchronous.
|
|
99
|
+
*/
|
|
100
|
+
readonly busyTimeout?: Duration.Input | undefined
|
|
88
101
|
|
|
89
102
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
90
103
|
|
|
@@ -98,7 +111,7 @@ interface SqliteConnection extends Connection {
|
|
|
98
111
|
}
|
|
99
112
|
|
|
100
113
|
/**
|
|
101
|
-
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default
|
|
114
|
+
* Creates a scoped Bun SQLite client for a database file, enabling WAL and a 5-second busy timeout by default. Explicit transactions on writable connections take the write lock for their duration, even when they only read; clients opened with `readonly: true` are unaffected. Streaming queries are not implemented.
|
|
102
115
|
*
|
|
103
116
|
* @category constructors
|
|
104
117
|
* @since 4.0.0
|
|
@@ -115,14 +128,20 @@ export const make = (
|
|
|
115
128
|
undefined
|
|
116
129
|
|
|
117
130
|
const makeConnection = Effect.gen(function*() {
|
|
131
|
+
const readonly = options.readonly === true
|
|
118
132
|
const db = new Database(options.filename, {
|
|
119
|
-
readonly
|
|
120
|
-
readwrite: options.readwrite ?? true,
|
|
121
|
-
create: options.create ?? true
|
|
133
|
+
readonly,
|
|
134
|
+
readwrite: readonly ? false : options.readwrite ?? true,
|
|
135
|
+
create: readonly ? false : options.create ?? true
|
|
122
136
|
} as any)
|
|
123
137
|
yield* Effect.addFinalizer(() => Effect.sync(() => db.close()))
|
|
138
|
+
const busyTimeout = Math.min(
|
|
139
|
+
MAX_BUSY_TIMEOUT,
|
|
140
|
+
Math.max(0, Math.round(Duration.toMillis(options.busyTimeout ?? Duration.seconds(5))))
|
|
141
|
+
)
|
|
142
|
+
db.run(`PRAGMA busy_timeout = ${busyTimeout};`)
|
|
124
143
|
|
|
125
|
-
if (options.disableWAL !== true) {
|
|
144
|
+
if (options.disableWAL !== true && !readonly) {
|
|
126
145
|
db.run("PRAGMA journal_mode = WAL;")
|
|
127
146
|
}
|
|
128
147
|
|
|
@@ -216,6 +235,7 @@ export const make = (
|
|
|
216
235
|
acquirer,
|
|
217
236
|
compiler,
|
|
218
237
|
transactionAcquirer,
|
|
238
|
+
beginTransaction: "BEGIN IMMEDIATE",
|
|
219
239
|
spanAttributes: [
|
|
220
240
|
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
|
|
221
241
|
[ATTR_DB_SYSTEM_NAME, "sqlite"]
|
package/src/SqliteMigrator.ts
CHANGED
|
@@ -22,7 +22,7 @@ export * from "effect/unstable/sql/Migrator"
|
|
|
22
22
|
/**
|
|
23
23
|
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
24
24
|
*
|
|
25
|
-
* @category
|
|
25
|
+
* @category running
|
|
26
26
|
* @since 4.0.0
|
|
27
27
|
*/
|
|
28
28
|
export const run: <R2 = never>(
|
|
@@ -78,7 +78,7 @@ export const run: <R2 = never>(
|
|
|
78
78
|
/**
|
|
79
79
|
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
80
80
|
*
|
|
81
|
-
* @category
|
|
81
|
+
* @category layers
|
|
82
82
|
* @since 4.0.0
|
|
83
83
|
*/
|
|
84
84
|
export const layer = <R>(
|