-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-repo-execute-logic.go
63 lines (52 loc) · 1.39 KB
/
db-repo-execute-logic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2024.
* Created by Andy Pangaribuan <https://github.com/apangaribuan>.
*
* This product is protected by copyright and distributed under
* licenses restricting copying, distribution and decompilation.
* All Rights Reserved.
*/
package db
import (
"strings"
"github.com/andypangaribuan/gmod/ice"
"github.com/andypangaribuan/gmod/mol"
)
func (slf *stuRepo[T]) delete(tx ice.DbTx, condition string, args []any) *stuRepoResult[T] {
var (
whereQuery = slf.getWhereQuery(condition, args)
endQuery = strings.TrimSpace(slf.getQuery("end-query", args))
fullQuery = slf.getQuery("full-query", args)
report = &stuReport{
tableName: slf.tableName,
insertColumn: slf.insertColumn,
insertArgSign: slf.insertArgSign,
args: slf.getArgs(args),
query: "DELETE FROM ::tableName",
}
)
if whereQuery != "" {
report.query += " " + whereQuery
}
if endQuery != "" {
report.query += " " + endQuery
}
if fullQuery != "" {
report.query = fullQuery
}
var (
err error
execReport *mol.DbExecReport
)
err = report.transform()
if err != nil {
return slf.result(report, err, nil, nil)
}
if tx == nil {
execReport, err = slf.ins.Execute(report.query, report.args...)
} else {
execReport, err = slf.ins.TxExecute(tx, report.query, report.args...)
}
report.execReport = execReport
return slf.result(report, err, nil, nil)
}