reactor sql generation

This commit is contained in:
anqiansong
2020-08-12 09:19:37 +08:00
parent 40895ba8d9
commit f226ffb57c
45 changed files with 892 additions and 1045 deletions

View File

@@ -1,17 +1,17 @@
package sqltemplate
package template
var Delete = `
func (m *{{.upperObject}}Model) Delete({{.lowerPrimaryKey}} {{.dataType}}) error {
{{if .containsCache}}{{if .isNotPrimaryKey}}data,err:=m.FindOne({{.lowerPrimaryKey}})
func (m *{{.upperStartCamelObject}}Model) Delete({{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
{{if .withCache}}{{if .containsIndexCache}}data,err:=m.FindOne({{.lowerStartCamelPrimaryKey}})
if err!=nil{
return err
}{{end}}
{{.keys}}
_, err {{if .isNotPrimaryKey}}={{else}}:={{end}} m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
query := ` + "`" + `delete from ` + "` +" + ` m.table + ` + " `" + ` where {{.snakePrimaryKey}} = ?` + "`" + `
return conn.Exec(query, {{.lowerPrimaryKey}})
}, {{.keyValues}}){{else}}query := ` + "`" + `delete from ` + "` +" + ` m.table + ` + " `" + ` where {{.snakePrimaryKey}} = ?` + "`" + `
_,err:=m.ExecNoCache(query, {{.lowerPrimaryKey}}){{end}}
_, err {{if .containsIndexCache}}={{else}}:={{end}} m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
query := ` + "`" + `delete from ` + "` +" + ` m.table + ` + " `" + ` where {{.originalPrimaryKey}} = ?` + "`" + `
return conn.Exec(query, {{.lowerStartCamelPrimaryKey}})
}, {{.keyValues}}){{else}}query := ` + "`" + `delete from ` + "` +" + ` m.table + ` + " `" + ` where {{.originalPrimaryKey}} = ?` + "`" + `
_,err:=m.ExecNoCache(query, {{.lowerStartCamelPrimaryKey}}){{end}}
return err
}
`