Skip to content

Commit 78f3604

Browse files
Merge pull request #4173 from drizzle-team/beta
Beta
2 parents e5c63db + df9ec8b commit 78f3604

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+23204
-297
lines changed

changelogs/drizzle-kit/0.30.5.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# New Features
2+
3+
## Added `Gel` dialect support and `gel-js` client support
4+
5+
Drizzle is getting a new `Gel` dialect with its own types and Gel-specific logic. In this first iteration, almost all query-building features have been copied from the `PostgreSQL` dialect since Gel is fully PostgreSQL-compatible. The only change in this iteration is the data types. The Gel dialect has a different set of available data types, and all mappings for these types have been designed to avoid any extra conversions on Drizzle's side. This means you will insert and select exactly the same data as supported by the Gel protocol.
6+
7+
Drizzle + Gel integration will work only through `drizzle-kit pull`. Drizzle won't support `generate`, `migrate`, or `push` features in this case. Instead, drizzle-kit is used solely to pull the Drizzle schema from the Gel database, which can then be used in your `drizzle-orm` queries.
8+
9+
The Gel + Drizzle workflow:
10+
11+
1. Use the `gel` CLI to manage your schema.
12+
2. Use the `gel` CLI to generate and apply migrations to the database.
13+
3. Use drizzle-kit to pull the Gel database schema into a Drizzle schema.
14+
4. Use drizzle-orm with gel-js to query the Gel database.
15+
16+
On the drizzle-kit side you can now use `dialect: "gel"`
17+
18+
```ts
19+
// drizzle.config.ts
20+
import { defineConfig } from 'drizzle-kit';
21+
22+
export default defineConfig({
23+
dialect: 'gel',
24+
});
25+
```
26+
27+
For a complete Get Started tutorial you can use our new guides:
28+
29+
- [Get Started with Drizzle and Gel in a new project](https://orm.drizzle.team/docs/get-started/gel-new)
30+
- [Get Started with Drizzle and Gel in a existing project](https://orm.drizzle.team/docs/get-started/gel-existing)

changelogs/drizzle-orm/0.40.0.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# New Features
2+
3+
## Added `Gel` dialect support and `gel-js` client support
4+
5+
Drizzle is getting a new `Gel` dialect with its own types and Gel-specific logic. In this first iteration, almost all query-building features have been copied from the `PostgreSQL` dialect since Gel is fully PostgreSQL-compatible. The only change in this iteration is the data types. The Gel dialect has a different set of available data types, and all mappings for these types have been designed to avoid any extra conversions on Drizzle's side. This means you will insert and select exactly the same data as supported by the Gel protocol.
6+
7+
Drizzle + Gel integration will work only through `drizzle-kit pull`. Drizzle won't support `generate`, `migrate`, or `push` features in this case. Instead, drizzle-kit is used solely to pull the Drizzle schema from the Gel database, which can then be used in your `drizzle-orm` queries.
8+
9+
The Gel + Drizzle workflow:
10+
11+
1. Use the `gel` CLI to manage your schema.
12+
2. Use the `gel` CLI to generate and apply migrations to the database.
13+
3. Use drizzle-kit to pull the Gel database schema into a Drizzle schema.
14+
4. Use drizzle-orm with gel-js to query the Gel database.
15+
16+
Here is a small example of how to connect to Gel using Drizzle:
17+
18+
```typescript copy
19+
// Make sure to install the 'gel' package
20+
import { drizzle } from "drizzle-orm/gel";
21+
import { createClient } from "gel";
22+
23+
const gelClient = createClient();
24+
const db = drizzle({ client: gelClient });
25+
26+
const result = await db.execute('select 1');
27+
```
28+
29+
On the drizzle-kit side you can now use `dialect: "gel"`
30+
31+
```ts
32+
// drizzle.config.ts
33+
import { defineConfig } from 'drizzle-kit';
34+
35+
export default defineConfig({
36+
dialect: 'gel',
37+
});
38+
```
39+
40+
For a complete Get Started tutorial you can use our new guides:
41+
42+
- [Get Started with Drizzle and Gel in a new project](https://orm.drizzle.team/docs/get-started/gel-new)
43+
- [Get Started with Drizzle and Gel in a existing project](https://orm.drizzle.team/docs/get-started/gel-existing)

drizzle-kit/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-kit",
3-
"version": "0.30.4",
3+
"version": "0.30.5",
44
"homepage": "https://orm.drizzle.team",
55
"keywords": [
66
"drizzle",
@@ -46,7 +46,8 @@
4646
"@drizzle-team/brocli": "^0.10.2",
4747
"@esbuild-kit/esm-loader": "^2.5.5",
4848
"esbuild": "^0.19.7",
49-
"esbuild-register": "^3.5.0"
49+
"esbuild-register": "^3.5.0",
50+
"gel": "^2.0.0"
5051
},
5152
"devDependencies": {
5253
"@arethetypeswrong/cli": "^0.15.3",
@@ -114,7 +115,7 @@
114115
"wrangler": "^3.22.1",
115116
"ws": "^8.16.0",
116117
"zod": "^3.20.2",
117-
"zx": "^7.2.2"
118+
"zx": "^8.3.2"
118119
},
119120
"exports": {
120121
".": {

drizzle-kit/src/cli/commands/introspect.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { render, renderWithTask } from 'hanji';
44
import { Minimatch } from 'minimatch';
55
import { join } from 'path';
66
import { plural, singular } from 'pluralize';
7+
import { GelSchema } from 'src/serializer/gelSchema';
78
import { drySingleStore, SingleStoreSchema, squashSingleStoreScheme } from 'src/serializer/singlestoreSchema';
89
import { assertUnreachable, originUUID } from '../../global';
10+
import { schemaToTypeScript as gelSchemaToTypeScript } from '../../introspect-gel';
911
import { schemaToTypeScript as mysqlSchemaToTypeScript } from '../../introspect-mysql';
1012
import { paramNameFor, schemaToTypeScript as postgresSchemaToTypeScript } from '../../introspect-pg';
1113
import { schemaToTypeScript as singlestoreSchemaToTypeScript } from '../../introspect-singlestore';
1214
import { schemaToTypeScript as sqliteSchemaToTypeScript } from '../../introspect-sqlite';
15+
import { fromDatabase as fromGelDatabase } from '../../serializer/gelSerializer';
1316
import { dryMySql, MySqlSchema, squashMysqlScheme } from '../../serializer/mysqlSchema';
1417
import { fromDatabase as fromMysqlDatabase } from '../../serializer/mysqlSerializer';
1518
import { dryPg, type PgSchema, squashPgScheme } from '../../serializer/pgSchema';
@@ -27,6 +30,7 @@ import {
2730
import { prepareOutFolder } from '../../utils';
2831
import { Entities } from '../validations/cli';
2932
import type { Casing, Prefix } from '../validations/common';
33+
import { GelCredentials } from '../validations/gel';
3034
import { LibSQLCredentials } from '../validations/libsql';
3135
import type { MysqlCredentials } from '../validations/mysql';
3236
import type { PostgresCredentials } from '../validations/postgres';
@@ -174,6 +178,132 @@ export const introspectPostgres = async (
174178
process.exit(0);
175179
};
176180

181+
export const introspectGel = async (
182+
casing: Casing,
183+
out: string,
184+
breakpoints: boolean,
185+
credentials: GelCredentials | undefined,
186+
tablesFilter: string[],
187+
schemasFilter: string[],
188+
prefix: Prefix,
189+
entities: Entities,
190+
) => {
191+
const { prepareGelDB } = await import('../connections');
192+
const db = await prepareGelDB(credentials);
193+
194+
const matchers = tablesFilter.map((it) => {
195+
return new Minimatch(it);
196+
});
197+
198+
const filter = (tableName: string) => {
199+
if (matchers.length === 0) return true;
200+
201+
let flags: boolean[] = [];
202+
203+
for (let matcher of matchers) {
204+
if (matcher.negate) {
205+
if (!matcher.match(tableName)) {
206+
flags.push(false);
207+
}
208+
}
209+
210+
if (matcher.match(tableName)) {
211+
flags.push(true);
212+
}
213+
}
214+
215+
if (flags.length > 0) {
216+
return flags.every(Boolean);
217+
}
218+
return false;
219+
};
220+
221+
const progress = new IntrospectProgress(true);
222+
223+
const res = await renderWithTask(
224+
progress,
225+
fromGelDatabase(
226+
db,
227+
filter,
228+
schemasFilter,
229+
entities,
230+
(stage, count, status) => {
231+
progress.update(stage, count, status);
232+
},
233+
),
234+
);
235+
236+
const schema = { id: originUUID, prevId: '', ...res } as GelSchema;
237+
const ts = gelSchemaToTypeScript(schema, casing);
238+
const relationsTs = relationsToTypeScript(schema, casing);
239+
const { internal, ...schemaWithoutInternals } = schema;
240+
241+
const schemaFile = join(out, 'schema.ts');
242+
writeFileSync(schemaFile, ts.file);
243+
const relationsFile = join(out, 'relations.ts');
244+
writeFileSync(relationsFile, relationsTs.file);
245+
console.log();
246+
247+
// const { snapshots, journal } = prepareOutFolder(out, 'gel');
248+
249+
// if (snapshots.length === 0) {
250+
// const { sqlStatements, _meta } = await applyGelSnapshotsDiff(
251+
// squashGelScheme(dryGel),
252+
// squashGelScheme(schema),
253+
// schemasResolver,
254+
// enumsResolver,
255+
// sequencesResolver,
256+
// policyResolver,
257+
// indPolicyResolver,
258+
// roleResolver,
259+
// tablesResolver,
260+
// columnsResolver,
261+
// viewsResolver,
262+
// dryPg,
263+
// schema,
264+
// );
265+
266+
// writeResult({
267+
// cur: schema,
268+
// sqlStatements,
269+
// journal,
270+
// _meta,
271+
// outFolder: out,
272+
// breakpoints,
273+
// type: 'introspect',
274+
// prefixMode: prefix,
275+
// });
276+
// } else {
277+
// render(
278+
// `[${
279+
// chalk.blue(
280+
// 'i',
281+
// )
282+
// }] No SQL generated, you already have migrations in project`,
283+
// );
284+
// }
285+
286+
render(
287+
`[${
288+
chalk.green(
289+
'✓',
290+
)
291+
}] Your schema file is ready ➜ ${chalk.bold.underline.blue(schemaFile)} 🚀`,
292+
);
293+
render(
294+
`[${
295+
chalk.green(
296+
'✓',
297+
)
298+
}] Your relations file is ready ➜ ${
299+
chalk.bold.underline.blue(
300+
relationsFile,
301+
)
302+
} 🚀`,
303+
);
304+
process.exit(0);
305+
};
306+
177307
export const introspectMysql = async (
178308
casing: Casing,
179309
out: string,

0 commit comments

Comments
 (0)