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

doc: update ORM syntax

This commit is contained in:
Alexander Medvednikov 2020-06-21 16:09:35 +02:00 committed by GitHub
parent db05e5b66c
commit 9d7afa4e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1470,27 +1470,27 @@ struct Customer { // struct name has to be the same as the table name (for now)
country string
}
db := pg.connect(db_name, db_user)
db := sqlite.connect('customers.db')
// select count(*) from Customer
nr_customers := db.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 := db.select from Customer where country == 'uk' && nr_orders > 0
uk_customers := sql db { select from Customer where country == 'uk' && nr_orders > 0 }
println(uk_customers.len)
for customer in uk_customers {
println('$customer.id - $customer.name')
}
// by adding `limit 1` we tell V that there will be only one object
customer := db.select from Customer where id == 1 limit 1
customer := sql db { select from Customer where id == 1 limit 1 }
println('$customer.id - $customer.name')
// insert a new customer
new_customer := Customer{name: 'Bob', nr_orders: 10}
db.insert(new_customer)
sql db { insert new_customer into Customer }
```
## vfmt