nitro-drizzle 0.0.0 → 0.2.2
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 +21 -0
- package/README.md +247 -0
- package/dist/config/defineConfig.d.mts +410 -0
- package/dist/config/defineConfig.mjs +34 -0
- package/dist/config/defineConfig.mjs.map +1 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +2 -0
- package/dist/context/internal/async.mjs +15 -0
- package/dist/context/internal/async.mjs.map +1 -0
- package/dist/context/internal/config.mjs +31 -0
- package/dist/context/internal/config.mjs.map +1 -0
- package/dist/context/internal/fs.mjs +15 -0
- package/dist/context/internal/fs.mjs.map +1 -0
- package/dist/context/internal/logger.mjs +20 -0
- package/dist/context/internal/logger.mjs.map +1 -0
- package/dist/context/internal/templates.mjs +40 -0
- package/dist/context/internal/templates.mjs.map +1 -0
- package/dist/context/internal/virtual.mjs +71 -0
- package/dist/context/internal/virtual.mjs.map +1 -0
- package/dist/context.d.mts +113 -0
- package/dist/context.mjs +78 -0
- package/dist/context.mjs.map +1 -0
- package/dist/dialects/index.d.mts +39 -0
- package/dist/dialects/index.mjs +1 -0
- package/dist/dialects/mysql.d.mts +30 -0
- package/dist/dialects/mysql.mjs +30 -0
- package/dist/dialects/mysql.mjs.map +1 -0
- package/dist/dialects/postgresql.d.mts +29 -0
- package/dist/dialects/postgresql.mjs +29 -0
- package/dist/dialects/postgresql.mjs.map +1 -0
- package/dist/dialects/sqlite.d.mts +29 -0
- package/dist/dialects/sqlite.mjs +29 -0
- package/dist/dialects/sqlite.mjs.map +1 -0
- package/dist/drivers/d1-http.d.mts +41 -0
- package/dist/drivers/d1-http.mjs +105 -0
- package/dist/drivers/d1-http.mjs.map +1 -0
- package/dist/drivers/d1.d.mts +26 -0
- package/dist/drivers/d1.mjs +52 -0
- package/dist/drivers/d1.mjs.map +1 -0
- package/dist/drivers/db0.d.mts +20 -0
- package/dist/drivers/db0.mjs +27 -0
- package/dist/drivers/db0.mjs.map +1 -0
- package/dist/drivers/index.d.mts +35 -0
- package/dist/drivers/index.mjs +14 -0
- package/dist/drivers/index.mjs.map +1 -0
- package/dist/drivers/internal/d1-dialect.mjs +41 -0
- package/dist/drivers/internal/d1-dialect.mjs.map +1 -0
- package/dist/drivers/internal/sql.mjs +6 -0
- package/dist/drivers/internal/sql.mjs.map +1 -0
- package/dist/drivers/mysql.d.mts +27 -0
- package/dist/drivers/mysql.mjs +32 -0
- package/dist/drivers/mysql.mjs.map +1 -0
- package/dist/drivers/pglite.d.mts +29 -0
- package/dist/drivers/pglite.mjs +29 -0
- package/dist/drivers/pglite.mjs.map +1 -0
- package/dist/drivers/postgresql.d.mts +27 -0
- package/dist/drivers/postgresql.mjs +30 -0
- package/dist/drivers/postgresql.mjs.map +1 -0
- package/dist/drivers/sqlite.d.mts +28 -0
- package/dist/drivers/sqlite.mjs +30 -0
- package/dist/drivers/sqlite.mjs.map +1 -0
- package/dist/meta.d.mts +8 -0
- package/dist/meta.mjs +9 -0
- package/dist/meta.mjs.map +1 -0
- package/dist/migrations/internal/migrate.d.mts +16 -0
- package/dist/migrations/internal/migrate.mjs +33 -0
- package/dist/migrations/internal/migrate.mjs.map +1 -0
- package/dist/migrations/migrate.d.mts +16 -0
- package/dist/migrations/migrate.mjs +23 -0
- package/dist/migrations/migrate.mjs.map +1 -0
- package/dist/migrations/task.d.mts +7 -0
- package/dist/migrations/task.mjs +11 -0
- package/dist/migrations/task.mjs.map +1 -0
- package/dist/migrations/useMigrations.d.mts +46 -0
- package/dist/migrations/useMigrations.mjs +57 -0
- package/dist/migrations/useMigrations.mjs.map +1 -0
- package/dist/migrations.d.mts +4 -0
- package/dist/migrations.mjs +3 -0
- package/dist/module/internal/assets.d.mts +12 -0
- package/dist/module/internal/assets.mjs +21 -0
- package/dist/module/internal/assets.mjs.map +1 -0
- package/dist/module/internal/externals.mjs +19 -0
- package/dist/module/internal/externals.mjs.map +1 -0
- package/dist/module/internal/fs.mjs +11 -0
- package/dist/module/internal/fs.mjs.map +1 -0
- package/dist/module/internal/path.mjs +11 -0
- package/dist/module/internal/path.mjs.map +1 -0
- package/dist/module/internal/reload.mjs +17 -0
- package/dist/module/internal/reload.mjs.map +1 -0
- package/dist/module/internal/resolver.mjs +27 -0
- package/dist/module/internal/resolver.mjs.map +1 -0
- package/dist/module/internal/rollup.mjs +8 -0
- package/dist/module/internal/rollup.mjs.map +1 -0
- package/dist/module/internal/types.mjs +39 -0
- package/dist/module/internal/types.mjs.map +1 -0
- package/dist/module/internal/virtual.mjs +23 -0
- package/dist/module/internal/virtual.mjs.map +1 -0
- package/dist/module.d.mts +37 -0
- package/dist/module.mjs +82 -0
- package/dist/module.mjs.map +1 -0
- package/dist/plugins/init.d.mts +24 -0
- package/dist/plugins/init.mjs +33 -0
- package/dist/plugins/init.mjs.map +1 -0
- package/dist/plugins/migrate.d.mts +22 -0
- package/dist/plugins/migrate.mjs +25 -0
- package/dist/plugins/migrate.mjs.map +1 -0
- package/dist/runtime/internal/config.mjs +24 -0
- package/dist/runtime/internal/config.mjs.map +1 -0
- package/dist/runtime/internal/createDatasource.mjs +15 -0
- package/dist/runtime/internal/createDatasource.mjs.map +1 -0
- package/dist/runtime/useDatasource.d.mts +19 -0
- package/dist/runtime/useDatasource.mjs +35 -0
- package/dist/runtime/useDatasource.mjs.map +1 -0
- package/dist/runtime.d.mts +79 -0
- package/dist/runtime.mjs +2 -0
- package/dist/shared.d.mts +12 -0
- package/dist/shared.mjs +1 -0
- package/dist/utils/usePrimaryKey.d.mts +14 -0
- package/dist/utils/usePrimaryKey.mjs +19 -0
- package/dist/utils/usePrimaryKey.mjs.map +1 -0
- package/dist/utils.d.mts +2 -0
- package/dist/utils.mjs +2 -0
- package/package.json +100 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexei Myshkouski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# nitro-drizzle
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/nitro-drizzle)
|
|
4
|
+
[](https://github.com/Myshkouski/nitro-drizzle/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/Myshkouski/nitro-drizzle/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
`nitro-drizzle` is a powerful module designed to seamlessly integrate the [Drizzle ORM](https://orm.drizzle.team/) with your [Nitro](https://nitro.unjs.io/) applications. It simplifies database management, schema definition, and migrations, allowing you to build robust and scalable backend services with ease.
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **Datasource Management**: Easily configure and manage multiple Drizzle ORM datasources within your Nitro project.
|
|
12
|
+
- **Multiple Database Drivers**: Support for various database drivers including SQLite (with `better-sqlite3`), PostgreSQL (with `pglite`), MySQL (with `mysql2`), and Cloudflare D1.
|
|
13
|
+
- **Automatic Migrations**: Configure automatic database migrations on application initialization.
|
|
14
|
+
- **Type-Safe Schemas**: Leverage Drizzle ORM's type-safe schemas for a better development experience.
|
|
15
|
+
- **Nitro Task Integration**: Run Drizzle migrations as Nitro tasks.
|
|
16
|
+
- **Hot Reloading**: Seamless integration with Nitro's development server for hot reloading of datasource configurations and schemas.
|
|
17
|
+
|
|
18
|
+
## 🚀 Installation
|
|
19
|
+
|
|
20
|
+
To get started, install the `nitro-drizzle` module and its peer dependencies:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install nitro-drizzle drizzle-orm drizzle-kit
|
|
24
|
+
# Install database drivers based on your needs:
|
|
25
|
+
# SQLite:
|
|
26
|
+
npm install better-sqlite3
|
|
27
|
+
# PostgreSQL (with pglite):
|
|
28
|
+
npm install @electric-sql/pglite
|
|
29
|
+
# MySQL:
|
|
30
|
+
npm install mysql2
|
|
31
|
+
# Cloudflare D1: (nitro-drizzle will use the `wrangler d1 bindings` for a local development, for production you can use `@cloudflare/workers-types` and connect directly to the database)
|
|
32
|
+
npm install @cloudflare/workers-types
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 📚 Usage
|
|
36
|
+
|
|
37
|
+
### 1. Configure Nitro Module
|
|
38
|
+
|
|
39
|
+
Add `nitro-drizzle/module` to your `nitro.config.ts` modules:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// nitro.config.ts
|
|
43
|
+
import { defineNitroConfig } from "nitropack/config";
|
|
44
|
+
|
|
45
|
+
export default defineNitroConfig({
|
|
46
|
+
modules: ["nitro-drizzle/module"],
|
|
47
|
+
drizzle: {
|
|
48
|
+
datasources: {
|
|
49
|
+
foo: { connector: "sqlite" },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
See [ModuleOptions](src/module/index.ts) for all available options.
|
|
56
|
+
|
|
57
|
+
### 2. Define Drizzle Config and Schema
|
|
58
|
+
|
|
59
|
+
Create your Drizzle configuration files and schemas in the `baseDir` specified in `nitro.config.ts` (e.g., `server/drizzle/foo/drizzle-sqlite.config.ts` and `server/drizzle/foo/sqlite/schema.ts`).
|
|
60
|
+
|
|
61
|
+
#### Example: `server/drizzle/foo/drizzle-sqlite.config.ts`
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { defineConfig } from "nitro-drizzle/config";
|
|
65
|
+
|
|
66
|
+
export default defineConfig(
|
|
67
|
+
{
|
|
68
|
+
strict: true,
|
|
69
|
+
dialect: "sqlite",
|
|
70
|
+
out: "./sqlite/migrations", // Migration output directory
|
|
71
|
+
schema: ["./sqlite/schema.ts"], // Path to your schema files
|
|
72
|
+
migrations: {
|
|
73
|
+
table: "drizzle_migrations", // Table to track migrations
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
import.meta.url, // Pass import.meta.url for correct path resolution
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Example: `server/drizzle/foo/sqlite/schema.ts`
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { sqliteTable, integer, text } from "drizzle-orm/sqlite-core";
|
|
84
|
+
|
|
85
|
+
export const users = sqliteTable("users", {
|
|
86
|
+
id: integer("id").primaryKey(),
|
|
87
|
+
name: text("name").notNull(),
|
|
88
|
+
email: text("email").notNull().unique(),
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Example: `server/drizzle/bar/drizzle-pglite.config.ts`
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { defineConfig } from "nitro-drizzle/config";
|
|
96
|
+
|
|
97
|
+
export default defineConfig(
|
|
98
|
+
{
|
|
99
|
+
dialect: "postgresql",
|
|
100
|
+
driver: "pglite",
|
|
101
|
+
out: "./postgres/migrations",
|
|
102
|
+
schema: ["./postgres/schema.ts"],
|
|
103
|
+
migrations: {
|
|
104
|
+
table: "drizzle_migrations",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
import.meta.url,
|
|
108
|
+
);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Example: `server/drizzle/bar/postgres/schema.ts`
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { pgTable, serial, text } from "drizzle-orm/pg-core";
|
|
115
|
+
|
|
116
|
+
export const products = pgTable("products", {
|
|
117
|
+
id: serial("id").primaryKey(),
|
|
118
|
+
name: text("name").notNull(),
|
|
119
|
+
description: text("description"),
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 3. Use Datasources in API Routes
|
|
124
|
+
|
|
125
|
+
You can access your configured datasources in your Nitro API routes using `useDatasource`.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
// server/routes/index.ts
|
|
129
|
+
import { eventHandler } from "h3";
|
|
130
|
+
import { useDatasource } from "nitro-drizzle/runtime";
|
|
131
|
+
|
|
132
|
+
export default eventHandler(async () => {
|
|
133
|
+
const fooDatasource = await useDatasource("foo"); // Access the 'foo' datasource
|
|
134
|
+
const barDatasource = await useDatasource("bar"); // Access the 'bar' datasource
|
|
135
|
+
|
|
136
|
+
await Promise.all([fooDatasource.waitReady(), barDatasource.waitReady()]);
|
|
137
|
+
|
|
138
|
+
// Example usage with 'foo' (SQLite)
|
|
139
|
+
const newUsers = await fooDatasource.database
|
|
140
|
+
.insert(fooDatasource.schema.users)
|
|
141
|
+
.values([
|
|
142
|
+
{ name: "Alice", email: "alice@example.com" },
|
|
143
|
+
{ name: "Bob", email: "bob@example.com" },
|
|
144
|
+
])
|
|
145
|
+
.returning()
|
|
146
|
+
.all();
|
|
147
|
+
|
|
148
|
+
// Example usage with 'bar' (PostgreSQL with pglite)
|
|
149
|
+
const newProducts = await barDatasource.database
|
|
150
|
+
.insert(barDatasource.schema.products)
|
|
151
|
+
.values([
|
|
152
|
+
{ name: "Laptop", description: "Powerful laptop" },
|
|
153
|
+
{ name: "Mouse", description: "Wireless mouse" },
|
|
154
|
+
])
|
|
155
|
+
.returning()
|
|
156
|
+
.all();
|
|
157
|
+
|
|
158
|
+
return { newUsers, newProducts };
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 4. Run Migrations
|
|
163
|
+
|
|
164
|
+
If you enabled Nitro tasks in `nitro.config.ts`, you can run migrations via the Nitro CLI:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npx nitro task drizzle:migrate
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 📖 API Documentation
|
|
171
|
+
|
|
172
|
+
### `useDatasource(name: string, options?: UseDatasourceOptions)`
|
|
173
|
+
|
|
174
|
+
- **Purpose**: Retrieves a Drizzle ORM datasource instance by its configured name. Caches the datasource for reuse.
|
|
175
|
+
- **Parameters**:
|
|
176
|
+
- `name`: The unique name of the datasource as defined in `nitro.config.ts`.
|
|
177
|
+
- `options` (optional):
|
|
178
|
+
- `autoClose`: `boolean` (default: `true`) - Whether to automatically close the datasource when the Nitro app closes.
|
|
179
|
+
- **Returns**: A `Promise` that resolves to the Drizzle ORM datasource instance, including `database` (the Drizzle client) and `schema` (your defined schema).
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { useDatasource } from "nitro-drizzle/runtime";
|
|
183
|
+
|
|
184
|
+
const myDatasource = await useDatasource("myDatasourceName");
|
|
185
|
+
const result = await myDatasource.database.select().from(myDatasource.schema.myTable).all();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `defineConfig(config: DrizzleConfig, filename: string)`
|
|
189
|
+
|
|
190
|
+
- **Purpose**: Helper function to define Drizzle configuration files (`drizzle.config.ts`) that are compatible with both `nitro-drizzle/module` and `drizzle-kit`. It handles path resolution automatically.
|
|
191
|
+
- **Parameters**:
|
|
192
|
+
- `config`: Your DrizzleKit configuration object.
|
|
193
|
+
- `filename`: Pass `import.meta.url` as the `filename` for correct relative path resolution.
|
|
194
|
+
- **Returns**: A DrizzleKit compatible configuration object.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
// drizzle.config.ts
|
|
198
|
+
import { defineConfig } from "nitro-drizzle/config";
|
|
199
|
+
|
|
200
|
+
export default defineConfig(
|
|
201
|
+
{
|
|
202
|
+
dialect: "sqlite",
|
|
203
|
+
out: "./migrations",
|
|
204
|
+
schema: ["./schema.ts"],
|
|
205
|
+
},
|
|
206
|
+
import.meta.url,
|
|
207
|
+
);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### `migrate(name: string)`
|
|
211
|
+
|
|
212
|
+
- **Purpose**: Runs Drizzle migrations for a specific datasource. This is typically used internally by the Nitro task, but can be called directly if needed.
|
|
213
|
+
- **Parameters**:
|
|
214
|
+
- `name`: The name of the datasource to migrate.
|
|
215
|
+
- **Returns**: A `Promise` that resolves to a `MigrationResult` object.
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
import { migrate } from "nitro-drizzle/migrations";
|
|
219
|
+
|
|
220
|
+
await migrate("myDatasourceName");
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## ⚙️ Development
|
|
224
|
+
|
|
225
|
+
- Install dependencies:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
pnpm install
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- Run the unit tests:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
pnpm test
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- Build the library:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
pnpm build
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
- Run the playground in development mode:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
pnpm playground
|
|
247
|
+
```
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { Config } from "drizzle-kit";
|
|
2
|
+
|
|
3
|
+
//#region src/config/defineConfig.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Define Drizzle config compatible with both 'nitro-drizzle/module' and 'drizzle-kit' packages.
|
|
6
|
+
*
|
|
7
|
+
* @param config
|
|
8
|
+
* @param dirname
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
declare function defineConfig(config: Config, filename: string): {
|
|
12
|
+
dialect: "gel" | "mysql" | "postgresql" | "singlestore" | "sqlite" | "turso";
|
|
13
|
+
breakpoints?: boolean;
|
|
14
|
+
tablesFilter?: string | string[];
|
|
15
|
+
extensionsFilters?: 'postgis'[];
|
|
16
|
+
schemaFilter?: string | string[];
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
strict?: boolean;
|
|
19
|
+
casing?: 'camelCase' | 'snake_case';
|
|
20
|
+
migrations?: {
|
|
21
|
+
table?: string;
|
|
22
|
+
schema?: string;
|
|
23
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
24
|
+
};
|
|
25
|
+
introspect?: {
|
|
26
|
+
casing: 'camel' | 'preserve';
|
|
27
|
+
};
|
|
28
|
+
entities?: {
|
|
29
|
+
roles?: boolean | {
|
|
30
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
31
|
+
exclude?: string[];
|
|
32
|
+
include?: string[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
schema: string | string[] | undefined;
|
|
36
|
+
out: string | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
dialect: "turso";
|
|
39
|
+
breakpoints?: boolean;
|
|
40
|
+
tablesFilter?: string | string[];
|
|
41
|
+
extensionsFilters?: 'postgis'[];
|
|
42
|
+
schemaFilter?: string | string[];
|
|
43
|
+
verbose?: boolean;
|
|
44
|
+
strict?: boolean;
|
|
45
|
+
casing?: 'camelCase' | 'snake_case';
|
|
46
|
+
migrations?: {
|
|
47
|
+
table?: string;
|
|
48
|
+
schema?: string;
|
|
49
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
50
|
+
};
|
|
51
|
+
introspect?: {
|
|
52
|
+
casing: 'camel' | 'preserve';
|
|
53
|
+
};
|
|
54
|
+
entities?: {
|
|
55
|
+
roles?: boolean | {
|
|
56
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
57
|
+
exclude?: string[];
|
|
58
|
+
include?: string[];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
dbCredentials: {
|
|
62
|
+
url: string;
|
|
63
|
+
authToken?: string;
|
|
64
|
+
};
|
|
65
|
+
schema: string | string[] | undefined;
|
|
66
|
+
out: string | undefined;
|
|
67
|
+
} | {
|
|
68
|
+
dialect: "sqlite";
|
|
69
|
+
breakpoints?: boolean;
|
|
70
|
+
tablesFilter?: string | string[];
|
|
71
|
+
extensionsFilters?: 'postgis'[];
|
|
72
|
+
schemaFilter?: string | string[];
|
|
73
|
+
verbose?: boolean;
|
|
74
|
+
strict?: boolean;
|
|
75
|
+
casing?: 'camelCase' | 'snake_case';
|
|
76
|
+
migrations?: {
|
|
77
|
+
table?: string;
|
|
78
|
+
schema?: string;
|
|
79
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
80
|
+
};
|
|
81
|
+
introspect?: {
|
|
82
|
+
casing: 'camel' | 'preserve';
|
|
83
|
+
};
|
|
84
|
+
entities?: {
|
|
85
|
+
roles?: boolean | {
|
|
86
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
87
|
+
exclude?: string[];
|
|
88
|
+
include?: string[];
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
dbCredentials: {
|
|
92
|
+
url: string;
|
|
93
|
+
};
|
|
94
|
+
schema: string | string[] | undefined;
|
|
95
|
+
out: string | undefined;
|
|
96
|
+
} | {
|
|
97
|
+
dialect: "postgresql";
|
|
98
|
+
breakpoints?: boolean;
|
|
99
|
+
tablesFilter?: string | string[];
|
|
100
|
+
extensionsFilters?: 'postgis'[];
|
|
101
|
+
schemaFilter?: string | string[];
|
|
102
|
+
verbose?: boolean;
|
|
103
|
+
strict?: boolean;
|
|
104
|
+
casing?: 'camelCase' | 'snake_case';
|
|
105
|
+
migrations?: {
|
|
106
|
+
table?: string;
|
|
107
|
+
schema?: string;
|
|
108
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
109
|
+
};
|
|
110
|
+
introspect?: {
|
|
111
|
+
casing: 'camel' | 'preserve';
|
|
112
|
+
};
|
|
113
|
+
entities?: {
|
|
114
|
+
roles?: boolean | {
|
|
115
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
116
|
+
exclude?: string[];
|
|
117
|
+
include?: string[];
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
dbCredentials: ({
|
|
121
|
+
host: string;
|
|
122
|
+
port?: number;
|
|
123
|
+
user?: string;
|
|
124
|
+
password?: string;
|
|
125
|
+
database: string;
|
|
126
|
+
ssl?: boolean | 'require' | 'allow' | 'prefer' | 'verify-full' | import("node:tls").ConnectionOptions;
|
|
127
|
+
} & {}) | {
|
|
128
|
+
url: string;
|
|
129
|
+
};
|
|
130
|
+
schema: string | string[] | undefined;
|
|
131
|
+
out: string | undefined;
|
|
132
|
+
} | {
|
|
133
|
+
dialect: "postgresql";
|
|
134
|
+
breakpoints?: boolean;
|
|
135
|
+
tablesFilter?: string | string[];
|
|
136
|
+
extensionsFilters?: 'postgis'[];
|
|
137
|
+
schemaFilter?: string | string[];
|
|
138
|
+
verbose?: boolean;
|
|
139
|
+
strict?: boolean;
|
|
140
|
+
casing?: 'camelCase' | 'snake_case';
|
|
141
|
+
migrations?: {
|
|
142
|
+
table?: string;
|
|
143
|
+
schema?: string;
|
|
144
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
145
|
+
};
|
|
146
|
+
introspect?: {
|
|
147
|
+
casing: 'camel' | 'preserve';
|
|
148
|
+
};
|
|
149
|
+
entities?: {
|
|
150
|
+
roles?: boolean | {
|
|
151
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
152
|
+
exclude?: string[];
|
|
153
|
+
include?: string[];
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
driver: "aws-data-api";
|
|
157
|
+
dbCredentials: {
|
|
158
|
+
database: string;
|
|
159
|
+
secretArn: string;
|
|
160
|
+
resourceArn: string;
|
|
161
|
+
};
|
|
162
|
+
schema: string | string[] | undefined;
|
|
163
|
+
out: string | undefined;
|
|
164
|
+
} | {
|
|
165
|
+
dialect: "postgresql";
|
|
166
|
+
breakpoints?: boolean;
|
|
167
|
+
tablesFilter?: string | string[];
|
|
168
|
+
extensionsFilters?: 'postgis'[];
|
|
169
|
+
schemaFilter?: string | string[];
|
|
170
|
+
verbose?: boolean;
|
|
171
|
+
strict?: boolean;
|
|
172
|
+
casing?: 'camelCase' | 'snake_case';
|
|
173
|
+
migrations?: {
|
|
174
|
+
table?: string;
|
|
175
|
+
schema?: string;
|
|
176
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
177
|
+
};
|
|
178
|
+
introspect?: {
|
|
179
|
+
casing: 'camel' | 'preserve';
|
|
180
|
+
};
|
|
181
|
+
entities?: {
|
|
182
|
+
roles?: boolean | {
|
|
183
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
184
|
+
exclude?: string[];
|
|
185
|
+
include?: string[];
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
driver: "pglite";
|
|
189
|
+
dbCredentials: {
|
|
190
|
+
url: string;
|
|
191
|
+
};
|
|
192
|
+
schema: string | string[] | undefined;
|
|
193
|
+
out: string | undefined;
|
|
194
|
+
} | {
|
|
195
|
+
dialect: "mysql";
|
|
196
|
+
breakpoints?: boolean;
|
|
197
|
+
tablesFilter?: string | string[];
|
|
198
|
+
extensionsFilters?: 'postgis'[];
|
|
199
|
+
schemaFilter?: string | string[];
|
|
200
|
+
verbose?: boolean;
|
|
201
|
+
strict?: boolean;
|
|
202
|
+
casing?: 'camelCase' | 'snake_case';
|
|
203
|
+
migrations?: {
|
|
204
|
+
table?: string;
|
|
205
|
+
schema?: string;
|
|
206
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
207
|
+
};
|
|
208
|
+
introspect?: {
|
|
209
|
+
casing: 'camel' | 'preserve';
|
|
210
|
+
};
|
|
211
|
+
entities?: {
|
|
212
|
+
roles?: boolean | {
|
|
213
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
214
|
+
exclude?: string[];
|
|
215
|
+
include?: string[];
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
dbCredentials: {
|
|
219
|
+
host: string;
|
|
220
|
+
port?: number;
|
|
221
|
+
user?: string;
|
|
222
|
+
password?: string;
|
|
223
|
+
database: string;
|
|
224
|
+
ssl?: string | {
|
|
225
|
+
pfx?: string;
|
|
226
|
+
key?: string;
|
|
227
|
+
passphrase?: string;
|
|
228
|
+
cert?: string;
|
|
229
|
+
ca?: string | string[];
|
|
230
|
+
crl?: string | string[];
|
|
231
|
+
ciphers?: string;
|
|
232
|
+
rejectUnauthorized?: boolean;
|
|
233
|
+
};
|
|
234
|
+
} | {
|
|
235
|
+
url: string;
|
|
236
|
+
};
|
|
237
|
+
schema: string | string[] | undefined;
|
|
238
|
+
out: string | undefined;
|
|
239
|
+
} | {
|
|
240
|
+
dialect: "sqlite";
|
|
241
|
+
breakpoints?: boolean;
|
|
242
|
+
tablesFilter?: string | string[];
|
|
243
|
+
extensionsFilters?: 'postgis'[];
|
|
244
|
+
schemaFilter?: string | string[];
|
|
245
|
+
verbose?: boolean;
|
|
246
|
+
strict?: boolean;
|
|
247
|
+
casing?: 'camelCase' | 'snake_case';
|
|
248
|
+
migrations?: {
|
|
249
|
+
table?: string;
|
|
250
|
+
schema?: string;
|
|
251
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
252
|
+
};
|
|
253
|
+
introspect?: {
|
|
254
|
+
casing: 'camel' | 'preserve';
|
|
255
|
+
};
|
|
256
|
+
entities?: {
|
|
257
|
+
roles?: boolean | {
|
|
258
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
259
|
+
exclude?: string[];
|
|
260
|
+
include?: string[];
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
driver: "d1-http";
|
|
264
|
+
dbCredentials: {
|
|
265
|
+
accountId: string;
|
|
266
|
+
databaseId: string;
|
|
267
|
+
token: string;
|
|
268
|
+
};
|
|
269
|
+
schema: string | string[] | undefined;
|
|
270
|
+
out: string | undefined;
|
|
271
|
+
} | {
|
|
272
|
+
dialect: "sqlite";
|
|
273
|
+
breakpoints?: boolean;
|
|
274
|
+
tablesFilter?: string | string[];
|
|
275
|
+
extensionsFilters?: 'postgis'[];
|
|
276
|
+
schemaFilter?: string | string[];
|
|
277
|
+
verbose?: boolean;
|
|
278
|
+
strict?: boolean;
|
|
279
|
+
casing?: 'camelCase' | 'snake_case';
|
|
280
|
+
migrations?: {
|
|
281
|
+
table?: string;
|
|
282
|
+
schema?: string;
|
|
283
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
284
|
+
};
|
|
285
|
+
introspect?: {
|
|
286
|
+
casing: 'camel' | 'preserve';
|
|
287
|
+
};
|
|
288
|
+
entities?: {
|
|
289
|
+
roles?: boolean | {
|
|
290
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
291
|
+
exclude?: string[];
|
|
292
|
+
include?: string[];
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
driver: "expo";
|
|
296
|
+
schema: string | string[] | undefined;
|
|
297
|
+
out: string | undefined;
|
|
298
|
+
} | {
|
|
299
|
+
dialect: "sqlite";
|
|
300
|
+
breakpoints?: boolean;
|
|
301
|
+
tablesFilter?: string | string[];
|
|
302
|
+
extensionsFilters?: 'postgis'[];
|
|
303
|
+
schemaFilter?: string | string[];
|
|
304
|
+
verbose?: boolean;
|
|
305
|
+
strict?: boolean;
|
|
306
|
+
casing?: 'camelCase' | 'snake_case';
|
|
307
|
+
migrations?: {
|
|
308
|
+
table?: string;
|
|
309
|
+
schema?: string;
|
|
310
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
311
|
+
};
|
|
312
|
+
introspect?: {
|
|
313
|
+
casing: 'camel' | 'preserve';
|
|
314
|
+
};
|
|
315
|
+
entities?: {
|
|
316
|
+
roles?: boolean | {
|
|
317
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
318
|
+
exclude?: string[];
|
|
319
|
+
include?: string[];
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
driver: "durable-sqlite";
|
|
323
|
+
schema: string | string[] | undefined;
|
|
324
|
+
out: string | undefined;
|
|
325
|
+
} | {
|
|
326
|
+
dialect: "singlestore";
|
|
327
|
+
breakpoints?: boolean;
|
|
328
|
+
tablesFilter?: string | string[];
|
|
329
|
+
extensionsFilters?: 'postgis'[];
|
|
330
|
+
schemaFilter?: string | string[];
|
|
331
|
+
verbose?: boolean;
|
|
332
|
+
strict?: boolean;
|
|
333
|
+
casing?: 'camelCase' | 'snake_case';
|
|
334
|
+
migrations?: {
|
|
335
|
+
table?: string;
|
|
336
|
+
schema?: string;
|
|
337
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
338
|
+
};
|
|
339
|
+
introspect?: {
|
|
340
|
+
casing: 'camel' | 'preserve';
|
|
341
|
+
};
|
|
342
|
+
entities?: {
|
|
343
|
+
roles?: boolean | {
|
|
344
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
345
|
+
exclude?: string[];
|
|
346
|
+
include?: string[];
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
dbCredentials: {
|
|
350
|
+
host: string;
|
|
351
|
+
port?: number;
|
|
352
|
+
user?: string;
|
|
353
|
+
password?: string;
|
|
354
|
+
database: string;
|
|
355
|
+
ssl?: string | {
|
|
356
|
+
pfx?: string;
|
|
357
|
+
key?: string;
|
|
358
|
+
passphrase?: string;
|
|
359
|
+
cert?: string;
|
|
360
|
+
ca?: string | string[];
|
|
361
|
+
crl?: string | string[];
|
|
362
|
+
ciphers?: string;
|
|
363
|
+
rejectUnauthorized?: boolean;
|
|
364
|
+
};
|
|
365
|
+
} | {
|
|
366
|
+
url: string;
|
|
367
|
+
};
|
|
368
|
+
schema: string | string[] | undefined;
|
|
369
|
+
out: string | undefined;
|
|
370
|
+
} | {
|
|
371
|
+
dialect: "gel";
|
|
372
|
+
breakpoints?: boolean;
|
|
373
|
+
tablesFilter?: string | string[];
|
|
374
|
+
extensionsFilters?: 'postgis'[];
|
|
375
|
+
schemaFilter?: string | string[];
|
|
376
|
+
verbose?: boolean;
|
|
377
|
+
strict?: boolean;
|
|
378
|
+
casing?: 'camelCase' | 'snake_case';
|
|
379
|
+
migrations?: {
|
|
380
|
+
table?: string;
|
|
381
|
+
schema?: string;
|
|
382
|
+
prefix?: "index" | "none" | "supabase" | "timestamp" | "unix";
|
|
383
|
+
};
|
|
384
|
+
introspect?: {
|
|
385
|
+
casing: 'camel' | 'preserve';
|
|
386
|
+
};
|
|
387
|
+
entities?: {
|
|
388
|
+
roles?: boolean | {
|
|
389
|
+
provider?: 'supabase' | 'neon' | (string & {});
|
|
390
|
+
exclude?: string[];
|
|
391
|
+
include?: string[];
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
dbCredentials?: {
|
|
395
|
+
tlsSecurity?: 'insecure' | 'no_host_verification' | 'strict' | 'default';
|
|
396
|
+
} & ({
|
|
397
|
+
url: string;
|
|
398
|
+
} | ({
|
|
399
|
+
host: string;
|
|
400
|
+
port?: number;
|
|
401
|
+
user?: string;
|
|
402
|
+
password?: string;
|
|
403
|
+
database: string;
|
|
404
|
+
}));
|
|
405
|
+
schema: string | string[] | undefined;
|
|
406
|
+
out: string | undefined;
|
|
407
|
+
};
|
|
408
|
+
//#endregion
|
|
409
|
+
export { defineConfig };
|
|
410
|
+
//# sourceMappingURL=defineConfig.d.mts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { relative, resolve } from "pathe";
|
|
2
|
+
import { cwd } from "node:process";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
//#region src/config/defineConfig.ts
|
|
5
|
+
/**
|
|
6
|
+
* Define Drizzle config compatible with both 'nitro-drizzle/module' and 'drizzle-kit' packages.
|
|
7
|
+
*
|
|
8
|
+
* @param config
|
|
9
|
+
* @param dirname
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function defineConfig(config, filename) {
|
|
13
|
+
const { schema, out, ...other } = config;
|
|
14
|
+
const workingDir = cwd();
|
|
15
|
+
const dirname = fileURLToPath(new URL(".", filename));
|
|
16
|
+
return {
|
|
17
|
+
schema: transformToPluginCompatiblePath(dirname, workingDir, schema),
|
|
18
|
+
out: transformToPluginCompatiblePath(dirname, workingDir, out),
|
|
19
|
+
...other
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function transformToPluginCompatiblePath(dirname, cwd, path) {
|
|
23
|
+
if (!path) return;
|
|
24
|
+
if (Array.isArray(path)) return path.flatMap((path) => transformToRelative(dirname, cwd, path));
|
|
25
|
+
return relative(cwd, resolve(dirname, path));
|
|
26
|
+
}
|
|
27
|
+
function transformToRelative(dirname, cwd, path) {
|
|
28
|
+
path = resolve(dirname, path);
|
|
29
|
+
return relative(cwd, path);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { defineConfig };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=defineConfig.mjs.map
|