diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index e3e8025d45..3cf5ada5d8 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -1140,13 +1140,6 @@ pub: foo int // todo } -/* -pub enum SqlExprKind { - select_ - insert - update -} -*/ pub enum SqlStmtKind { insert update diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 0e4f5405f7..810f313173 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1293,21 +1293,16 @@ pub fn (mut f Fmt) sql_expr(node ast.SqlExpr) { f.write('sql ') f.expr(node.db_expr) f.writeln(' {') - f.write('\t') - f.write('select ') - esym := f.table.get_type_symbol(node.table_expr.typ) - table_name := util.strip_mod_name(esym.name) + f.write('\tselect ') + table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name) if node.is_count { f.write('count ') } else { - if node.fields.len > 0 { - for tfi, tf in node.fields { - f.write(tf.name) - if tfi < node.fields.len - 1 { - f.write(', ') - } + for i, fd in node.fields { + f.write(fd.name) + if i < node.fields.len - 1 { + f.write(', ') } - f.write(' ') } } f.write('from $table_name') @@ -2361,12 +2356,13 @@ pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) { f.expr(node.db_expr) f.writeln(' {') table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name) + f.write('\t') match node.kind { .insert { - f.writeln('\tinsert $node.object_var_name into $table_name') + f.writeln('insert $node.object_var_name into $table_name') } .update { - f.write('\tupdate $table_name set ') + f.write('update $table_name set ') for i, col in node.updated_columns { f.write('$col = ') f.expr(node.update_exprs[i]) @@ -2382,7 +2378,7 @@ pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) { f.writeln('') } .delete { - f.write('\tdelete from $table_name where ') + f.write('delete from $table_name where ') f.expr(node.where_expr) f.writeln('') }