-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutation.go
54 lines (46 loc) · 1.35 KB
/
mutation.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
/*
Package spnr provides the orm for Cloud Spanner.
*/
package spnr
import (
"context"
)
// DML offers ORM with Mutation API.
// It also contains read operations (call Reader method.)
type Mutation struct {
table string
logger logger
logEnabled bool
}
// New is alias for NewMutation.
func New(tableName string) *Mutation {
return &Mutation{table: tableName}
}
// NewMutation initializes ORM with Mutation API.
// It also contains read operations (call Reader method of Mutation.)
// If you want to use DML, use NewDML() instead.
func NewMutation(tableName string) *Mutation {
return &Mutation{table: tableName}
}
// NewDMLWithOptions initializes Mutation with options.
// Check Options for the available options.
func NewMutationWithOptions(tableName string, op *Options) *Mutation {
m := &Mutation{table: tableName, logger: op.Logger, logEnabled: op.LogEnabled}
if m.logger == nil {
m.logger = newDefaultLogger()
}
return m
}
// Reader returns Reader struct to call read operations.
func (m *Mutation) Reader(ctx context.Context, tx Transaction) *Reader {
return &Reader{table: m.table, ctx: ctx, tx: tx, logger: m.logger, logEnabled: m.logEnabled}
}
// GetTableName returns table name
func (m *Mutation) GetTableName() string {
return m.table
}
func (m *Mutation) logf(format string, v ...any) {
if m.logEnabled {
m.logger.Printf(format, v...)
}
}