Skip to content

Commit 8b8c277

Browse files
authored
ts: Add Prisma example (#167)
* ts: add prisma example * fix curl commands for sequalize * update package.json
1 parent ee4fc0f commit 8b8c277

18 files changed

+963
-2
lines changed

ts/prisma/.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/prisma/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Encore + Prisma TypeScript Example
2+
3+
This is a RESTful API Starter with [Prisma](https://prisma.io) 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/prisma
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+
## Configure Prisma
22+
23+
Get the connection string to the shadow database by running:
24+
25+
```
26+
encore db conn-uri encore_prisma_test --shadow
27+
28+
```
29+
30+
Then edit `users/prisma/schema.prisma` replace `<paste shadow db connection string here>` with the output of the above command.
31+
32+
33+
## Using the API
34+
35+
Counts and returns the number of existing users
36+
37+
```bash
38+
curl 'http://localhost:4000/count/users'
39+
```
40+
41+
Create a new user
42+
43+
```bash
44+
curl 'http://localhost:4000/users' -d '{"name":"John","surname":"Doe"}'
45+
```
46+
47+
Get all users data
48+
49+
```bash
50+
curl 'http://localhost:4000/users'
51+
52+
# for paginated data:
53+
curl 'http://localhost:4000/users?page=1&limit=10'
54+
```
55+
56+
Get user data by id
57+
58+
```bash
59+
curl 'http://localhost:4000/users/:id'
60+
```
61+
62+
Update user data
63+
64+
```bash
65+
# partial update
66+
curl -XPATCH 'http://localhost:4000/users/:id' -d '{"data":{"name":"Johnny"}}'
67+
68+
# update complete data
69+
curl -XPATCH 'http://localhost:4000/users/:id' -d '{"data":{"name":"Mary","surname":"Jane"}}'
70+
```
71+
72+
Delete an user by id
73+
74+
```bash
75+
curl -X DELETE 'http://localhost:4000/users/:id'
76+
```
77+
78+
## Deployment
79+
80+
Deploy your application to a staging environment in Encore's free development cloud:
81+
82+
```bash
83+
git add -A .
84+
git commit -m 'Commit message'
85+
git push encore
86+
```
87+
88+
Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL.
89+
90+
From there you can also connect your own AWS or GCP account to use for deployment.
91+
92+
Now off you go into the clouds!

ts/prisma/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)