mirror of
https://github.com/vlang/v.git
synced 2025-09-19 04:17:46 -04:00
This commit is contained in:
parent
3cbc141c80
commit
85a2dd9f13
46
vlib/orm/orm_generic_test.v
Normal file
46
vlib/orm/orm_generic_test.v
Normal file
@ -0,0 +1,46 @@
|
||||
// vtest build: present_sqlite3? && !sanitize-memory-clang
|
||||
import db.sqlite
|
||||
|
||||
pub enum MessageStatus as u8 {
|
||||
ready
|
||||
}
|
||||
|
||||
pub struct Message[T] {
|
||||
message_id int @[primary; sql: serial]
|
||||
status MessageStatus
|
||||
}
|
||||
|
||||
pub struct Queue[T] {
|
||||
conn &sqlite.DB
|
||||
}
|
||||
|
||||
pub struct Queue_config {
|
||||
path string
|
||||
db ?sqlite.DB @[omitempty]
|
||||
}
|
||||
|
||||
pub fn new[T](config Queue_config) !Queue[T] {
|
||||
mut conn := if db := config.db {
|
||||
db
|
||||
} else {
|
||||
sqlite.connect(config.path) or { return error('Failed to connect to database: ${err}') }
|
||||
}
|
||||
mut queue := Queue[T]{
|
||||
conn: &conn
|
||||
}
|
||||
return queue
|
||||
}
|
||||
|
||||
pub fn (mut self Queue[T]) take() !Message[T] {
|
||||
messages := sql self.conn {
|
||||
select from Message[T] where status == MessageStatus.ready order by message_id limit 1
|
||||
} or { return error('') }
|
||||
message := messages.first()
|
||||
return message
|
||||
}
|
||||
|
||||
struct Payload {}
|
||||
|
||||
fn test_main() {
|
||||
_ := new[Payload](path: ':memory:')!
|
||||
}
|
@ -101,6 +101,8 @@ fn (mut p Parser) sql_expr() ast.Expr {
|
||||
|
||||
if is_count {
|
||||
typ = ast.int_type
|
||||
} else if table_type.has_flag(.generic) {
|
||||
typ = ast.new_type(p.table.find_or_register_array(table_type)).set_flag(.generic)
|
||||
} else {
|
||||
typ = ast.new_type(p.table.find_or_register_array(table_type))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user