mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: SqlStmt
This commit is contained in:
parent
13faf864cb
commit
090e6e936a
@ -123,6 +123,12 @@ fn test_orm_sqlite() {
|
||||
println(customer)
|
||||
assert customer.is_customer == true
|
||||
assert customer.name == 'Kate'
|
||||
//
|
||||
/*
|
||||
sql db {
|
||||
update User set age = 31 where name = 'Kate'
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ pub type Expr = AnonFn | ArrayInit | AsCast | Assoc | BoolLiteral | CallExpr | C
|
||||
pub type Stmt = AssertStmt | AssignStmt | Attr | Block | BranchStmt | Comment | CompIf |
|
||||
ConstDecl | DeferStmt | EnumDecl | ExprStmt | FnDecl | ForCStmt | ForInStmt | ForStmt |
|
||||
GlobalDecl | GoStmt | GotoLabel | GotoStmt | HashStmt | Import | InterfaceDecl | Module |
|
||||
Return | SqlInsertExpr | StructDecl | TypeDecl | UnsafeStmt
|
||||
Return | SqlStmt | StructDecl | TypeDecl | UnsafeStmt
|
||||
|
||||
pub type ScopeObject = ConstField | GlobalDecl | Var
|
||||
|
||||
@ -808,8 +808,16 @@ pub enum SqlExprKind {
|
||||
update
|
||||
}
|
||||
*/
|
||||
pub struct SqlInsertExpr {
|
||||
|
||||
pub enum SqlStmtKind {
|
||||
insert
|
||||
update
|
||||
delete
|
||||
}
|
||||
|
||||
pub struct SqlStmt {
|
||||
pub:
|
||||
kind SqlStmtKind
|
||||
db_expr Expr // `db` in `sql db {`
|
||||
table_name string
|
||||
object_var_name string // `user`
|
||||
|
@ -1817,7 +1817,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
||||
c.return_stmt(mut it)
|
||||
c.scope_returns = true
|
||||
}
|
||||
ast.SqlInsertExpr {
|
||||
ast.SqlStmt {
|
||||
c.sql_insert_expr(node)
|
||||
}
|
||||
ast.StructDecl {
|
||||
@ -2654,7 +2654,7 @@ fn (mut c Checker) sql_expr(node ast.SqlExpr) table.Type {
|
||||
return node.typ
|
||||
}
|
||||
|
||||
fn (mut c Checker) sql_insert_expr(node ast.SqlInsertExpr) table.Type {
|
||||
fn (mut c Checker) sql_insert_expr(node ast.SqlStmt ) table.Type {
|
||||
c.expr(node.db_expr)
|
||||
return table.void_type
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
g.write_autofree_stmts_when_needed(node)
|
||||
g.return_statement(node)
|
||||
}
|
||||
ast.SqlInsertExpr{
|
||||
ast.SqlStmt{
|
||||
g.sql_insert_expr(node)
|
||||
}
|
||||
ast.StructDecl {
|
||||
|
@ -484,7 +484,7 @@ fn (mut g JsGen) stmt(node ast.Stmt) {
|
||||
}
|
||||
g.gen_return_stmt(it)
|
||||
}
|
||||
ast.SqlInsertExpr{
|
||||
ast.SqlStmt{
|
||||
}
|
||||
ast.StructDecl {
|
||||
g.gen_struct_decl(it)
|
||||
|
@ -14,7 +14,7 @@ const (
|
||||
|
||||
enum SqlExprSide { left right }
|
||||
|
||||
fn (mut g Gen) sql_insert_expr(node ast.SqlInsertExpr) {
|
||||
fn (mut g Gen) sql_insert_expr(node ast.SqlStmt) {
|
||||
sym := g.table.get_type_symbol(node.table_type)
|
||||
info := sym.info as table.Struct
|
||||
fields := info.fields.filter(it.typ in [table.string_type, table.int_type, table.bool_type] &&
|
||||
|
@ -103,7 +103,7 @@ fn (mut p Parser) sql_expr() ast.Expr {
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut p Parser) sql_insert_expr() ast.SqlInsertExpr {
|
||||
fn (mut p Parser) sql_insert_expr() ast.SqlStmt{
|
||||
p.inside_match = true
|
||||
defer { p.inside_match = false }
|
||||
// `sql db {`
|
||||
@ -130,7 +130,7 @@ fn (mut p Parser) sql_insert_expr() ast.SqlInsertExpr {
|
||||
// fields := info.fields.filter(it.typ in [table.string_type, table.int_type, table.bool_type])
|
||||
table_name := sym.name
|
||||
p.check(.rcbr)
|
||||
return ast.SqlInsertExpr{
|
||||
return ast.SqlStmt{
|
||||
db_expr: db_expr
|
||||
table_name: table_name
|
||||
table_type: table_type
|
||||
|
Loading…
Reference in New Issue
Block a user