github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/sqlx/builder/stmt_delete_test.go (about) 1 package builder 2 3 import ( 4 "testing" 5 ) 6 7 func TestStmtDelete(t *testing.T) { 8 table := T(DB("db"), "t") 9 10 if table.Delete().Type() != STMT_DELETE { 11 panic("Delete type should be STMT_DELETE") 12 } 13 14 exprCases{ 15 Case( 16 "Delete with err", 17 table.Delete().Expr(), 18 ExprErr(DeleteNeedLimitByWhere), 19 ), 20 Case( 21 "Delete with modifier", 22 table.Delete().Modifier("IGNORE").Where( 23 Col(table, "F_a").Eq(1), 24 ).Expr(), 25 Expr( 26 "DELETE IGNORE FROM `db`.`t` WHERE `F_a` = ?", 27 1, 28 ), 29 ), 30 Case( 31 "Delete simple", 32 table.Delete().Comment("Comment").Where( 33 Col(table, "F_a").Eq(1), 34 ).Expr(), 35 Expr( 36 "/* Comment */ DELETE FROM `db`.`t` WHERE `F_a` = ?", 37 1, 38 ), 39 ), 40 Case( 41 "Delete with limit", 42 table.Delete(). 43 Where( 44 Col(table, "F_a").Eq(1), 45 ). 46 Limit(1). 47 Expr(), 48 Expr( 49 "DELETE FROM `db`.`t` WHERE `F_a` = ? LIMIT 1", 50 1, 51 ), 52 ), 53 Case( 54 "Delete with order", 55 table.Delete(). 56 Where(Col(table, "F_a").Eq(1)). 57 DescendBy(Col(table, "F_b")). 58 AscendBy(Col(table, "F_a")). 59 Expr(), 60 Expr( 61 "DELETE FROM `db`.`t` WHERE `F_a` = ? ORDER BY (`F_a`) ASC", 62 1, 63 ), 64 ), 65 }.Run(t, "Stmt delete") 66 }