2023-02-28 00:54:03 +03:00
|
|
|
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
|
2023-04-04 08:23:06 +03:00
|
|
|
}!
|
2023-02-28 00:54:03 +03:00
|
|
|
|
|
|
|
user := User{
|
|
|
|
name: 'test'
|
|
|
|
}
|
|
|
|
|
|
|
|
sql db {
|
|
|
|
insert user into User
|
2023-04-04 08:23:06 +03:00
|
|
|
}!
|
2023-02-28 00:54:03 +03:00
|
|
|
|
|
|
|
users := sql db {
|
|
|
|
select from User
|
2023-04-04 08:23:06 +03:00
|
|
|
}!
|
2023-02-28 00:54:03 +03:00
|
|
|
|
|
|
|
assert users.len == 1
|
|
|
|
assert users.first().name == user.name
|
|
|
|
}
|