@beignet/provider-db-drizzle 0.0.9

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 (43) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +1046 -0
  3. package/dist/mysql/index.d.ts +254 -0
  4. package/dist/mysql/index.d.ts.map +1 -0
  5. package/dist/mysql/index.js +348 -0
  6. package/dist/mysql/index.js.map +1 -0
  7. package/dist/postgres/index.d.ts +240 -0
  8. package/dist/postgres/index.d.ts.map +1 -0
  9. package/dist/postgres/index.js +296 -0
  10. package/dist/postgres/index.js.map +1 -0
  11. package/dist/shared/idempotency-core.d.ts +71 -0
  12. package/dist/shared/idempotency-core.d.ts.map +1 -0
  13. package/dist/shared/idempotency-core.js +169 -0
  14. package/dist/shared/idempotency-core.js.map +1 -0
  15. package/dist/shared/identifiers.d.ts +20 -0
  16. package/dist/shared/identifiers.d.ts.map +1 -0
  17. package/dist/shared/identifiers.js +27 -0
  18. package/dist/shared/identifiers.js.map +1 -0
  19. package/dist/shared/instrumentation.d.ts +19 -0
  20. package/dist/shared/instrumentation.d.ts.map +1 -0
  21. package/dist/shared/instrumentation.js +41 -0
  22. package/dist/shared/instrumentation.js.map +1 -0
  23. package/dist/shared/outbox-core.d.ts +76 -0
  24. package/dist/shared/outbox-core.d.ts.map +1 -0
  25. package/dist/shared/outbox-core.js +193 -0
  26. package/dist/shared/outbox-core.js.map +1 -0
  27. package/dist/shared/rows.d.ts +84 -0
  28. package/dist/shared/rows.d.ts.map +1 -0
  29. package/dist/shared/rows.js +128 -0
  30. package/dist/shared/rows.js.map +1 -0
  31. package/dist/sqlite/index.d.ts +235 -0
  32. package/dist/sqlite/index.d.ts.map +1 -0
  33. package/dist/sqlite/index.js +293 -0
  34. package/dist/sqlite/index.js.map +1 -0
  35. package/package.json +173 -0
  36. package/src/mysql/index.ts +627 -0
  37. package/src/postgres/index.ts +572 -0
  38. package/src/shared/idempotency-core.ts +280 -0
  39. package/src/shared/identifiers.ts +28 -0
  40. package/src/shared/instrumentation.ts +49 -0
  41. package/src/shared/outbox-core.ts +322 -0
  42. package/src/shared/rows.ts +197 -0
  43. package/src/sqlite/index.ts +547 -0
@@ -0,0 +1,293 @@
1
+ /**
2
+ * @beignet/provider-db-drizzle/sqlite
3
+ *
4
+ * Drizzle ORM SQLite provider, backed by libSQL, that creates a typed
5
+ * database port. Works with local `file:` SQLite databases and with Turso's
6
+ * hosted libSQL service.
7
+ *
8
+ * Configuration:
9
+ * - SQLITE_DB_URL: libSQL database URL (required)
10
+ * - SQLITE_DB_AUTH_TOKEN: auth token for remote connections such as Turso
11
+ * (optional for local dev)
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import * as schema from "@/db/schema";
16
+ * import { createDrizzleSqliteProvider } from "@beignet/provider-db-drizzle/sqlite";
17
+ *
18
+ * export const drizzleSqliteProvider = createDrizzleSqliteProvider({ schema });
19
+ *
20
+ * // In createNextServer:
21
+ * const server = await createNextServer({
22
+ * ports: basePorts,
23
+ * providers: [drizzleSqliteProvider],
24
+ * // ...
25
+ * });
26
+ *
27
+ * // In infra:
28
+ * const todos = createDrizzleTodoRepository(ctx.ports.db.db);
29
+ * ```
30
+ */
31
+ import { createDomainEventRecorder, } from "@beignet/core/ports";
32
+ import { createProvider, createProviderInstrumentation, } from "@beignet/core/providers";
33
+ import { createClient } from "@libsql/client";
34
+ import { sql } from "drizzle-orm";
35
+ import { drizzle } from "drizzle-orm/libsql";
36
+ import { z } from "zod";
37
+ import { createIdempotencyPortCore, formatIdempotencyMutationErrorMessage, } from "../shared/idempotency-core.js";
38
+ import { quoteIdentifier } from "../shared/identifiers.js";
39
+ import { createDbQueryLogger } from "../shared/instrumentation.js";
40
+ import { createOutboxPortCore, } from "../shared/outbox-core.js";
41
+ /**
42
+ * Create a Unit of Work port backed by Drizzle's libSQL transaction API.
43
+ *
44
+ * Beignet does not own your repository interfaces. This helper only
45
+ * provides the transaction boundary and post-commit event flushing; your app
46
+ * decides which transaction-scoped ports to create.
47
+ */
48
+ export function createDrizzleSqliteUnitOfWork(options) {
49
+ return {
50
+ async transaction(work) {
51
+ const events = createDomainEventRecorder();
52
+ const result = await options.db.transaction(async (tx) => {
53
+ const txPorts = options.createTransactionPorts(tx, events);
54
+ return work(txPorts);
55
+ }, options.transactionConfig);
56
+ if (options.eventBus) {
57
+ await events.flush(options.eventBus);
58
+ }
59
+ return result;
60
+ },
61
+ };
62
+ }
63
+ function readRowsAffected(result) {
64
+ const rowsAffected = result.rowsAffected;
65
+ return typeof rowsAffected === "number" ? rowsAffected : undefined;
66
+ }
67
+ function createSqliteExecutor(db, table) {
68
+ return {
69
+ table,
70
+ // SQLite serializes writers; no row-locking clause exists or is needed.
71
+ claimLockSuffix: sql.raw(""),
72
+ insertPrefix: sql.raw("insert or ignore into"),
73
+ insertConflictSuffix: sql.raw(""),
74
+ async rows(query) {
75
+ return db.all(query);
76
+ },
77
+ async row(query) {
78
+ return db.get(query);
79
+ },
80
+ async run(query) {
81
+ return readRowsAffected(await db.run(query));
82
+ },
83
+ withTransaction(fn) {
84
+ if ("transaction" in db && typeof db.transaction === "function") {
85
+ return db.transaction((tx) => fn(createSqliteExecutor(tx, table)));
86
+ }
87
+ return undefined;
88
+ },
89
+ };
90
+ }
91
+ /**
92
+ * Create idempotent SQL statements for the Drizzle SQLite outbox table.
93
+ *
94
+ * Run these during migrations or local setup before using
95
+ * `createDrizzleSqliteOutboxPort(...)`.
96
+ */
97
+ export function createDrizzleSqliteOutboxSetupStatements(options = {}) {
98
+ const tableName = options.tableName ?? "outbox_messages";
99
+ const table = quoteIdentifier(tableName, '"');
100
+ const indexPrefix = tableName.replaceAll(/[^A-Za-z0-9_]/g, "_");
101
+ return [
102
+ `CREATE TABLE IF NOT EXISTS ${table} (
103
+ id text PRIMARY KEY NOT NULL,
104
+ kind text NOT NULL,
105
+ name text NOT NULL,
106
+ payload_json text NOT NULL,
107
+ status text NOT NULL,
108
+ attempts integer DEFAULT 0 NOT NULL,
109
+ max_attempts integer DEFAULT 3 NOT NULL,
110
+ available_at text NOT NULL,
111
+ claimed_at text,
112
+ locked_until text,
113
+ claim_token text,
114
+ delivered_at text,
115
+ last_error_json text,
116
+ created_at text NOT NULL,
117
+ updated_at text NOT NULL
118
+ )`,
119
+ `CREATE INDEX IF NOT EXISTS ${quoteIdentifier(`${indexPrefix}_available_idx`, '"')} ON ${table} (status, available_at)`,
120
+ `CREATE INDEX IF NOT EXISTS ${quoteIdentifier(`${indexPrefix}_locked_idx`, '"')} ON ${table} (status, locked_until)`,
121
+ ];
122
+ }
123
+ /**
124
+ * Create a Beignet outbox port backed by a Drizzle SQLite database.
125
+ *
126
+ * Claiming uses a claim-token lease so concurrent workers can safely compete
127
+ * for eligible messages.
128
+ */
129
+ export function createDrizzleSqliteOutboxPort(db, adapterOptions = {}) {
130
+ const table = sql.raw(quoteIdentifier(adapterOptions.tableName ?? "outbox_messages", '"'));
131
+ const executor = createSqliteExecutor(db, table);
132
+ return createOutboxPortCore(executor, { now: adapterOptions.now });
133
+ }
134
+ /**
135
+ * Error thrown when `complete(...)` or `fail(...)` does not match an
136
+ * in-progress idempotency reservation with the provided fingerprint.
137
+ *
138
+ * This usually signals a workflow bug: the reservation was never made, was
139
+ * already completed or released, expired and was cleaned up, or the caller
140
+ * passed a different fingerprint than the one used to reserve.
141
+ */
142
+ export class DrizzleSqliteIdempotencyMutationError extends Error {
143
+ action;
144
+ namespace;
145
+ key;
146
+ scopeKey;
147
+ constructor(args) {
148
+ super(formatIdempotencyMutationErrorMessage(args));
149
+ this.name = "DrizzleSqliteIdempotencyMutationError";
150
+ this.action = args.action;
151
+ this.namespace = args.namespace;
152
+ this.key = args.key;
153
+ this.scopeKey = args.scopeKey;
154
+ }
155
+ }
156
+ /**
157
+ * Create idempotent SQL statements for the Drizzle SQLite idempotency table.
158
+ *
159
+ * Run these during migrations or local setup before using
160
+ * `createDrizzleSqliteIdempotencyPort(...)`.
161
+ */
162
+ export function createDrizzleSqliteIdempotencySetupStatements(options = {}) {
163
+ const tableName = options.tableName ?? "idempotency_records";
164
+ const table = quoteIdentifier(tableName, '"');
165
+ const indexPrefix = tableName.replaceAll(/[^A-Za-z0-9_]/g, "_");
166
+ return [
167
+ `CREATE TABLE IF NOT EXISTS ${table} (
168
+ storage_key text PRIMARY KEY NOT NULL,
169
+ namespace text NOT NULL,
170
+ idempotency_key text NOT NULL,
171
+ scope_key text NOT NULL,
172
+ fingerprint text NOT NULL,
173
+ status text NOT NULL,
174
+ result_json text,
175
+ reserved_at text NOT NULL,
176
+ completed_at text,
177
+ expires_at text,
178
+ updated_at text NOT NULL
179
+ )`,
180
+ `CREATE INDEX IF NOT EXISTS ${quoteIdentifier(`${indexPrefix}_lookup_idx`, '"')} ON ${table} (namespace, scope_key, idempotency_key)`,
181
+ `CREATE INDEX IF NOT EXISTS ${quoteIdentifier(`${indexPrefix}_expires_idx`, '"')} ON ${table} (expires_at)`,
182
+ ];
183
+ }
184
+ /**
185
+ * Create a Beignet idempotency port backed by a Drizzle SQLite database.
186
+ *
187
+ * The port accepts both the root Drizzle database and transaction clients, so
188
+ * applications can expose root idempotency for ordinary retry-safe commands and
189
+ * transaction-scoped idempotency from Unit of Work.
190
+ */
191
+ export function createDrizzleSqliteIdempotencyPort(db, adapterOptions = {}) {
192
+ const table = sql.raw(quoteIdentifier(adapterOptions.tableName ?? "idempotency_records", '"'));
193
+ const executor = createSqliteExecutor(db, table);
194
+ return createIdempotencyPortCore(executor, { now: adapterOptions.now }, DrizzleSqliteIdempotencyMutationError);
195
+ }
196
+ const SQLITE_DB_URL_PREFIXES = [
197
+ "libsql://",
198
+ "file:",
199
+ "http://",
200
+ "https://",
201
+ "ws://",
202
+ "wss://",
203
+ ];
204
+ /**
205
+ * Configuration schema for the Drizzle SQLite provider.
206
+ * Validates environment variables with SQLITE_ prefix.
207
+ */
208
+ const SqliteConfigSchema = z.object({
209
+ /**
210
+ * libSQL database URL.
211
+ * Accepts every URL scheme @libsql/client accepts: "libsql://" and "file:"
212
+ * plus "http(s)://" and "ws(s)://" for local sqld instances.
213
+ * Example: "libsql://<org>-<db>.turso.io" or "file:local.db"
214
+ */
215
+ DB_URL: z
216
+ .string()
217
+ .min(1)
218
+ .refine((val) => SQLITE_DB_URL_PREFIXES.some((prefix) => val.startsWith(prefix)), {
219
+ message: 'DB_URL must start with "libsql://", "file:", "http://", "https://", "ws://", or "wss://" (e.g., "libsql://<org>-<db>.turso.io", "file:local.db", or "http://127.0.0.1:8080")',
220
+ }),
221
+ /**
222
+ * Auth token for remote libSQL connections (optional for local dev).
223
+ * Required when connecting to Turso's hosted libSQL service.
224
+ */
225
+ DB_AUTH_TOKEN: z.string().optional(),
226
+ });
227
+ /**
228
+ * Create a Drizzle SQLite provider factory.
229
+ *
230
+ * This factory creates a service provider that:
231
+ * - Uses libSQL via @libsql/client, for local `file:` SQLite databases and
232
+ * Turso's hosted libSQL service
233
+ * - Uses Drizzle ORM via drizzle-orm/libsql
234
+ * - Exposes a typed DbPort<TSchema> on ports
235
+ * - Uses SQLITE_-prefixed env vars for connection config
236
+ *
237
+ * @template TSchema - The Drizzle schema type (inferred from the schema parameter)
238
+ * @param options - Configuration options including the schema
239
+ * @returns A service provider that can be used with createNextServer
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * import * as schema from "@/db/schema";
244
+ * import { createDrizzleSqliteProvider } from "@beignet/provider-db-drizzle/sqlite";
245
+ *
246
+ * export const drizzleSqliteProvider = createDrizzleSqliteProvider({ schema });
247
+ * ```
248
+ */
249
+ export function createDrizzleSqliteProvider(options) {
250
+ const { schema, portName = "db" } = options;
251
+ return createProvider({
252
+ name: "drizzle-sqlite",
253
+ config: {
254
+ schema: SqliteConfigSchema,
255
+ envPrefix: "SQLITE_",
256
+ },
257
+ async setup({ ports, config }) {
258
+ if (!config) {
259
+ throw new Error("[drizzleSqliteProvider] Missing config. Set SQLITE_DB_URL (and optional SQLITE_DB_AUTH_TOKEN).");
260
+ }
261
+ // 1. Create libSQL client
262
+ const client = createClient({
263
+ url: config.DB_URL,
264
+ authToken: config.DB_AUTH_TOKEN,
265
+ });
266
+ const instrumentation = createProviderInstrumentation(ports, {
267
+ providerName: "drizzle-sqlite",
268
+ watcher: "db",
269
+ });
270
+ const logger = createDbQueryLogger(instrumentation, portName);
271
+ // 2. Create typed Drizzle instance
272
+ const db = logger
273
+ ? drizzle(client, { schema, logger })
274
+ : drizzle(client, { schema });
275
+ // 3. Build a typed DbPort
276
+ const dbPort = { db, client };
277
+ return {
278
+ ports: { [portName]: dbPort },
279
+ async stop() {
280
+ // Gracefully close the database connection
281
+ try {
282
+ await dbPort.client.close();
283
+ }
284
+ catch (error) {
285
+ // Log error but don't throw - we're shutting down anyway
286
+ console.error("[drizzleSqliteProvider] Error closing database connection:", error);
287
+ }
288
+ },
289
+ };
290
+ },
291
+ });
292
+ }
293
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sqlite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,OAAO,EAEL,yBAAyB,GAI1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAA6C,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAuB,MAAM,oBAAoB,CAAC;AAGlE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,qCAAqC,GAEtC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;A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b,gGAAgG,CACjG,CAAC;YACJ,CAAC;YAED,0BAA0B;YAC1B,MAAM,MAAM,GAAW,YAAY,CAAC;gBAClC,GAAG,EAAE,MAAM,CAAC,MAAM;gBAClB,SAAS,EAAE,MAAM,CAAC,aAAa;aAChC,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,6BAA6B,CAAC,KAAK,EAAE;gBAC3D,YAAY,EAAE,gBAAgB;gBAC9B,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,mBAAmB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;YAE9D,mCAAmC;YACnC,MAAM,EAAE,GAA4B,MAAM;gBACxC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;gBACrC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;YAEhC,0BAA0B;YAC1B,MAAM,MAAM,GAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;YAE/C,OAAO;gBACL,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAuC;gBAClE,KAAK,CAAC,IAAI;oBACR,2CAA2C;oBAC3C,IAAI,CAAC;wBACH,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;oBAC9B,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,yDAAyD;wBACzD,OAAO,CAAC,KAAK,CACX,4DAA4D,EAC5D,KAAK,CACN,CAAC;oBACJ,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,173 @@
1
+ {
2
+ "name": "@beignet/provider-db-drizzle",
3
+ "version": "0.0.9",
4
+ "type": "module",
5
+ "description": "Drizzle ORM database providers for Beignet — typed DbPort, unit of work, outbox, and idempotency for SQLite (libSQL/Turso), Postgres, and MySQL.",
6
+ "exports": {
7
+ "./sqlite": {
8
+ "types": "./dist/sqlite/index.d.ts",
9
+ "default": "./dist/sqlite/index.js"
10
+ },
11
+ "./postgres": {
12
+ "types": "./dist/postgres/index.d.ts",
13
+ "default": "./dist/postgres/index.js"
14
+ },
15
+ "./mysql": {
16
+ "types": "./dist/mysql/index.d.ts",
17
+ "default": "./dist/mysql/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "src",
23
+ "!src/**/*.test.ts",
24
+ "!src/**/*.test.tsx",
25
+ "!src/**/*.test-d.ts",
26
+ "README.md",
27
+ "CHANGELOG.md"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "dev": "tsc --watch",
32
+ "clean": "rm -rf dist coverage .turbo",
33
+ "test": "bun test",
34
+ "test:coverage": "bun test --coverage",
35
+ "lint": "biome check ."
36
+ },
37
+ "keywords": [
38
+ "beignet",
39
+ "drizzle",
40
+ "sqlite",
41
+ "libsql",
42
+ "turso",
43
+ "postgres",
44
+ "pg",
45
+ "mysql",
46
+ "mysql2",
47
+ "provider",
48
+ "database",
49
+ "ports",
50
+ "hex",
51
+ "hexagonal"
52
+ ],
53
+ "license": "MIT",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/taylorbryant/beignet.git",
57
+ "directory": "packages/provider-db-drizzle"
58
+ },
59
+ "author": "Taylor Bryant",
60
+ "homepage": "https://github.com/taylorbryant/beignet#readme",
61
+ "bugs": "https://github.com/taylorbryant/beignet/issues",
62
+ "sideEffects": false,
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "engines": {
67
+ "node": ">=18.0.0"
68
+ },
69
+ "peerDependencies": {
70
+ "@beignet/core": ">=0.0.3 <1.0.0",
71
+ "@libsql/client": "^0.6.0 || ^0.14.0 || ^0.15.0",
72
+ "drizzle-orm": "^0.45.2",
73
+ "mysql2": ">=3.6.0",
74
+ "pg": ">=8.11.0"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "@libsql/client": {
78
+ "optional": true
79
+ },
80
+ "mysql2": {
81
+ "optional": true
82
+ },
83
+ "pg": {
84
+ "optional": true
85
+ }
86
+ },
87
+ "dependencies": {
88
+ "zod": "^4.0.0"
89
+ },
90
+ "devDependencies": {
91
+ "@beignet/devtools": "*",
92
+ "@electric-sql/pglite": "^0.5.2",
93
+ "@libsql/client": "^0.14.0",
94
+ "@types/bun": "^1.3.13",
95
+ "@types/node": "^20.10.0",
96
+ "@types/pg": "^8.11.0",
97
+ "drizzle-orm": "^0.45.2",
98
+ "mysql2": "^3.12.0",
99
+ "pg": "^8.13.0",
100
+ "typescript": "^5.3.0"
101
+ },
102
+ "beignet": {
103
+ "provider": {
104
+ "displayName": "Drizzle database provider",
105
+ "ports": [
106
+ "db"
107
+ ],
108
+ "env": [
109
+ "SQLITE_DB_URL",
110
+ "SQLITE_DB_AUTH_TOKEN",
111
+ "POSTGRES_DB_URL",
112
+ "MYSQL_DB_URL"
113
+ ],
114
+ "watchers": [
115
+ "db"
116
+ ],
117
+ "variants": [
118
+ {
119
+ "name": "sqlite",
120
+ "displayName": "Drizzle SQLite provider",
121
+ "env": [
122
+ "SQLITE_DB_URL",
123
+ "SQLITE_DB_AUTH_TOKEN"
124
+ ],
125
+ "requiredEnv": [
126
+ "SQLITE_DB_URL"
127
+ ],
128
+ "registration": {
129
+ "required": true,
130
+ "tokens": [
131
+ "drizzleSqliteProvider",
132
+ "createDrizzleSqliteProvider"
133
+ ]
134
+ }
135
+ },
136
+ {
137
+ "name": "postgres",
138
+ "displayName": "Drizzle Postgres provider",
139
+ "env": [
140
+ "POSTGRES_DB_URL"
141
+ ],
142
+ "requiredEnv": [
143
+ "POSTGRES_DB_URL"
144
+ ],
145
+ "registration": {
146
+ "required": true,
147
+ "tokens": [
148
+ "drizzlePostgresProvider",
149
+ "createDrizzlePostgresProvider"
150
+ ]
151
+ }
152
+ },
153
+ {
154
+ "name": "mysql",
155
+ "displayName": "Drizzle MySQL provider",
156
+ "env": [
157
+ "MYSQL_DB_URL"
158
+ ],
159
+ "requiredEnv": [
160
+ "MYSQL_DB_URL"
161
+ ],
162
+ "registration": {
163
+ "required": true,
164
+ "tokens": [
165
+ "drizzleMysqlProvider",
166
+ "createDrizzleMysqlProvider"
167
+ ]
168
+ }
169
+ }
170
+ ]
171
+ }
172
+ }
173
+ }