@alchemy.run/drizzle 0.0.0 → 2.0.0-beta.85
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/LICENSE +201 -0
- package/README.md +82 -4
- package/lib/Cloudflare.d.ts +104 -0
- package/lib/Cloudflare.d.ts.map +1 -0
- package/lib/Cloudflare.js +115 -0
- package/lib/Cloudflare.js.map +1 -0
- package/lib/D1.d.ts +48 -0
- package/lib/D1.d.ts.map +1 -0
- package/lib/D1.js +50 -0
- package/lib/D1.js.map +1 -0
- package/lib/LibSQL.d.ts +45 -0
- package/lib/LibSQL.d.ts.map +1 -0
- package/lib/LibSQL.js +47 -0
- package/lib/LibSQL.js.map +1 -0
- package/lib/MySQL.d.ts +45 -0
- package/lib/MySQL.d.ts.map +1 -0
- package/lib/MySQL.js +42 -0
- package/lib/MySQL.js.map +1 -0
- package/lib/Postgres.d.ts +62 -0
- package/lib/Postgres.d.ts.map +1 -0
- package/lib/Postgres.js +59 -0
- package/lib/Postgres.js.map +1 -0
- package/lib/Providers.d.ts +47 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +45 -0
- package/lib/Providers.js.map +1 -0
- package/lib/Schema.d.ts +85 -0
- package/lib/Schema.d.ts.map +1 -0
- package/lib/Schema.js +514 -0
- package/lib/Schema.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/package.json +78 -3
- package/src/Cloudflare.ts +144 -0
- package/src/D1.ts +77 -0
- package/src/LibSQL.ts +74 -0
- package/src/MySQL.ts +86 -0
- package/src/Postgres.ts +100 -0
- package/src/Providers.ts +51 -0
- package/src/Schema.ts +773 -0
- package/src/index.ts +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,9 +1,87 @@
|
|
|
1
1
|
# @alchemy.run/drizzle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Drizzle ORM](https://orm.drizzle.team) for [Alchemy](https://alchemy.run). Generate migrations from your schema at deploy time, and query D1, Postgres, MySQL, or libSQL from a Worker or Lambda with a typed Effect client.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```sh
|
|
6
|
+
npm install alchemy @alchemy.run/drizzle @alchemy.run/cloudflare drizzle-orm drizzle-kit effect
|
|
7
|
+
```
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
A schema:
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
```typescript
|
|
12
|
+
// src/schema.ts
|
|
13
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
14
|
+
|
|
15
|
+
export const Users = sqliteTable("users", {
|
|
16
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
17
|
+
email: text("email").notNull().unique(),
|
|
18
|
+
name: text("name").notNull(),
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
A D1 database whose migrations are generated from that schema on deploy, and a Worker that queries it:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// src/api.ts
|
|
26
|
+
import * as Cloudflare from "@alchemy.run/cloudflare";
|
|
27
|
+
import * as Drizzle from "@alchemy.run/drizzle";
|
|
28
|
+
import * as Effect from "effect/Effect";
|
|
29
|
+
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
|
30
|
+
import { Users } from "./schema.ts";
|
|
31
|
+
|
|
32
|
+
export const Database = Effect.gen(function* () {
|
|
33
|
+
const schema = yield* Drizzle.Schema("Schema", {
|
|
34
|
+
schema: "./src/schema.ts",
|
|
35
|
+
out: "./migrations",
|
|
36
|
+
dialect: "sqlite",
|
|
37
|
+
});
|
|
38
|
+
return yield* Cloudflare.D1.Database("Db", { migrations: schema });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default class Api extends Cloudflare.Worker<Api>()(
|
|
42
|
+
"Api",
|
|
43
|
+
{ main: import.meta.url },
|
|
44
|
+
Effect.gen(function* () {
|
|
45
|
+
const d1 = yield* Cloudflare.D1.QueryDatabase(yield* Database);
|
|
46
|
+
const db = yield* Drizzle.D1(d1);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
fetch: Effect.gen(function* () {
|
|
50
|
+
const users = yield* db.select().from(Users);
|
|
51
|
+
return yield* HttpServerResponse.json({ users });
|
|
52
|
+
}).pipe(Effect.orDie),
|
|
53
|
+
};
|
|
54
|
+
}).pipe(Effect.provide(Cloudflare.D1.QueryDatabaseBinding)),
|
|
55
|
+
) {}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// alchemy.run.ts
|
|
60
|
+
import * as Alchemy from "alchemy";
|
|
61
|
+
import * as Cloudflare from "@alchemy.run/cloudflare";
|
|
62
|
+
import * as Drizzle from "@alchemy.run/drizzle";
|
|
63
|
+
import * as Effect from "effect/Effect";
|
|
64
|
+
import * as Layer from "effect/Layer";
|
|
65
|
+
import Api from "./src/api.ts";
|
|
66
|
+
|
|
67
|
+
export default Alchemy.Stack(
|
|
68
|
+
"MyApp",
|
|
69
|
+
{
|
|
70
|
+
providers: Layer.mergeAll(Cloudflare.providers(), Drizzle.providers()),
|
|
71
|
+
state: Cloudflare.state(),
|
|
72
|
+
},
|
|
73
|
+
Effect.gen(function* () {
|
|
74
|
+
const api = yield* Api;
|
|
75
|
+
return { url: api.url };
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`Drizzle.Postgres`, `Drizzle.MySQL`, and `Drizzle.LibSQL` work the same way for the other databases.
|
|
81
|
+
|
|
82
|
+
## Learn more
|
|
83
|
+
|
|
84
|
+
- [Drizzle with D1](https://alchemy.run/sql/drizzle/d1)
|
|
85
|
+
- [Drizzle with Postgres](https://alchemy.run/sql/drizzle/postgres)
|
|
86
|
+
- [Drizzle migrations](https://alchemy.run/sql/drizzle/migrations)
|
|
87
|
+
- [SQL on alchemy.run](https://alchemy.run/sql)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DurableObjectState } from "@alchemy.run/cloudflare/Workers/DurableObjectState";
|
|
2
|
+
import type { SqlMigrations } from "@alchemy.run/cloudflare/Workers/SqlMigrations";
|
|
3
|
+
import * as SqliteDoClient from "@effect/sql-sqlite-do/SqliteClient";
|
|
4
|
+
import type { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
5
|
+
import * as SQLiteDoDrizzle from "drizzle-orm/effect-sqlite-do";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
/**
|
|
8
|
+
* Migrations for {@link DurableObject} — the shape of the `migrations.js`
|
|
9
|
+
* bundle `drizzle-kit generate` emits for `driver: "durable-sqlite"`
|
|
10
|
+
* (each migration's `.sql` file imported as a text module).
|
|
11
|
+
*/
|
|
12
|
+
export interface DurableObjectMigrations {
|
|
13
|
+
readonly migrations: Record<string, string>;
|
|
14
|
+
readonly migrationsTable?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface DurableObjectConfig<TRelations extends AnyRelations = EmptyRelations> extends SQLiteDoDrizzle.EffectDrizzleSQLiteDoConfig<TRelations> {
|
|
17
|
+
/**
|
|
18
|
+
* Migrations applied before the database is returned. Prefer a snapshot
|
|
19
|
+
* from `Cloudflare.SqlMigrations(dir)`: SQL is read during construction
|
|
20
|
+
* and applied with Alchemy's `__alchemy_migrations` bookkeeping.
|
|
21
|
+
* The generated Drizzle `migrations.js` input remains supported and uses
|
|
22
|
+
* Drizzle's own migrator; its SQL imports still require loader support.
|
|
23
|
+
*/
|
|
24
|
+
readonly migrations?: SqlMigrations | DurableObjectMigrations | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Open a Drizzle database over the current Durable Object's SQLite
|
|
28
|
+
* storage using the `drizzle-orm/effect-sqlite-do` integration (driven by
|
|
29
|
+
* `@effect/sql-sqlite-do`'s `SqliteClient`), applying migrations first
|
|
30
|
+
* when provided. `Cloudflare.SqlMigrations` captures a SQL directory during
|
|
31
|
+
* construction without importing `.sql` files. Each instance applies pending
|
|
32
|
+
* files on activation using Alchemy's shared migration history.
|
|
33
|
+
*
|
|
34
|
+
* Every query is an Effect with a typed error channel — drizzle's
|
|
35
|
+
* `EffectDrizzleQueryError` (query + params + cause, wrapping the
|
|
36
|
+
* underlying effect-sql `SqlError`) — so failures are handled with
|
|
37
|
+
* `Effect.catchTag` instead of leaking as defects. Transactions add
|
|
38
|
+
* `SqlError` to the union. Opening the db itself never fails: a
|
|
39
|
+
* migration that cannot apply dies, since the instance is unusable
|
|
40
|
+
* without its schema.
|
|
41
|
+
*
|
|
42
|
+
* Yield it in the object's inner (instance) Effect — it runs when the
|
|
43
|
+
* instance activates, before any request reaches its methods:
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // schema.ts
|
|
47
|
+
* import { defineRelations } from "drizzle-orm";
|
|
48
|
+
* import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
49
|
+
*
|
|
50
|
+
* export const users = sqliteTable("users", {
|
|
51
|
+
* id: integer("id").primaryKey({ autoIncrement: true }),
|
|
52
|
+
* name: text("name").notNull(),
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* export const posts = sqliteTable("posts", {
|
|
56
|
+
* id: integer("id").primaryKey({ autoIncrement: true }),
|
|
57
|
+
* userId: integer("user_id").notNull().references(() => users.id),
|
|
58
|
+
* title: text("title").notNull(),
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* export const relations = defineRelations({ users, posts }, (t) => ({
|
|
62
|
+
* users: { posts: t.many.posts() },
|
|
63
|
+
* posts: { author: t.one.users({ from: t.posts.userId, to: t.users.id }) },
|
|
64
|
+
* }));
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import * as Drizzle from "@alchemy.run/drizzle/Cloudflare";
|
|
69
|
+
* import { posts, relations, users } from "./schema.ts";
|
|
70
|
+
*
|
|
71
|
+
* export class Users extends Cloudflare.DurableObject<Users>()(
|
|
72
|
+
* "Users",
|
|
73
|
+
* Effect.gen(function* () {
|
|
74
|
+
* const migrations = yield* Cloudflare.SqlMigrations("./drizzle");
|
|
75
|
+
* return Effect.gen(function* () {
|
|
76
|
+
* const db = yield* Drizzle.DurableObject({ migrations, relations });
|
|
77
|
+
*
|
|
78
|
+
* return {
|
|
79
|
+
* addUser: (name: string) => db.insert(users).values({ name }),
|
|
80
|
+
* listUsers: () => db.select().from(users),
|
|
81
|
+
* listUsersWithPosts: () =>
|
|
82
|
+
* db.query.users.findMany({ with: { posts: true } }),
|
|
83
|
+
* // typed error handling per operation:
|
|
84
|
+
* tryAddUser: (name: string) =>
|
|
85
|
+
* db
|
|
86
|
+
* .insert(users)
|
|
87
|
+
* .values({ name })
|
|
88
|
+
* .pipe(
|
|
89
|
+
* Effect.catchTag("EffectDrizzleQueryError", () =>
|
|
90
|
+
* Effect.succeed(undefined),
|
|
91
|
+
* ),
|
|
92
|
+
* ),
|
|
93
|
+
* };
|
|
94
|
+
* });
|
|
95
|
+
* }),
|
|
96
|
+
* ) {}
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @binding
|
|
100
|
+
*/
|
|
101
|
+
export declare const DurableObject: <TRelations extends AnyRelations = EmptyRelations>(config?: DurableObjectConfig<TRelations> | undefined) => Effect.Effect<SQLiteDoDrizzle.EffectSQLiteDoDatabase<TRelations> & {
|
|
102
|
+
$client: SqliteDoClient.SqliteClient;
|
|
103
|
+
}, never, DurableObjectState | import("alchemy").RuntimeContext | import("effect/Scope").Scope>;
|
|
104
|
+
//# sourceMappingURL=Cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cloudflare.d.ts","sourceRoot":"","sources":["../src/Cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AACnF,OAAO,KAAK,cAAc,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAGhE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/C;AAED,MAAM,WAAW,mBAAmB,CAClC,UAAU,SAAS,YAAY,GAAG,cAAc,CAChD,SAAQ,eAAe,CAAC,2BAA2B,CAAC,UAAU,CAAC;IAC/D;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,GAAG,uBAAuB,GAAG,SAAS,CAAC;CAC3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,SAAS,YAAY;;+FAiC/B,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { DurableObjectState } from "@alchemy.run/cloudflare/Workers/DurableObjectState";
|
|
2
|
+
import * as SqliteDoClient from "@effect/sql-sqlite-do/SqliteClient";
|
|
3
|
+
import * as SQLiteDoDrizzle from "drizzle-orm/effect-sqlite-do";
|
|
4
|
+
import { migrate } from "drizzle-orm/effect-sqlite-do/migrator";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Scheduler from "effect/Scheduler";
|
|
9
|
+
/**
|
|
10
|
+
* Open a Drizzle database over the current Durable Object's SQLite
|
|
11
|
+
* storage using the `drizzle-orm/effect-sqlite-do` integration (driven by
|
|
12
|
+
* `@effect/sql-sqlite-do`'s `SqliteClient`), applying migrations first
|
|
13
|
+
* when provided. `Cloudflare.SqlMigrations` captures a SQL directory during
|
|
14
|
+
* construction without importing `.sql` files. Each instance applies pending
|
|
15
|
+
* files on activation using Alchemy's shared migration history.
|
|
16
|
+
*
|
|
17
|
+
* Every query is an Effect with a typed error channel — drizzle's
|
|
18
|
+
* `EffectDrizzleQueryError` (query + params + cause, wrapping the
|
|
19
|
+
* underlying effect-sql `SqlError`) — so failures are handled with
|
|
20
|
+
* `Effect.catchTag` instead of leaking as defects. Transactions add
|
|
21
|
+
* `SqlError` to the union. Opening the db itself never fails: a
|
|
22
|
+
* migration that cannot apply dies, since the instance is unusable
|
|
23
|
+
* without its schema.
|
|
24
|
+
*
|
|
25
|
+
* Yield it in the object's inner (instance) Effect — it runs when the
|
|
26
|
+
* instance activates, before any request reaches its methods:
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // schema.ts
|
|
30
|
+
* import { defineRelations } from "drizzle-orm";
|
|
31
|
+
* import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
32
|
+
*
|
|
33
|
+
* export const users = sqliteTable("users", {
|
|
34
|
+
* id: integer("id").primaryKey({ autoIncrement: true }),
|
|
35
|
+
* name: text("name").notNull(),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* export const posts = sqliteTable("posts", {
|
|
39
|
+
* id: integer("id").primaryKey({ autoIncrement: true }),
|
|
40
|
+
* userId: integer("user_id").notNull().references(() => users.id),
|
|
41
|
+
* title: text("title").notNull(),
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* export const relations = defineRelations({ users, posts }, (t) => ({
|
|
45
|
+
* users: { posts: t.many.posts() },
|
|
46
|
+
* posts: { author: t.one.users({ from: t.posts.userId, to: t.users.id }) },
|
|
47
|
+
* }));
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import * as Drizzle from "@alchemy.run/drizzle/Cloudflare";
|
|
52
|
+
* import { posts, relations, users } from "./schema.ts";
|
|
53
|
+
*
|
|
54
|
+
* export class Users extends Cloudflare.DurableObject<Users>()(
|
|
55
|
+
* "Users",
|
|
56
|
+
* Effect.gen(function* () {
|
|
57
|
+
* const migrations = yield* Cloudflare.SqlMigrations("./drizzle");
|
|
58
|
+
* return Effect.gen(function* () {
|
|
59
|
+
* const db = yield* Drizzle.DurableObject({ migrations, relations });
|
|
60
|
+
*
|
|
61
|
+
* return {
|
|
62
|
+
* addUser: (name: string) => db.insert(users).values({ name }),
|
|
63
|
+
* listUsers: () => db.select().from(users),
|
|
64
|
+
* listUsersWithPosts: () =>
|
|
65
|
+
* db.query.users.findMany({ with: { posts: true } }),
|
|
66
|
+
* // typed error handling per operation:
|
|
67
|
+
* tryAddUser: (name: string) =>
|
|
68
|
+
* db
|
|
69
|
+
* .insert(users)
|
|
70
|
+
* .values({ name })
|
|
71
|
+
* .pipe(
|
|
72
|
+
* Effect.catchTag("EffectDrizzleQueryError", () =>
|
|
73
|
+
* Effect.succeed(undefined),
|
|
74
|
+
* ),
|
|
75
|
+
* ),
|
|
76
|
+
* };
|
|
77
|
+
* });
|
|
78
|
+
* }),
|
|
79
|
+
* ) {}
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @binding
|
|
83
|
+
*/
|
|
84
|
+
export const DurableObject = Effect.fn("Drizzle.DurableObject")(function* (config) {
|
|
85
|
+
const state = yield* DurableObjectState;
|
|
86
|
+
const storage = state.raw.storage;
|
|
87
|
+
const { migrations, ...drizzleConfig } = config ?? {};
|
|
88
|
+
// Built on the ambient (instance) Scope — the client wraps the DO's
|
|
89
|
+
// local SQLite storage, so there is no disposable resource behind it.
|
|
90
|
+
const services = yield* Layer.build(SqliteDoClient.layer({ storage }));
|
|
91
|
+
const client = Context.get(services, SqliteDoClient.SqliteClient);
|
|
92
|
+
const original = client.withTransaction;
|
|
93
|
+
const scheduler = new Scheduler.MixedScheduler("sync");
|
|
94
|
+
const withTransaction = (body) => original(body).pipe(Effect.provideService(Scheduler.Scheduler, scheduler));
|
|
95
|
+
// A parent input-gate timer can block later transaction timers. Yield through
|
|
96
|
+
// microtasks while retaining the adapter's client, SQL permit, and context.
|
|
97
|
+
yield* Effect.sync(() => Object.assign(client, { withTransaction }));
|
|
98
|
+
const db = yield* SQLiteDoDrizzle.makeWithDefaults(drizzleConfig).pipe(Effect.provideContext(services));
|
|
99
|
+
if (migrations !== undefined && "_tag" in migrations) {
|
|
100
|
+
yield* migrations.apply().pipe(Effect.orDie);
|
|
101
|
+
}
|
|
102
|
+
else if (migrations !== undefined) {
|
|
103
|
+
// A migration that cannot apply leaves the instance unusable — there
|
|
104
|
+
// is no meaningful recovery at init, so it dies rather than forcing
|
|
105
|
+
// every caller to handle (or orDie) an error channel.
|
|
106
|
+
yield* migrate(db, {
|
|
107
|
+
migrations: migrations.migrations,
|
|
108
|
+
...(migrations.migrationsTable !== undefined
|
|
109
|
+
? { migrationsTable: migrations.migrationsTable }
|
|
110
|
+
: {}),
|
|
111
|
+
}).pipe(Effect.orDie);
|
|
112
|
+
}
|
|
113
|
+
return db;
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=Cloudflare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cloudflare.js","sourceRoot":"","sources":["../src/Cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AAExF,OAAO,KAAK,cAAc,MAAM,oCAAoC,CAAC;AAErE,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAChE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAyB9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,EAEvE,MAAwC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,kBAAkB,CAAC;IACxC,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IAClC,MAAM,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;IACtD,oEAAoE;IACpE,sEAAsE;IACtE,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC;IACxC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,eAAe,GAAkC,CAAC,IAAI,EAAE,EAAE,CAC9D,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IAC7E,8EAA8E;IAC9E,4EAA4E;IAC5E,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IACrE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,IAAI,CACpE,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAChC,CAAC;IACF,IAAI,UAAU,KAAK,SAAS,IAAI,MAAM,IAAI,UAAU,EAAE,CAAC;QACrD,KAAK,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,qEAAqE;QACrE,oEAAoE;QACpE,sDAAsD;QACtD,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE;YACjB,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,GAAG,CAAC,UAAU,CAAC,eAAe,KAAK,SAAS;gBAC1C,CAAC,CAAC,EAAE,eAAe,EAAE,UAAU,CAAC,eAAe,EAAE;gBACjD,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC,CAAC"}
|
package/lib/D1.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { D1DatabaseSource } from "@alchemy.run/cloudflare/D1/SQL";
|
|
2
|
+
import * as D1Client from "@effect/sql-d1/D1Client";
|
|
3
|
+
import type { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
4
|
+
import type { EffectSQLiteD1Database } from "drizzle-orm/effect-d1";
|
|
5
|
+
import * as SQLiteD1Drizzle from "drizzle-orm/effect-d1";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
/**
|
|
8
|
+
* Open a Drizzle database over a Cloudflare D1 binding using the
|
|
9
|
+
* `drizzle-orm/effect-d1` integration (which drives queries through
|
|
10
|
+
* `@effect/sql-d1`'s `D1Client`).
|
|
11
|
+
*
|
|
12
|
+
* Accepts the client returned by `Cloudflare.D1.QueryDatabase(db)` — or its
|
|
13
|
+
* `raw` effect directly — and returns a chainable Proxy over
|
|
14
|
+
* `EffectSQLiteD1Database` (via `proxyChain`): every property read records a
|
|
15
|
+
* step, every call records args, and the chain is replayed against the
|
|
16
|
+
* resolved drizzle db when it's finally yielded as an Effect. Callers don't
|
|
17
|
+
* need a separate `yield* conn` step:
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const d1 = yield* Cloudflare.D1.QueryDatabase(Db);
|
|
21
|
+
* const db = yield* Drizzle.D1(d1, { relations });
|
|
22
|
+
*
|
|
23
|
+
* fetch: Effect.gen(function* () {
|
|
24
|
+
* const rows = yield* db.select().from(users);
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The client build is deferred until the first query and memoized on the
|
|
29
|
+
* current execution's `Scope` (via {@link makeExecutionMemo}), so the
|
|
30
|
+
* `D1Client` (and its prepared-statement cache) is built at most once per
|
|
31
|
+
* execution — a Worker `fetch`/`queue`/`scheduled` event, a Durable Object
|
|
32
|
+
* call, or a Workflow run — and reused across every query in that execution.
|
|
33
|
+
* Resolving the binding is likewise deferred, so deploy / plan-time
|
|
34
|
+
* invocations (where `WorkerEnvironment` isn't provided) never touch D1.
|
|
35
|
+
*
|
|
36
|
+
* The client is built against that same execution scope, so its finalizer
|
|
37
|
+
* fires when the scope closes — when the request / run settles, not when the
|
|
38
|
+
* Worker's isolate-lifetime init completes. Wrapping queries in a nested
|
|
39
|
+
* `Effect.scoped` narrows both the memo and the client's lifetime to that
|
|
40
|
+
* block: memo key and finalizer target are always the same scope object, so
|
|
41
|
+
* they cannot disagree.
|
|
42
|
+
*
|
|
43
|
+
* @binding
|
|
44
|
+
*/
|
|
45
|
+
export declare const D1: <TRelations extends AnyRelations = EmptyRelations, E = never, R = never>(database: D1DatabaseSource<E, R>, config?: SQLiteD1Drizzle.EffectDrizzleSQLiteD1Config<TRelations>) => Effect.Effect<EffectSQLiteD1Database<TRelations> & {
|
|
46
|
+
$client: D1Client.D1Client;
|
|
47
|
+
}, never, never>;
|
|
48
|
+
//# sourceMappingURL=D1.d.ts.map
|
package/lib/D1.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"D1.d.ts","sourceRoot":"","sources":["../src/D1.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,EAAE,GAAI,UAAU,SAAS,YAAY,GAAG,cAAc,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,YAC7E,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,WACvB,eAAe,CAAC,2BAA2B,CAAC,UAAU,CAAC;aAe/C,QAAQ,CAAC,QAAQ;gBAWjC,CAAC"}
|
package/lib/D1.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as D1Client from "@effect/sql-d1/D1Client";
|
|
2
|
+
import { makeExecutionMemo } from "alchemy/Runtime/ExecutionMemo";
|
|
3
|
+
import { proxyChain } from "alchemy/Util/proxy-chain";
|
|
4
|
+
import * as SQLiteD1Drizzle from "drizzle-orm/effect-d1";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
/**
|
|
8
|
+
* Open a Drizzle database over a Cloudflare D1 binding using the
|
|
9
|
+
* `drizzle-orm/effect-d1` integration (which drives queries through
|
|
10
|
+
* `@effect/sql-d1`'s `D1Client`).
|
|
11
|
+
*
|
|
12
|
+
* Accepts the client returned by `Cloudflare.D1.QueryDatabase(db)` — or its
|
|
13
|
+
* `raw` effect directly — and returns a chainable Proxy over
|
|
14
|
+
* `EffectSQLiteD1Database` (via `proxyChain`): every property read records a
|
|
15
|
+
* step, every call records args, and the chain is replayed against the
|
|
16
|
+
* resolved drizzle db when it's finally yielded as an Effect. Callers don't
|
|
17
|
+
* need a separate `yield* conn` step:
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const d1 = yield* Cloudflare.D1.QueryDatabase(Db);
|
|
21
|
+
* const db = yield* Drizzle.D1(d1, { relations });
|
|
22
|
+
*
|
|
23
|
+
* fetch: Effect.gen(function* () {
|
|
24
|
+
* const rows = yield* db.select().from(users);
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The client build is deferred until the first query and memoized on the
|
|
29
|
+
* current execution's `Scope` (via {@link makeExecutionMemo}), so the
|
|
30
|
+
* `D1Client` (and its prepared-statement cache) is built at most once per
|
|
31
|
+
* execution — a Worker `fetch`/`queue`/`scheduled` event, a Durable Object
|
|
32
|
+
* call, or a Workflow run — and reused across every query in that execution.
|
|
33
|
+
* Resolving the binding is likewise deferred, so deploy / plan-time
|
|
34
|
+
* invocations (where `WorkerEnvironment` isn't provided) never touch D1.
|
|
35
|
+
*
|
|
36
|
+
* The client is built against that same execution scope, so its finalizer
|
|
37
|
+
* fires when the scope closes — when the request / run settles, not when the
|
|
38
|
+
* Worker's isolate-lifetime init completes. Wrapping queries in a nested
|
|
39
|
+
* `Effect.scoped` narrows both the memo and the client's lifetime to that
|
|
40
|
+
* block: memo key and finalizer target are always the same scope object, so
|
|
41
|
+
* they cannot disagree.
|
|
42
|
+
*
|
|
43
|
+
* @binding
|
|
44
|
+
*/
|
|
45
|
+
export const D1 = (database, config) => Effect.map(makeExecutionMemo(Effect.gen(function* () {
|
|
46
|
+
const db = yield* Effect.isEffect(database) ? database : database.raw;
|
|
47
|
+
const d1Ctx = yield* Layer.build(D1Client.layer({ db }));
|
|
48
|
+
return yield* SQLiteD1Drizzle.makeWithDefaults(config ?? {}).pipe(Effect.provideContext(d1Ctx));
|
|
49
|
+
})), (db) => proxyChain(db));
|
|
50
|
+
//# sourceMappingURL=D1.js.map
|
package/lib/D1.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"D1.js","sourceRoot":"","sources":["../src/D1.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAChB,QAAgC,EAChC,MAAgE,EAChE,EAAE,CACF,MAAM,CAAC,GAAG,CACR,iBAAiB,CACf,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;IACtE,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC,CAAC,eAAe,CAAC,gBAAgB,CAC5C,MAAM,IAAK,EAA8D,CAC1E,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC,CACH,EACD,CAAC,EAAE,EAAE,EAAE,CACL,UAAU,CAKR,EAMC,CACF,CACJ,CAAC"}
|