-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatastore.go
More file actions
94 lines (80 loc) · 2.24 KB
/
datastore.go
File metadata and controls
94 lines (80 loc) · 2.24 KB
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
package goquery
import (
"io"
"github.com/jackc/pgconn"
)
type RecordHandler func(interface{}) error
type BindParamTemplateFunction func(field string, i int) string
type SequenceTemplateFunction func(sequence string) string
type UrlTemplateFunction func(config *RdbmsConfig) string
const (
DEST OutputFormat = iota
JSON
CSV
)
type DbDialect struct {
TableExistsStmt string
Bind BindParamTemplateFunction
Seq SequenceTemplateFunction
Url UrlTemplateFunction
}
type QueryInput struct {
DataSet DataSet
StatementKey string
Statement string
Suffix string
BindParams []interface{}
StmtAppends []interface{}
PanicOnErr bool
LogSql bool
}
type QueryOutput struct {
OutputFormat OutputFormat
Writer io.Writer
Options OutputOptions
rowFunction RowFunction
}
type InsertInput struct {
Dataset DataSet
Records interface{}
Batch bool
BatchSize int
PanicOnErr bool
}
type OutputOptions struct {
ToCamelCase bool
IsArray bool
DateFormat string
OmitNull bool
CsvPrintHeader bool
}
type DataStore interface {
Connection() interface{}
NewTransaction() (Tx, error)
Transaction(tf TransactionFunction) error
Fetch(tx *Tx, input QueryInput, output QueryOutput, dest any) error
FetchRows(tx *Tx, input QueryInput) (Rows, error)
GetJSON(writer io.Writer, input QueryInput, jo OutputOptions) error
GetCSV(input QueryInput, co OutputOptions) (string, error)
Select(stmt ...string) *FluentSelect
Insert(ds DataSet) *FluentInsert
//InsertRecs(ds DataSet, recs interface{}, batch bool, batchSize int, tx *Tx) error
InsertRecs(tx *Tx, input InsertInput) error
//UpdateRecs(ds DataSet, recs interface{}, batch bool, batchSize int, tx *Tx) error
Exec(tx *Tx, stmt string, params ...interface{}) error
Execr(tx *Tx, stmt string, params ...interface{}) (ExecResult, error)
MustExec(tx *Tx, stmt string, params ...interface{})
MustExecr(tx *Tx, stmt string, params ...interface{}) ExecResult
//RecordsetIterator(s Select, handler RecordHandler)
}
type Batch interface {
Queue(stmt string, params ...interface{})
Len() int
}
type BatchResult interface {
Exec() (pgconn.CommandTag, error)
Close() error
}
type ExecResult interface {
RowsAffected() int64
}