mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
orm: fix order by with custom column name (#22813)
This commit is contained in:
parent
a1904154d3
commit
fad49da199
3 changed files with 47 additions and 1 deletions
37
vlib/orm/orm_order_by_custom_field_test.v
Normal file
37
vlib/orm/orm_order_by_custom_field_test.v
Normal file
|
@ -0,0 +1,37 @@
|
|||
import db.sqlite
|
||||
|
||||
@[table: 'prefixed_records']
|
||||
struct Record {
|
||||
id int @[primary; sql: 'CustomId']
|
||||
name string @[sql: 'named_name']
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut db := sqlite.connect(':memory:')!
|
||||
defer { db.close() or {} }
|
||||
|
||||
prepare(db)!
|
||||
|
||||
last := sql db {
|
||||
select from Record where name == 'first' order by id limit 1
|
||||
}!
|
||||
assert last.len == 1
|
||||
assert last[0].name == 'first'
|
||||
}
|
||||
|
||||
fn prepare(db sqlite.DB) ! {
|
||||
db.exec('
|
||||
CREATE TABLE prefixed_records (
|
||||
CustomId INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
named_name TEXT
|
||||
);
|
||||
')!
|
||||
|
||||
db.exec("
|
||||
INSERT INTO prefixed_records
|
||||
(named_name)
|
||||
VALUES
|
||||
('first'),
|
||||
('last');
|
||||
")!
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue