From fef26a0b1932516386f8a92d5614d76123a78e7a Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Wed, 31 Aug 2022 18:23:36 +0200 Subject: [PATCH] fmt: fix striping modules prefix in orm (#15005) --- vlib/v/fmt/fmt.v | 13 +++++++++++-- vlib/v/fmt/tests/orm_prefix_keep.vv | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 vlib/v/fmt/tests/orm_prefix_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 68b839e385..32e60a978f 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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 { diff --git a/vlib/v/fmt/tests/orm_prefix_keep.vv b/vlib/v/fmt/tests/orm_prefix_keep.vv new file mode 100644 index 0000000000..38e984628a --- /dev/null +++ b/vlib/v/fmt/tests/orm_prefix_keep.vv @@ -0,0 +1,9 @@ +// somefile.v +import orm +import models + +fn init_db(db orm.Connection) { + sql db { + create table models.User + } +}