-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.go
More file actions
84 lines (70 loc) · 3.5 KB
/
Copy pathinterfaces.go
File metadata and controls
84 lines (70 loc) · 3.5 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
// interfaces.go
// Core interfaces for Thing ORM: DBAdapter, CacheClient, SQLBuilder, Dialector, etc.
// These are public and intended for use by users and driver developers.
package thing
import (
"context"
"database/sql"
"time"
)
// DBAdapter defines the interface for database drivers.
type DBAdapter interface {
Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
GetCount(ctx context.Context, tableName string, where string, args []interface{}) (int64, error)
BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
Close() error
DB() *sql.DB
Builder() SQLBuilder
DialectName() string
}
// Tx defines the interface for transaction operations.
type Tx interface {
Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Commit() error
Rollback() error
}
// CacheClient defines the interface for cache drivers.
type CacheClient interface {
Get(ctx context.Context, key string) (string, error)
Set(ctx context.Context, key string, value string, expiration time.Duration) error
Delete(ctx context.Context, key string) error
GetModel(ctx context.Context, key string, dest interface{}) error
SetModel(ctx context.Context, key string, model interface{}, fieldsToCache []string, expiration time.Duration) error
DeleteModel(ctx context.Context, key string) error
GetQueryIDs(ctx context.Context, queryKey string) ([]int64, error)
SetQueryIDs(ctx context.Context, queryKey string, ids []int64, expiration time.Duration) error
DeleteQueryIDs(ctx context.Context, queryKey string) error
AcquireLock(ctx context.Context, lockKey string, expiration time.Duration) (bool, error)
ReleaseLock(ctx context.Context, lockKey string) error
Incr(ctx context.Context, key string) (int64, error)
Expire(ctx context.Context, key string, expiration time.Duration) error
GetCacheStats(ctx context.Context) CacheStats
// MGetModel retrieves multiple models from cache in a single batch operation.
// The keys slice and dests slice must have the same length.
// Each dest must be a non-nil pointer to a struct.
// Returns a slice of errors, one per key. ErrNotFound means cache miss.
MGetModel(ctx context.Context, keys []string, dests []interface{}) []error
}
// CacheStats holds cache operation counters for monitoring.
type CacheStats struct {
Counters map[string]int // Operation name to count
}
// Dialector defines how to quote identifiers and bind variables for a specific SQL dialect.
type Dialector interface {
Quote(identifier string) string // Quote a SQL identifier (table/column name)
Placeholder(index int) string // Bind variable placeholder (e.g. ?, $1)
}
// SQLBuilder defines the contract for SQL generation with dialect-specific identifier quoting.
type SQLBuilder interface {
BuildSelectSQL(tableName string, columns []string) string
BuildSelectIDsSQL(tableName string, pkName string, where string, args []interface{}, order string) (string, []interface{})
BuildInsertSQL(tableName string, columns []string) string
BuildUpdateSQL(tableName string, setClauses []string, pkName string) string
BuildDeleteSQL(tableName, pkName string) string
BuildCountSQL(tableName string, whereClause string) string
Rebind(query string) string
}