mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: add mysql support (#9630)
* add mysql to orm * fix got to big packet error * format sql.v * format example * custom sql types * add mysql table cration * add documentation * format sql.v * fix markdown * start implementing select_expr for mysql * remove orm.c * format sql.v * finish mysql expr * remove c * remove unessecary files * change to c implementation * remove c * added str interpolation for idents * fix string insert * fix compilation problems * fix gitly compilation * fix typing mistake * add link to orm docs
This commit is contained in:
71
vlib/orm/README.md
Normal file
71
vlib/orm/README.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# ORM
|
||||
|
||||
## Attributes
|
||||
|
||||
### Fields
|
||||
|
||||
- `[primary]` set the field as the primary key
|
||||
- `[nonull]` field will be `NOT NULL` in table creation
|
||||
- `[skip]` field will be skipped
|
||||
- `[sql: type]` sets the type which is used in sql (special type `serial`)
|
||||
|
||||
## Usage
|
||||
|
||||
```v ignore
|
||||
struct Foo {
|
||||
id int [primary; sql: serial]
|
||||
name string [nonull]
|
||||
}
|
||||
```
|
||||
|
||||
### Create
|
||||
|
||||
```v ignore
|
||||
sql db {
|
||||
create table Foo
|
||||
}
|
||||
```
|
||||
|
||||
### Insert
|
||||
|
||||
```v ignore
|
||||
var := Foo{
|
||||
name: 'abc'
|
||||
}
|
||||
|
||||
sql db {
|
||||
insert var into Foo
|
||||
}
|
||||
```
|
||||
|
||||
### Update
|
||||
|
||||
```v ignore
|
||||
sql db {
|
||||
update Foo set name = 'cde' where name == 'abc'
|
||||
}
|
||||
```
|
||||
|
||||
### Delete
|
||||
```v ignore
|
||||
sql db {
|
||||
delete from Foo where id > 10
|
||||
}
|
||||
```
|
||||
|
||||
### Select
|
||||
```v ignore
|
||||
result := sql db {
|
||||
select from Foo where id == 1
|
||||
}
|
||||
```
|
||||
```v ignore
|
||||
result := sql db {
|
||||
select from Foo where id > 1 limit 5
|
||||
}
|
||||
```
|
||||
```v ignore
|
||||
result := sql db {
|
||||
select from Foo where id > 1 order by id
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user