1
0
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:
Swastik Baranwal
2023-01-11 15:28:55 +05:30
committed by GitHub
parent e854051c1f
commit b872487d82
4 changed files with 49 additions and 3 deletions

View File

@ -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
}