-
Notifications
You must be signed in to change notification settings - Fork 0
/
querier.go
57 lines (48 loc) · 2.37 KB
/
querier.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
56
57
package sqltx
import (
"context"
"database/sql"
)
// Querier interface can be used in helper functions that can take either a
// transaction or a database connection
type Querier interface {
// PrepareContext creates a prepared statement for later queries or executions.
// Multiple queries or executions may be run concurrently from the
// returned statement.
// The caller must call the statement's Close method
// when the statement is no longer needed.
//
// The provided context is used for the preparation of the statement, not for the
// execution of the statement.
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
// Prepare creates a prepared statement for later queries or executions.
// Multiple queries or executions may be run concurrently from the
// returned statement.
// The caller must call the statement's Close method
// when the statement is no longer needed.
Prepare(query string) (*sql.Stmt, error)
// ExecContext executes a query that doesn't return rows.
// For example: an INSERT and UPDATE.
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// Exec executes a query that doesn't return rows.
// For example: an INSERT and UPDATE.
Exec(query string, args ...interface{}) (sql.Result, error)
// QueryContext executes a query that returns rows, typically a SELECT.
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
// Query executes a query that returns rows, typically a SELECT.
Query(query string, args ...interface{}) (*sql.Rows, error)
// QueryRowContext executes a query that is expected to return at most one row.
// QueryRowContext always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
// QueryRow executes a query that is expected to return at most one row.
// QueryRow always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
QueryRow(query string, args ...interface{}) *sql.Row
}