Skip to content

Commit 8c2c07d

Browse files
Gel (#514)
* refactor: replace EdgeDB with Gel * Add Gel Get Started, logos and connections --------- Co-authored-by: Vlad Stohnii <[email protected]>
1 parent 8bf34ac commit 8c2c07d

File tree

15 files changed

+617
-95
lines changed

15 files changed

+617
-95
lines changed

public/svg/gel_dark.svg

Lines changed: 10 additions & 0 deletions
Loading

public/svg/gel_light.svg

Lines changed: 10 additions & 0 deletions
Loading

public/svg/gel_logo_letters.svg

Lines changed: 9 additions & 0 deletions
Loading

public/svg/gel_transparent.svg

Lines changed: 12 additions & 0 deletions
Loading

src/content/docs/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"Connect::",
1717
["get-started-postgresql", "PostgreSQL"],
18+
["get-started-gel", "Gel"],
1819
["get-started-mysql", "MySQL"],
1920
["get-started-sqlite", "SQLite"],
2021
["get-started-singlestore", "SingleStore"],

src/content/docs/get-started-gel.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import Tab from '@mdx/Tab.astro';
2+
import Tabs from '@mdx/Tabs.astro';
3+
import Npm from "@mdx/Npm.astro";
4+
import Callout from '@mdx/Callout.astro';
5+
import Steps from '@mdx/Steps.astro';
6+
import AnchorCards from '@mdx/AnchorCards.astro';
7+
import Prerequisites from "@mdx/Prerequisites.astro";
8+
import CodeTabs from "@mdx/CodeTabs.astro";
9+
import WhatsNextPostgres from "@mdx/WhatsNextPostgres.astro";
10+
11+
# Drizzle \<\> PostgreSQL
12+
<Prerequisites>
13+
- Database [connection basics](/docs/connect-overview) with Drizzle
14+
- gel-js [basics](https://github.com/geldata/gel-js)
15+
</Prerequisites>
16+
17+
Drizzle has native support for Gel connections with the `gel-js` client.
18+
19+
#### Step 1 - Install packages
20+
<Npm>
21+
drizzle-orm gel
22+
-D drizzle-kit
23+
</Npm>
24+
25+
#### Step 2 - Initialize the driver and make a query
26+
<CodeTabs items={["gel", "gel with config"]}>
27+
```typescript copy
28+
// Make sure to install the 'gel' package
29+
import { drizzle } from 'drizzle-orm/gel';
30+
31+
const db = drizzle(process.env.DATABASE_URL);
32+
33+
const result = await db.execute('select 1');
34+
```
35+
```typescript copy
36+
// Make sure to install the 'gel' package
37+
import { drizzle } from "drizzle-orm/gel";
38+
39+
// You can specify any property from the gel connection options
40+
const db = drizzle({
41+
connection: {
42+
dsn: process.env.DATABASE_URL,
43+
tlsSecurity: "default",
44+
},
45+
});
46+
47+
const result = await db.execute("select 1");
48+
```
49+
</CodeTabs>
50+
51+
If you need to provide your existing driver:
52+
53+
```typescript copy
54+
// Make sure to install the 'gel' package
55+
import { drizzle } from "drizzle-orm/gel";
56+
import { createClient } from "gel";
57+
58+
const gelClient = createClient();
59+
const db = drizzle({ client: gelClient });
60+
61+
const result = await db.execute('select 1');
62+
```
63+
64+
#### What's next?
65+
66+
<WhatsNextPostgres/>

src/content/docs/get-started/_meta.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[
22
["postgresql-new", "PostgreSQL"],
33
["postgresql-existing", "PostgreSQL"],
4+
["gel-new", "Gel"],
5+
["gel-existing", "Gel"],
46
["singlestore-new", "SingleStore"],
57
["singlestore-existing", "SingleStore"],
68
["neon-new", "PostgreSQL"],
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import Tab from '@mdx/Tab.astro';
2+
import Tabs from '@mdx/Tabs.astro';
3+
import Npm from "@mdx/Npm.astro";
4+
import Npx from "@mdx/Npx.astro";
5+
import Callout from '@mdx/Callout.astro';
6+
import Steps from '@mdx/Steps.astro';
7+
import AnchorCards from '@mdx/AnchorCards.astro';
8+
import Breadcrumbs from '@mdx/Breadcrumbs.astro';
9+
import Prerequisites from "@mdx/Prerequisites.astro";
10+
import CodeTabs from "@mdx/CodeTabs.astro";
11+
import FileStructure from '@mdx/get-started/FileStructure.mdx';
12+
import InstallPackages from '@mdx/get-started/InstallPackages.mdx';
13+
import ConnectPostgreSQL from '@mdx/get-started/postgresql/ConnectPostgreSQL.mdx'
14+
import CreateTable from '@mdx/get-started/postgresql/CreateTable.mdx'
15+
import SetupConfig from '@mdx/get-started/SetupConfig.mdx';
16+
import ApplyChanges from '@mdx/get-started/ApplyChanges.mdx';
17+
import RunFile from '@mdx/get-started/RunFile.mdx';
18+
import QueryDatabase from '@mdx/get-started/QueryDatabase.mdx';
19+
import SetupEnv from '@mdx/get-started/SetupEnv.mdx';
20+
21+
<Breadcrumbs/>
22+
23+
# Get Started with Drizzle and Gel in existing project
24+
25+
<Prerequisites>
26+
- **tsx** - package for running TypeScript files - [read here](https://tsx.is/)
27+
- **gel-js** - package for querying your Gel database - [read here](https://github.com/geldata/gel-js)
28+
- **gel** - cli tool to manage your Gel database - [read here](https://docs.edgedb.com/get-started/cli)
29+
</Prerequisites>
30+
31+
Drizzle has native support for Gel connections with the `gel` client.
32+
33+
This is the basic file structure of the project. In the `src` directory, we have table definition in `index.ts`. In `drizzle` folder there are generated Gel to Drizzle schema
34+
35+
```plaintext
36+
📦 <project root>
37+
├ 📂 drizzle
38+
├ 📂 dbschema
39+
│ ├ 📂 migrations
40+
│ ├ 📜 default.esdl
41+
│ └ 📜 scoping.esdl
42+
├ 📂 src
43+
│ └ 📜 index.ts
44+
├ 📜 drizzle.config.ts
45+
├ 📜 edgedb.toml
46+
├ 📜 package.json
47+
└ 📜 tsconfig.json
48+
```
49+
50+
#### Step 4 - Install **gel** package
51+
<Npm>
52+
drizzle-orm gel
53+
-D drizzle-kit tsx
54+
</Npm>
55+
56+
#### Step 5 - Setup Drizzle config file
57+
58+
**Drizzle config** - a configuration file that is used by [Drizzle Kit](/docs/kit-overview) and contains all the information about your database connection, migration folder and schema files.
59+
60+
Create a `drizzle.config.ts` file in the root of your project and add the following content:
61+
62+
```typescript copy filename="drizzle.config.ts"
63+
import { defineConfig } from 'drizzle-kit';
64+
65+
export default defineConfig({
66+
dialect: 'gel',
67+
});
68+
```
69+
70+
#### Step 6 - Pull Gel types to Drizzle schema
71+
72+
Pull your database schema:
73+
<Npx>
74+
drizzle-kit pull
75+
</Npx>
76+
77+
Here is an example of the generated schema.ts file:
78+
79+
```ts
80+
// drizzle/schema.ts
81+
import { gelTable, uniqueIndex, uuid, smallint, text } from "drizzle-orm/gel-core"
82+
import { sql } from "drizzle-orm"
83+
84+
export const users = gelTable("users", {
85+
id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(),
86+
age: smallint(),
87+
email: text().notNull(),
88+
name: text(),
89+
}, (table) => [
90+
uniqueIndex("a8c6061c-f37f-11ef-9249-0d78f6c1807b;schemaconstr").using("btree", table.id.asc().nullsLast().op("uuid_ops")),
91+
]);
92+
```
93+
94+
#### Step 6 - Connect Drizzle ORM to the database
95+
96+
Create a `index.ts` file in the `src` directory and initialize the connection:
97+
98+
```typescript copy
99+
import { drizzle } from "drizzle-orm/gel";
100+
import { createClient } from "gel";
101+
102+
const gelClient = createClient();
103+
const db = drizzle({ client: gelClient });
104+
```
105+
106+
#### Step 7 - Query the database
107+
108+
```typescript copy filename="src/index.ts"
109+
import { eq } from "drizzle-orm";
110+
import { drizzle } from "drizzle-orm/gel";
111+
import { createClient } from "gel";
112+
import { users } from "../drizzle/schema";
113+
114+
const gelClient = createClient();
115+
const db = drizzle({ client: gelClient });
116+
117+
async function main() {
118+
const user: typeof users.$inferInsert = {
119+
name: "John",
120+
age: 30,
121+
122+
};
123+
124+
await db.insert(users).values(user);
125+
console.log("New user created!");
126+
127+
const usersResponse = await db.select().from(users);
128+
console.log("Getting all users from the database: ", usersResponse);
129+
/*
130+
const users: {
131+
id: number;
132+
name: string;
133+
age: number;
134+
email: string;
135+
}[]
136+
*/
137+
138+
await db
139+
.update(users)
140+
.set({
141+
age: 31,
142+
})
143+
.where(eq(users.email, user.email));
144+
console.log("User info updated!");
145+
146+
await db.delete(users).where(eq(users.email, user.email));
147+
console.log("User deleted!");
148+
}
149+
150+
main();
151+
```
152+
153+
#### Step 8 - Run index.ts file
154+
155+
<RunFile/>

0 commit comments

Comments
 (0)