Skip to content

Commit ff9d7c8

Browse files
authored
Add a TS drizzle example (#164)
* Add a TS drizzle example * Add Knex example
1 parent 8b8c277 commit ff9d7c8

28 files changed

+2781
-0
lines changed

ts/drizzle/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.encore
2+
encore.gen.go
3+
encore.gen.cue
4+
/.encore
5+
node_modules
6+
/encore.gen

ts/drizzle/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Encore + Drizzle TypeScript Example
2+
3+
This is a RESTful API Starter with [Drizzle](https://orm.drizzle.team/) as ORM to handle database CRUD operations.
4+
5+
## Developing locally
6+
7+
When you have [installed Encore](https://encore.dev/docs/install), you can create a new Encore application and clone this example with this command.
8+
9+
```bash
10+
encore app create my-app-name --example=ts/drizzle
11+
```
12+
13+
## Running locally
14+
15+
```bash
16+
encore run
17+
```
18+
19+
While `encore run` is running, open <http://localhost:9400/> to view Encore's [local developer dashboard](https://encore.dev/docs/observability/dev-dash).
20+
21+
## Using the API
22+
23+
Counts and returns the number of existing users
24+
25+
```bash
26+
curl 'http://localhost:4000/count/users'
27+
```
28+
29+
Create a new user
30+
31+
```bash
32+
curl 'http://localhost:4000/users' -d '{"name":"John","surname":"Doe"}'
33+
```
34+
35+
Get all users data
36+
37+
```bash
38+
curl 'http://localhost:4000/users'
39+
40+
# for paginated data:
41+
curl 'http://localhost:4000/users?page=1&limit=10'
42+
```
43+
44+
Get user data by id
45+
46+
```bash
47+
curl 'http://localhost:4000/users/:id'
48+
```
49+
50+
Update user data
51+
52+
```bash
53+
# partial update
54+
curl 'http://localhost:4000/users/:id' -d '{"data":{"name":"Johnny"}}'
55+
56+
# update complete data
57+
curl 'http://localhost:4000/users/:id' -d '{"data":{"name":"Mary","surname":"Jane"}}'
58+
```
59+
60+
Delete an user by id
61+
62+
```bash
63+
curl -X DELETE 'http://localhost:4000/users/:id'
64+
```
65+
66+
## Generate migrations
67+
After you've updated your `schema.ts` file, you can generate migrations by running `npx drizzle-kit generate` in the same directory as `drizzle.config.ts`.
68+
69+
## Deployment
70+
71+
Deploy your application to a staging environment in Encore's free development cloud:
72+
73+
```bash
74+
git add -A .
75+
git commit -m 'Commit message'
76+
git push encore
77+
```
78+
79+
Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL.
80+
81+
From there you can also connect your own AWS or GCP account to use for deployment.
82+
83+
Now off you go into the clouds!

ts/drizzle/encore.app

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
// The app is not currently linked to the encore.dev platform.
3+
// Use "encore app link" to link it.
4+
"id": "",
5+
"lang": "typescript",
6+
}

0 commit comments

Comments
 (0)