-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.go
76 lines (68 loc) · 1.63 KB
/
delete.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
64
65
66
67
68
69
70
71
72
73
74
75
76
package mysql
import (
"fmt"
"time"
"github.com/codebdy/entify-core/model/data"
"github.com/codebdy/entify-core/shared"
)
func (b *MySQLBuilder) BuildDeleteSQL(id uint64, tableName string) string {
sql := fmt.Sprintf(
"DELETE FROM `%s` WHERE (`%s` = '%d')",
tableName,
"id",
id,
)
return sql
}
func (b *MySQLBuilder) BuildSoftDeleteSQL(id uint64, tableName string) string {
sql := fmt.Sprintf(
"UPDATE `%s` SET `%s` = '%s' WHERE (`%s` = %d)",
tableName,
shared.DELETED_AT,
time.Now(),
"id",
id,
)
return sql
}
func (b *MySQLBuilder) BuildDeletePovitSQL(povit *data.AssociationPovit) string {
return fmt.Sprintf(
"DELETE FROM `%s` WHERE (`%s` = %d AND `%s` = %d)",
povit.Table().Name,
povit.Source.Column.Name,
povit.Source.Value,
povit.Target.Column.Name,
povit.Target.Value,
)
}
func (b *MySQLBuilder) BuildCheckPovitSQL(povit *data.AssociationPovit) string {
return fmt.Sprintf(
"SELECT count(%s) from `%s` WHERE (`%s` = %d AND `%s` = %d)",
povit.Source.Column.Name,
povit.Table().Name,
povit.Source.Column.Name,
povit.Source.Value,
povit.Target.Column.Name,
povit.Target.Value,
)
}
//删除前检查SQL
func (b *MySQLBuilder) BuildCheckAssociationSQL(ownerId uint64, tableName string, ownerFieldName string) string {
sql := fmt.Sprintf(
"SELECT count(%s) FROM `%s` WHERE (`%s` = '%d')",
ownerFieldName,
tableName,
ownerFieldName,
ownerId,
)
return sql
}
func (b *MySQLBuilder) BuildClearAssociationSQL(ownerId uint64, tableName string, ownerFieldName string) string {
sql := fmt.Sprintf(
"DELETE FROM `%s` WHERE (`%s` = '%d')",
tableName,
ownerFieldName,
ownerId,
)
return sql
}