-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.go
More file actions
67 lines (52 loc) · 1.48 KB
/
executor.go
File metadata and controls
67 lines (52 loc) · 1.48 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
package sqlite
import (
"database/sql"
"github.com/tinywasm/orm"
)
// sqliteExecutor implements orm.Executor and orm.TxExecutor.
type sqliteExecutor struct {
db *sql.DB
}
func (e *sqliteExecutor) Exec(query string, args ...any) error {
_, err := e.db.Exec(query, args...)
return err
}
func (e *sqliteExecutor) QueryRow(query string, args ...any) orm.Scanner {
return e.db.QueryRow(query, args...)
}
func (e *sqliteExecutor) Query(query string, args ...any) (orm.Rows, error) {
return e.db.Query(query, args...)
}
func (e *sqliteExecutor) Close() error {
return e.db.Close()
}
func (e *sqliteExecutor) BeginTx() (orm.TxBoundExecutor, error) {
tx, err := e.db.Begin()
if err != nil {
return nil, err
}
return &sqliteTxExecutor{tx: tx}, nil
}
// sqliteTxExecutor implements orm.TxBoundExecutor.
type sqliteTxExecutor struct {
tx *sql.Tx
}
func (e *sqliteTxExecutor) Exec(query string, args ...any) error {
_, err := e.tx.Exec(query, args...)
return err
}
func (e *sqliteTxExecutor) QueryRow(query string, args ...any) orm.Scanner {
return e.tx.QueryRow(query, args...)
}
func (e *sqliteTxExecutor) Query(query string, args ...any) (orm.Rows, error) {
return e.tx.Query(query, args...)
}
func (e *sqliteTxExecutor) Commit() error {
return e.tx.Commit()
}
func (e *sqliteTxExecutor) Rollback() error {
return e.tx.Rollback()
}
func (e *sqliteTxExecutor) Close() error {
return nil // sql.Tx doesn't have an explicit close outside of Commit/Rollback, but we must implement the interface
}