-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathoptions.go
106 lines (89 loc) · 3.2 KB
/
options.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package pggen
// options.go contains functional options that can be passed to generated code.
type InsertOpt func(opts *InsertOptions)
type InsertOptions struct {
UsePkey bool
DefaultFields FieldSet
DisableTimestamps bool
}
// InsertDisableTimestamps tells an insert method to not
// set the timestamp fields
func InsertDisableTimestamps(opts *InsertOptions) {
opts.DisableTimestamps = true
}
// InsertUsePkey tells an insert method to insert the primary key into the database
// rather than let the database compute it automatically from the default value
// as is the default.
func InsertUsePkey(opts *InsertOptions) {
opts.UsePkey = true
}
// Set the fields that will be generated from the default values stored in the database.
// By default, all field values are inserted based on the provided struct.
// If all fields are specified, only those fields which actually have a default in the
// database are defaulted, other fields are inserted as normal.
func InsertDefaultFields(fieldSet FieldSet) InsertOpt {
return func(opts *InsertOptions) {
opts.DefaultFields = fieldSet
}
}
type UpsertOpt func(opts *UpsertOptions)
type UpsertOptions struct {
UsePkey bool
DefaultFields FieldSet
DisableTimestamps bool
}
// UpsertDisableTimestamps tells an upsert method to not
// set the timestamp fields
func UpsertDisableTimestamps(opts *UpsertOptions) {
opts.DisableTimestamps = true
}
// UpsertUsePkey tells an upsert method to insert the primary key into the database
// rather than let the database compute it automatically from the default value
// as is the default.
func UpsertUsePkey(opts *UpsertOptions) {
opts.UsePkey = true
}
// Set the fields that will be generated from the default values stored in the database.
// By default, all field values are inserted based on the provided struct.
// If all fields are specified, only those fields which actually have a default in the
// database are defaulted, other fields are inserted as normal.
func UpsertDefaultFields(fieldSet FieldSet) UpsertOpt {
return func(opts *UpsertOptions) {
opts.DefaultFields = fieldSet
}
}
type GetOpt func(opts *GetOptions)
type GetOptions struct {
}
type ListOpt func(opts *ListOptions)
type ListOptions struct {
SucceedOnPartialResults bool
}
// ListSucceedOnPartialResults tells a list method to not
// fail if not all requested results are returned
func ListSucceedOnPartialResults(opts *ListOptions) {
opts.SucceedOnPartialResults = true
}
type DeleteOpt func(opts *DeleteOptions)
type DeleteOptions struct {
DoHardDelete bool
}
// DeleteDoHardDelete tells a delete method to delete the data from the database
// even if a `deleted_at` timestamp has been configured for soft deletes. If soft
// deletes have not been configured for the table (via the `deleted_at_field` config
// key), this flag has no effect.
func DeleteDoHardDelete(opts *DeleteOptions) {
opts.DoHardDelete = true
}
type UpdateOpt func(opts *UpdateOptions)
type UpdateOptions struct {
DisableTimestamps bool
}
// UpdateDisableTimestamps tells an update method to not
// set the timestamp fields
func UpdateDisableTimestamps(opts *UpdateOptions) {
opts.DisableTimestamps = true
}
type IncludeOpt func(opts *IncludeOptions)
type IncludeOptions struct {
}