36 lines
845 B
Markdown
36 lines
845 B
Markdown
|
# DSL Idea
|
||
|
|
||
|
## How should it look?
|
||
|
|
||
|
```bash
|
||
|
# User class
|
||
|
# auto-handles `id`, `pwhash`, and 2FA
|
||
|
schema User auth
|
||
|
id int primary index
|
||
|
name string required
|
||
|
bio string required
|
||
|
email email required
|
||
|
created tzdate once`datetime.datetime.now()`
|
||
|
|
||
|
|
||
|
# foreign key relations are specified with `@<key>`
|
||
|
schema Friendship
|
||
|
id int primary index
|
||
|
u1_id int @user.id required
|
||
|
u2_id int @user.id required
|
||
|
|
||
|
|
||
|
# specify returned fields in brackets [field1 field2]
|
||
|
endpoint /user/{uid}
|
||
|
find User (id == uid) [name bio created]
|
||
|
|
||
|
|
||
|
# * this is a auth-protected endpoint
|
||
|
# * the `|` operator evaluates the next statement if the current one fails
|
||
|
endpoint /friends auth
|
||
|
find Friendship (u1id == auth.id or u2id == auth.id) one [u1id u2id] >>
|
||
|
find User (id == u1id) one [name bio]
|
||
|
| find User (id == u2id) one [name bio]
|
||
|
```
|
||
|
|