parser: fix orm generic struct table type parsing (fix #24049) (#24149)

This commit is contained in:
Felipe Pena 2025-04-07 09:36:52 -03:00 committed by GitHub
parent 3cbc141c80
commit 85a2dd9f13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View 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:')!
}

View File

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