mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
parent
2ab152390e
commit
6f97ced860
@ -167,6 +167,7 @@ const skip_with_fsanitize_memory = [
|
|||||||
'vlib/orm/orm_option_time_test.v',
|
'vlib/orm/orm_option_time_test.v',
|
||||||
'vlib/db/sqlite/sqlite_test.v',
|
'vlib/db/sqlite/sqlite_test.v',
|
||||||
'vlib/db/sqlite/sqlite_orm_test.v',
|
'vlib/db/sqlite/sqlite_orm_test.v',
|
||||||
|
'vlib/db/sqlite/sqlite_comptime_field_test.v',
|
||||||
'vlib/db/sqlite/parent_child_test.v',
|
'vlib/db/sqlite/parent_child_test.v',
|
||||||
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
|
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
|
||||||
'vlib/v/tests/orm_enum_test.v',
|
'vlib/v/tests/orm_enum_test.v',
|
||||||
@ -240,6 +241,7 @@ const skip_on_ubuntu_musl = [
|
|||||||
'vlib/net/http/status_test.v',
|
'vlib/net/http/status_test.v',
|
||||||
'vlib/db/sqlite/sqlite_test.v',
|
'vlib/db/sqlite/sqlite_test.v',
|
||||||
'vlib/db/sqlite/sqlite_orm_test.v',
|
'vlib/db/sqlite/sqlite_orm_test.v',
|
||||||
|
'vlib/db/sqlite/sqlite_comptime_field_test.v',
|
||||||
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
|
'vlib/db/sqlite/sqlite_vfs_lowlevel_test.v',
|
||||||
'vlib/db/sqlite/parent_child_test.v',
|
'vlib/db/sqlite/parent_child_test.v',
|
||||||
'vlib/orm/orm_test.v',
|
'vlib/orm/orm_test.v',
|
||||||
|
43
vlib/db/sqlite/sqlite_comptime_field_test.v
Normal file
43
vlib/db/sqlite/sqlite_comptime_field_test.v
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import db.sqlite
|
||||||
|
|
||||||
|
@[table: 'blog']
|
||||||
|
pub struct Blog {
|
||||||
|
id int @[primary; sql: serial]
|
||||||
|
slug string
|
||||||
|
language string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn records_by_field[T](db sqlite.DB, fieldname string, value string) ![]T {
|
||||||
|
$for field in T.fields {
|
||||||
|
if field.name == fieldname {
|
||||||
|
entries := sql db {
|
||||||
|
select from Blog where field.name == value
|
||||||
|
} or { return err }
|
||||||
|
return entries
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return error('fieldname not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
db := sqlite.connect(':memory:')!
|
||||||
|
sql db {
|
||||||
|
create table Blog
|
||||||
|
}!
|
||||||
|
|
||||||
|
row := Blog{
|
||||||
|
slug: 'Test'
|
||||||
|
language: 'v'
|
||||||
|
}
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
insert row into Blog
|
||||||
|
}!
|
||||||
|
rows := records_by_field[Blog](db, 'language', 'v') or {
|
||||||
|
println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert rows.len == 1
|
||||||
|
}
|
@ -566,7 +566,8 @@ fn (mut c Checker) check_where_expr_has_no_pointless_exprs(table_type_symbol &as
|
|||||||
|| expr.left is ast.PrefixExpr {
|
|| expr.left is ast.PrefixExpr {
|
||||||
c.check_where_expr_has_no_pointless_exprs(table_type_symbol, field_names,
|
c.check_where_expr_has_no_pointless_exprs(table_type_symbol, field_names,
|
||||||
expr.left)
|
expr.left)
|
||||||
} else {
|
} else if !(expr.left is ast.SelectorExpr
|
||||||
|
&& c.comptime.is_comptime_selector_field_name(expr.left, 'name')) {
|
||||||
c.orm_error(has_no_field_error, expr.left.pos())
|
c.orm_error(has_no_field_error, expr.left.pos())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,8 +809,12 @@ fn (mut g Gen) write_orm_where_expr(expr ast.Expr, mut fields []string, mut pare
|
|||||||
data << expr
|
data << expr
|
||||||
}
|
}
|
||||||
ast.SelectorExpr {
|
ast.SelectorExpr {
|
||||||
|
if g.comptime.is_comptime_selector_field_name(expr, 'name') {
|
||||||
|
fields << g.comptime.comptime_for_field_value.name
|
||||||
|
} else {
|
||||||
data << expr
|
data << expr
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ast.BoolLiteral {
|
ast.BoolLiteral {
|
||||||
data << expr
|
data << expr
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user