fmt: minor cleanup of sql_expr (#8340)

pull/8353/head
Lukas Neubert 2021-01-26 10:36:46 +01:00 committed by GitHub
parent 22847d1ec3
commit 3790bd67e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 21 deletions

View File

@ -1140,13 +1140,6 @@ pub:
foo int // todo foo int // todo
} }
/*
pub enum SqlExprKind {
select_
insert
update
}
*/
pub enum SqlStmtKind { pub enum SqlStmtKind {
insert insert
update update

View File

@ -1293,22 +1293,17 @@ pub fn (mut f Fmt) sql_expr(node ast.SqlExpr) {
f.write('sql ') f.write('sql ')
f.expr(node.db_expr) f.expr(node.db_expr)
f.writeln(' {') f.writeln(' {')
f.write('\t') f.write('\tselect ')
f.write('select ') table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name)
esym := f.table.get_type_symbol(node.table_expr.typ)
table_name := util.strip_mod_name(esym.name)
if node.is_count { if node.is_count {
f.write('count ') f.write('count ')
} else { } else {
if node.fields.len > 0 { for i, fd in node.fields {
for tfi, tf in node.fields { f.write(fd.name)
f.write(tf.name) if i < node.fields.len - 1 {
if tfi < node.fields.len - 1 {
f.write(', ') f.write(', ')
} }
} }
f.write(' ')
}
} }
f.write('from $table_name') f.write('from $table_name')
if node.has_where { if node.has_where {
@ -2361,12 +2356,13 @@ pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) {
f.expr(node.db_expr) f.expr(node.db_expr)
f.writeln(' {') f.writeln(' {')
table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name) table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name)
f.write('\t')
match node.kind { match node.kind {
.insert { .insert {
f.writeln('\tinsert $node.object_var_name into $table_name') f.writeln('insert $node.object_var_name into $table_name')
} }
.update { .update {
f.write('\tupdate $table_name set ') f.write('update $table_name set ')
for i, col in node.updated_columns { for i, col in node.updated_columns {
f.write('$col = ') f.write('$col = ')
f.expr(node.update_exprs[i]) f.expr(node.update_exprs[i])
@ -2382,7 +2378,7 @@ pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) {
f.writeln('') f.writeln('')
} }
.delete { .delete {
f.write('\tdelete from $table_name where ') f.write('delete from $table_name where ')
f.expr(node.where_expr) f.expr(node.where_expr)
f.writeln('') f.writeln('')
} }