mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: allow using connections, that were explicitly casted to orm.Connection
too (#17427)
This commit is contained in:
31
vlib/orm/orm_interface_test.v
Normal file
31
vlib/orm/orm_interface_test.v
Normal file
@ -0,0 +1,31 @@
|
||||
import db.sqlite
|
||||
import orm
|
||||
|
||||
struct User {
|
||||
id int [primary; sql: serial]
|
||||
name string
|
||||
}
|
||||
|
||||
fn test_orm_interface() {
|
||||
sqlite_db := sqlite.connect(':memory:') or { panic(err) }
|
||||
db := orm.Connection(sqlite_db)
|
||||
|
||||
sql db {
|
||||
create table User
|
||||
}
|
||||
|
||||
user := User{
|
||||
name: 'test'
|
||||
}
|
||||
|
||||
sql db {
|
||||
insert user into User
|
||||
}
|
||||
|
||||
users := sql db {
|
||||
select from User
|
||||
}
|
||||
|
||||
assert users.len == 1
|
||||
assert users.first().name == user.name
|
||||
}
|
Reference in New Issue
Block a user