Skip to content

Commit

Permalink
docs: add a code sample showing how to delete rows with the builtin ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Sep 16, 2023
1 parent b88840e commit 6698e28
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4982,7 +4982,7 @@ struct Customer {
db := sqlite.connect('customers.db')!
// you can create tables:
// You can create tables from your struct declarations. For example the next query will issue SQL similar to this:
// CREATE TABLE IF NOT EXISTS `Customer` (
// `id` INTEGER PRIMARY KEY,
// `name` TEXT NOT NULL,
Expand All @@ -4993,28 +4993,48 @@ sql db {
create table Customer
}!
// insert a new customer:
new_customer := Customer{
name: 'Bob'
country: 'uk'
nr_orders: 10
}
sql db {
insert new_customer into Customer
}!
us_customer := Customer{
name: 'Martin'
country: 'us'
nr_orders: 5
}
sql db {
insert us_customer into Customer
}!
// update a customer:
sql db {
update Customer set nr_orders = nr_orders + 1 where name == 'Bob'
}!
// select count(*) from customers
nr_customers := sql db {
select count from Customer
}!
println('number of all customers: ${nr_customers}')
// V syntax can be used to build queries
// V's syntax can be used to build queries:
uk_customers := sql db {
select from Customer where country == 'uk' && nr_orders > 0
}!
println(uk_customers.len)
println('We found a total of ${uk_customers.len} customers, that match the query.')
for customer in uk_customers {
println('${customer.id} - ${customer.name}')
println('customer: ${customer.id}, ${customer.name}, ${customer.country}, ${customer.nr_orders}')
}
// insert a new customer
new_customer := Customer{
name: 'Bob'
nr_orders: 10
}
// delete a customer
sql db {
insert new_customer into Customer
delete from Customer where name == 'Bob'
}!
```

Expand Down

0 comments on commit 6698e28

Please sign in to comment.