1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

orm: improve the README and the tests. Add an error message for foreign key tags (#15670)

This commit is contained in:
Hitalo Souza
2022-09-06 07:12:37 -03:00
committed by GitHub
parent e3d3863fbe
commit 95a328be98
4 changed files with 41 additions and 25 deletions

View File

@@ -17,6 +17,7 @@
- `[sql: 'name']` sets a custom column name for the field
- `[sql_type: 'SQL TYPE']` sets the sql type which is used in sql
- `[default: 'sql defaults']` sets the default value or function when create a new table
- `[fkey: 'parent_id']` sets foreign key for an field which holds an array
## Usage
@@ -27,7 +28,15 @@ struct Foo {
created_at time.Time [sql_type: 'DATETIME']
updated_at string [sql_type: 'DATETIME']
deleted_at time.Time
children []Child [fkey: 'parent_id']
}
struct Child {
id int [primary; sql: serial]
parent_id int
name string
}
```
### Create
@@ -54,6 +63,14 @@ var := Foo{
created_at: time.now()
updated_at: time.now().str()
deleted_at: time.now()
children: [
Child{
name: 'abc'
},
Child{
name: 'def'
},
]
}
sql db {
@@ -65,7 +82,7 @@ sql db {
```v ignore
sql db {
update Foo set name = 'cde' where name == 'abc'
update Foo set name = 'cde', updated_at = time.now() where name == 'abc'
}
```
@@ -84,7 +101,7 @@ result := sql db {
```
```v ignore
result := sql db {
select from Foo where id > 1 limit 5
select from Foo where id > 1 && name != 'lasanha' limit 5
}
```
```v ignore