1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix striping modules prefix in orm (#15005)

This commit is contained in:
Louis Schmieder 2022-08-31 18:23:36 +02:00 committed by GitHub
parent 806c39d46e
commit fef26a0b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -1262,7 +1262,12 @@ pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) {
}
pub fn (mut f Fmt) sql_stmt_line(node ast.SqlStmtLine) {
table_name := util.strip_mod_name(f.table.sym(node.table_expr.typ).name)
sym := f.table.sym(node.table_expr.typ)
mut table_name := sym.name
if !table_name.starts_with('C.') && !table_name.starts_with('JS.') {
table_name = f.no_cur_mod(f.short_module(sym.name)) // TODO f.type_to_str?
}
f.mark_types_import_as_used(node.table_expr.typ)
f.write('\t')
match node.kind {
@ -2530,7 +2535,11 @@ pub fn (mut f Fmt) sql_expr(node ast.SqlExpr) {
f.expr(node.db_expr)
f.writeln(' {')
f.write('\tselect ')
table_name := util.strip_mod_name(f.table.sym(node.table_expr.typ).name)
sym := f.table.sym(node.table_expr.typ)
mut table_name := sym.name
if !table_name.starts_with('C.') && !table_name.starts_with('JS.') {
table_name = f.no_cur_mod(f.short_module(sym.name)) // TODO f.type_to_str?
}
if node.is_count {
f.write('count ')
} else {

View File

@ -0,0 +1,9 @@
// somefile.v
import orm
import models
fn init_db(db orm.Connection) {
sql db {
create table models.User
}
}