forked from go-gorp/gorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgorp_go17.go
54 lines (40 loc) · 1.54 KB
/
gorp_go17.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
// Copyright 2012 James Cooper. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Package gorp provides a simple way to marshal Go structs to and from
// SQL databases. It uses the database/sql package, and should work with any
// compliant database/sql driver.
//
// Source code and project home:
// https://github.com/go-gorp/gorp
//
// +build !go1.8
package gorp
import "database/sql"
// Executor exposes the sql.DB and sql.Tx functions so that it can be used
// on internal functions that need to be agnostic to the underlying object.
type executor interface {
Exec(query string, args ...interface{}) (sql.Result, error)
Prepare(query string) (*sql.Stmt, error)
QueryRow(query string, args ...interface{}) *sql.Row
Query(query string, args ...interface{}) (*sql.Rows, error)
}
func exec(e SqlExecutor, query string, args ...interface{}) (sql.Result, error) {
executor, _ := extractExecutorAndContext(e)
return executor.Exec(query, args...)
}
func prepare(e SqlExecutor, query string) (*sql.Stmt, error) {
executor, _ := extractExecutorAndContext(e)
return executor.Prepare(query)
}
func queryRow(e SqlExecutor, query string, args ...interface{}) *sql.Row {
executor, _ := extractExecutorAndContext(e)
return executor.QueryRow(query, args...)
}
func query(e SqlExecutor, query string, args ...interface{}) (*sql.Rows, error) {
executor, _ := extractExecutorAndContext(e)
return executor.Query(query, args...)
}
func begin(m *DbMap) (*sql.Tx, error) {
return m.Db.Begin()
}