mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
tools: cleanup entries from the hardcoded skip_files list in common.v (used by v test
, v test-self
etc); use the new // vtest build:
syntax to mark the tests instead (#23918)
This commit is contained in:
parent
9f3f1291e8
commit
a80bc23314
109 changed files with 208 additions and 322 deletions
|
@ -1,3 +1,4 @@
|
|||
// vtest build: !(macos || windows)
|
||||
import db.mysql
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// vtest build: !(macos || windows)
|
||||
import os
|
||||
import db.sqlite
|
||||
import db.mysql
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// vtest build: linux
|
||||
module main
|
||||
|
||||
/*
|
||||
import db.pg
|
||||
*/
|
||||
|
||||
const dash = '----------------------------------------------------------------'
|
||||
|
||||
struct Customer {
|
||||
id int
|
||||
|
@ -13,53 +10,62 @@ struct Customer {
|
|||
country string
|
||||
}
|
||||
|
||||
const dash = '----------------------------------------------------------------'
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
db := pg.connect(pg.Config{
|
||||
host: 'localhost' //'127.0.0.1'
|
||||
user: 'postgres'
|
||||
db := pg.connect(
|
||||
host: 'localhost' // or '127.0.0.1'
|
||||
user: 'postgres'
|
||||
dbname: 'customerdb'
|
||||
}) or {
|
||||
println('failed to connect')
|
||||
println(err)
|
||||
) or {
|
||||
eprintln('failed to connect, error: ${err}')
|
||||
return
|
||||
}
|
||||
|
||||
nr_customers := db.select count from Customer
|
||||
println('Total customers: $nr_customers')
|
||||
nr_customers := sql db {
|
||||
select count from Customer
|
||||
}!
|
||||
println('Total customers: ${nr_customers}')
|
||||
|
||||
// V syntax can be used to build queries
|
||||
println(dash)
|
||||
bg_country := 'Bulgaria'
|
||||
bg_customers := db.select from Customer where country == bg_country && id != 2
|
||||
// V syntax can be used to build queries
|
||||
bg_customers := sql db {
|
||||
select from Customer where country == bg_country && id != 2
|
||||
}!
|
||||
for customer in bg_customers {
|
||||
println('$customer.country | $customer.id - $customer.name')
|
||||
println('${customer.country} | ${customer.id} - ${customer.name}')
|
||||
}
|
||||
|
||||
println(dash)
|
||||
ru_customers := db.select from Customer where country == 'Russia'
|
||||
ru_customers := sql db {
|
||||
select from Customer where country == 'Russia'
|
||||
}!
|
||||
for customer in ru_customers {
|
||||
println('$customer.country | $customer.id - $customer.name')
|
||||
println('${customer.country} | ${customer.id} - ${customer.name}')
|
||||
}
|
||||
|
||||
// by adding `limit 1` we tell V that there will be only one object
|
||||
println(dash)
|
||||
existing := db.select from Customer where id == 1 limit 1 or { panic(err) }
|
||||
println('Existing customer name: $existing.name')
|
||||
existing := sql db {
|
||||
select from Customer where id == 1 limit 1
|
||||
}!
|
||||
println('Existing customer name: ${existing}[0].name')
|
||||
println('Existing customer full information:')
|
||||
println(existing)
|
||||
|
||||
println(dash)
|
||||
q := Customer{}
|
||||
// It's easy to handle queries that don't return any data
|
||||
if anon := db.select from Customer where id == 12345 && name == q.name &&
|
||||
nr_orders > q.nr_orders limit 1 {
|
||||
println('Non existing customer name: $anon.name')
|
||||
}
|
||||
_ := sql db {
|
||||
select from Customer where id == 12345 && name == q.name && nr_orders > q.nr_orders limit 1
|
||||
}!
|
||||
// Insert a new customer
|
||||
nc := Customer{
|
||||
name: 'John Doe'
|
||||
name: 'John Doe'
|
||||
nr_orders: 10
|
||||
}
|
||||
db.insert(nc)*/
|
||||
sql db {
|
||||
insert nc into Customer
|
||||
}!
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue