-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-func.go
48 lines (39 loc) · 1 KB
/
db-func.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
/*
* 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 "github.com/andypangaribuan/gmod/ice"
func NewRepo[T any](db ice.DbInstance, tableName string, opt ...RepoOptBuilder) Repo[T] {
stu := &stuRepo[T]{
ins: db,
tableName: tableName,
withDeletedAtIsNull: true,
rwFetchWhenNull: true,
}
for _, val := range opt {
v, ok := val.(*stuRepoOptBuilder)
if ok && v != nil {
if v.withDeletedAtIsNull != nil {
stu.withDeletedAtIsNull = *v.withDeletedAtIsNull
}
if v.rwFetchWhenNull != nil {
stu.rwFetchWhenNull = *v.rwFetchWhenNull
}
}
}
return stu
}
func RepoOpt() RepoOptBuilder {
return new(stuRepoOptBuilder)
}
func FetchOpt() FetchOptBuilder {
return new(stuFetchOptBuilder)
}
func Update() UpdateBuilder {
return new(stuUpdateBuilder)
}