-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction.go
55 lines (54 loc) · 1.37 KB
/
transaction.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
package kin
//
//import (
// "database/sql"
// "errors"
//)
//
//// Transaction is an interface for interacting with a query transaction. It
//// abstracts away managing connection pools and various low-level bits.
//type Transaction[T Model] interface {
// // Commit commits the transaction with the query.
// Commit() error
//
// // Exec runs a query against the query that doesn't return any results.
// Exec(query string, args ...interface{}) error
//
// // Rollback the transaction when an error occurs.
// Rollback() error
//
// // StartTransaction
// StartTransaction() (Transaction[T], error)
//
// // Statement generates a new query to be executed at a later time.
// Query(stmt string, params ...interface{}) *Statement[T]
//}
//
//type transaction[T Model] struct {
// tx *sql.Tx
//}
//
//func (t *transaction[T]) Commit() error {
// return t.tx.Commit()
//}
//
//func (t *transaction[T]) Exec(query string, args ...interface{}) error {
// _, err := t.tx.Exec(query, args...)
// return err
//}
//
//func (t *transaction[T]) Rollback() error {
// return t.tx.Rollback()
//}
//
//func (t *transaction[T]) StartTransaction() (Transaction[T], error) {
// return nil, errors.New("transaction already started")
//}
//
//func (t *transaction[T]) Query(stmt string, params ...interface{}) *Statement[T] {
// return &Statement[T]{
// db: t.tx,
// stmt: stmt,
// params: params,
// }
//}