mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen
: allow ORM to work with DB aliases (#16939)
This commit is contained in:
@ -1,5 +1,34 @@
|
||||
import sqlite
|
||||
|
||||
type Connection = sqlite.DB
|
||||
|
||||
struct User {
|
||||
pub:
|
||||
id int [primary; sql: serial]
|
||||
name string
|
||||
}
|
||||
|
||||
type Content = []u8 | string
|
||||
|
||||
struct Host {
|
||||
pub:
|
||||
db Connection
|
||||
}
|
||||
|
||||
fn (back Host) get_users() []User {
|
||||
return []
|
||||
}
|
||||
|
||||
fn create_host(db Connection) Host {
|
||||
sql db {
|
||||
create table User
|
||||
}
|
||||
|
||||
return Host{
|
||||
db: db
|
||||
}
|
||||
}
|
||||
|
||||
fn test_sqlite() {
|
||||
$if !linux {
|
||||
return
|
||||
@ -56,3 +85,8 @@ fn test_can_access_sqlite_result_consts() {
|
||||
assert sqlite.sqlite_row == 100
|
||||
assert sqlite.sqlite_done == 101
|
||||
}
|
||||
|
||||
fn test_alias_db() {
|
||||
create_host(sqlite.connect(':memory:')!)
|
||||
assert true
|
||||
}
|
||||
|
Reference in New Issue
Block a user