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:
20
doc/docs.md
20
doc/docs.md
@@ -3147,8 +3147,8 @@ fn test() []int {
|
||||
|
||||
(This is still in an alpha state)
|
||||
|
||||
V has a built-in ORM (object-relational mapping) which supports SQLite,
|
||||
and will soon support MySQL, Postgres, MS SQL, and Oracle.
|
||||
V has a built-in ORM (object-relational mapping) which supports SQLite and MySQL,
|
||||
but soon it will support Postgres, MS SQL, and Oracle.
|
||||
|
||||
V's ORM provides a number of benefits:
|
||||
|
||||
@@ -3164,20 +3164,26 @@ import sqlite
|
||||
|
||||
struct Customer {
|
||||
// struct name has to be the same as the table name (for now)
|
||||
id int // a field named `id` of integer type must be the first field
|
||||
name string
|
||||
id int [primary; sql: serial] // a field named `id` of integer type must be the first field
|
||||
name string [nonull]
|
||||
nr_orders int
|
||||
country string
|
||||
country string [nonull]
|
||||
}
|
||||
|
||||
db := sqlite.connect('customers.db') ?
|
||||
|
||||
// you can create tables
|
||||
// CREATE TABLE IF NOT EXISTS `Customer` (`id` INTEGER PRIMARY KEY, `name` TEXT NOT NULL, `nr_orders` INTEGER, `country` TEXT NOT NULL)
|
||||
sql db {
|
||||
create table Customer
|
||||
}
|
||||
|
||||
// select count(*) from Customer
|
||||
nr_customers := sql db {
|
||||
select count from Customer
|
||||
}
|
||||
println('number of all customers: $nr_customers')
|
||||
// V syntax can be used to build queries
|
||||
// db.select returns an array
|
||||
uk_customers := sql db {
|
||||
select from Customer where country == 'uk' && nr_orders > 0
|
||||
}
|
||||
@@ -3200,7 +3206,7 @@ sql db {
|
||||
}
|
||||
```
|
||||
|
||||
For more examples, see <a href='https://github.com/vlang/v/blob/master/vlib/orm/orm_test.v'>vlib/orm/orm_test.v</a>.
|
||||
For more examples and the docs, see <a href='https://github.com/vlang/v/tree/master/vlib/orm'>vlib/orm</a>.
|
||||
|
||||
## Writing Documentation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user