Documentation
¶
Index ¶
- Variables
- func ToJSON(rows *sql.Rows) ([]byte, error)
- func Unmarshal(rows *sql.Rows, v interface{}) error
- func UnmarshalWithMetrics(r metrics.Recorder, rows *sql.Rows, v interface{}) error
- type AsyncMockDB
- func (db *AsyncMockDB) AssertNoCalls()
- func (db *AsyncMockDB) Exec(ctx context.Context, q string, args ...interface{}) (sql.Result, error)
- func (db *AsyncMockDB) ExecWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) (sql.Result, error)
- func (db *AsyncMockDB) Fetch(ctx context.Context, q string, c interface{}, args ...interface{}) error
- func (db *AsyncMockDB) FetchJSON(ctx context.Context, q string, args ...interface{}) ([]byte, error)
- func (db *AsyncMockDB) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) ([]byte, error)
- func (db *AsyncMockDB) FetchWithMetrics(ctx context.Context, r metrics.Recorder, q string, c interface{}, ...) error
- func (db *AsyncMockDB) Ping(ctx context.Context) error
- func (db *AsyncMockDB) Shutdown(ctx context.Context) error
- func (db *AsyncMockDB) Stats(context.Context) sql.DBStats
- type Builder
- func (b *Builder) AddToArgs(vals ...interface{}) *Builder
- func (b *Builder) BuildWhere(join string) string
- func (b *Builder) WhereDistinct(field string, val interface{}) *Builder
- func (b *Builder) WhereExact(field string, val interface{}) *Builder
- func (b *Builder) WhereGreater(field string, val interface{}) *Builder
- func (b *Builder) WhereGreaterEq(field string, val interface{}) *Builder
- func (b *Builder) WhereIn(field string, vals ...interface{}) *Builder
- func (b *Builder) WhereLess(field string, val interface{}) *Builder
- func (b *Builder) WhereLessEq(field string, val interface{}) *Builder
- func (b *Builder) WhereLike(field string, vals ...string) *Builder
- func (b *Builder) WhereNotDistinct(field string, val interface{}) *Builder
- func (b *Builder) WhereNotExact(field string, val interface{}) *Builder
- func (b *Builder) WhereNotIn(field string, vals ...interface{}) *Builder
- func (b *Builder) WhereNotLike(field string, vals ...string) *Builder
- func (b *Builder) WhereNotNull(field string) *Builder
- func (b *Builder) WhereNull(field string) *Builder
- type DBResult
- type Database
- type Dialect
- type Executer
- type Fetcher
- type JSONApi
- func (j *JSONApi) Fetch(ctx context.Context, requestURI string, container interface{}, ...) error
- func (j *JSONApi) FetchJSON(ctx context.Context, requestURI string, args ...interface{}) ([]byte, error)
- func (j *JSONApi) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, requestURI string, ...) ([]byte, error)
- func (j *JSONApi) FetchWithMetrics(ctx context.Context, r metrics.Recorder, requestURI string, ...) error
- func (j *JSONApi) Ping(ctx context.Context) error
- type JSONFetcher
- type Join
- type MSSQLDatastore
- func (m *MSSQLDatastore) BeginTx(ctx context.Context) (Transaction, error)
- func (m *MSSQLDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (m *MSSQLDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
- func (m *MSSQLDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
- func (m *MSSQLDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
- func (m *MSSQLDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
- func (m *MSSQLDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, ...) error
- func (m *MSSQLDatastore) Ping(ctx context.Context) error
- func (m *MSSQLDatastore) Shutdown(context.Context) error
- func (m *MSSQLDatastore) Stats(context.Context) sql.DBStats
- type MSSQLTx
- func (m *MSSQLTx) Commit() error
- func (m *MSSQLTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (m *MSSQLTx) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
- func (m *MSSQLTx) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
- func (m *MSSQLTx) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
- func (m *MSSQLTx) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
- func (m *MSSQLTx) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, ...) error
- func (m *MSSQLTx) Ping(ctx context.Context) error
- func (m *MSSQLTx) Rollback() error
- func (*MSSQLTx) Shutdown(context.Context) error
- func (*MSSQLTx) Stats(context.Context) sql.DBStats
- type MockDB
- func (db *MockDB) AssertNoCalls()
- func (db *MockDB) Exec(ctx context.Context, q string, args ...interface{}) (sql.Result, error)
- func (db *MockDB) ExecWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) (sql.Result, error)
- func (db *MockDB) Fetch(ctx context.Context, q string, c interface{}, args ...interface{}) error
- func (db *MockDB) FetchJSON(ctx context.Context, q string, args ...interface{}) ([]byte, error)
- func (db *MockDB) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) ([]byte, error)
- func (db *MockDB) FetchWithMetrics(ctx context.Context, r metrics.Recorder, q string, c interface{}, ...) error
- func (db *MockDB) OnConsecutiveFetch(fc []DBResult)
- func (db *MockDB) Ping(context.Context) error
- func (db *MockDB) Shutdown(context.Context) error
- func (db *MockDB) Stats(context.Context) sql.DBStats
- type MySQLDatastore
- func (m *MySQLDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (m *MySQLDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
- func (m *MySQLDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
- func (m *MySQLDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
- func (m *MySQLDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
- func (m *MySQLDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, ...) error
- func (m *MySQLDatastore) Ping(ctx context.Context) error
- func (m *MySQLDatastore) Shutdown(context.Context) error
- func (m *MySQLDatastore) Stats(context.Context) sql.DBStats
- type Pinger
- type PostgresDatastore
- func (p *PostgresDatastore) BeginTx(ctx context.Context) (Transaction, error)
- func (p *PostgresDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (p *PostgresDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
- func (p *PostgresDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
- func (p *PostgresDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
- func (p *PostgresDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
- func (p *PostgresDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, ...) error
- func (p *PostgresDatastore) Ping(ctx context.Context) error
- func (p *PostgresDatastore) Shutdown(context.Context) error
- func (p *PostgresDatastore) Stats(context.Context) sql.DBStats
- type PostgresTx
- func (p *PostgresTx) Commit() error
- func (p *PostgresTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (p *PostgresTx) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
- func (p *PostgresTx) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
- func (p *PostgresTx) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
- func (p *PostgresTx) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
- func (p *PostgresTx) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, ...) error
- func (p *PostgresTx) Ping(ctx context.Context) error
- func (p *PostgresTx) Rollback() error
- func (*PostgresTx) Shutdown(context.Context) error
- func (*PostgresTx) Stats(context.Context) sql.DBStats
- type SQLResult
- type SQLiteDatastore
- func (s *SQLiteDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (s *SQLiteDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
- func (s *SQLiteDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
- func (s *SQLiteDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
- func (s *SQLiteDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
- func (s *SQLiteDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, ...) error
- func (s *SQLiteDatastore) Ping(ctx context.Context) error
- func (s *SQLiteDatastore) Shutdown(context.Context) error
- func (s *SQLiteDatastore) Stats(context.Context) sql.DBStats
- type Transaction
- type TransactionDB
Constants ¶
This section is empty.
Variables ¶
var ( // QueryLimit is a hard timeout on the amount of time a query is allowed to run. // QueryLimit is exported so that an application can adjust it to fit their needs. QueryLimit = 5 * time.Minute ErrEmptyObject = errors.New("godb empty object") )
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
Types ¶
type AsyncMockDB ¶ added in v1.0.6
type AsyncMockDB struct { FetchPointer int FetchCount int FetchJSONPointer int FetchJSONCount int ExecPointer int ExecCount int CallCount int Expected []DBResult // contains filtered or unexported fields }
AsyncMockDB implements the Database interface and allows for database mocking. AsyncMockDB checks THAT a query executes, but does not say that it happens in any order. If you need to assert that your queries happen in order, use MockDB
func NewAsyncMockDB ¶ added in v1.0.6
func NewAsyncMockDB(t *testing.T) *AsyncMockDB
NewAsyncMockDB returns a ready to use AsyncMockDB struct.
func (*AsyncMockDB) AssertNoCalls ¶ added in v1.0.6
func (db *AsyncMockDB) AssertNoCalls()
AssertNoCalls asserts that there were no Fetch or Exec calls.
func (*AsyncMockDB) Exec ¶ added in v1.0.6
Exec allows for mocking the response from an exec request.
func (*AsyncMockDB) ExecWithMetrics ¶ added in v1.0.6
func (db *AsyncMockDB) ExecWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) (sql.Result, error)
ExecWithMetrics mocks ExecWithMetrics by simply ignoring the metrics during the unittest. This allows ExecWithMetrics to work exactly as Exec does during a unit test.
func (*AsyncMockDB) Fetch ¶ added in v1.0.6
func (db *AsyncMockDB) Fetch(ctx context.Context, q string, c interface{}, args ...interface{}) error
Fetch allows for mocking the response from a fetch request.
func (*AsyncMockDB) FetchJSON ¶ added in v1.0.6
func (db *AsyncMockDB) FetchJSON(ctx context.Context, q string, args ...interface{}) ([]byte, error)
FetchJSON allows for mocking the response from a fetch request.
func (*AsyncMockDB) FetchJSONWithMetrics ¶ added in v1.0.6
func (db *AsyncMockDB) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics mocks FetchJSONWithMetrics by simply ignoring the metrics during the unittest. This allows FetchJSONWithMetrics to work exactly as FetchJSON does during a unit test.
func (*AsyncMockDB) FetchWithMetrics ¶ added in v1.0.6
func (db *AsyncMockDB) FetchWithMetrics(ctx context.Context, r metrics.Recorder, q string, c interface{}, args ...interface{}) error
FetchWithMetrics mocks FetchWithMetrics by simply ignoring the metrics during the unittest. This allows FetchWithMetrics to work exactly as Fetch does during a unit test.
func (*AsyncMockDB) Ping ¶ added in v1.0.6
func (db *AsyncMockDB) Ping(ctx context.Context) error
Ping satisfies the Database interface.
type Builder ¶ added in v1.0.27
func NewBuilder ¶ added in v1.0.20
func (*Builder) AddToArgs ¶ added in v1.0.27
AddToArgs simply adds additional parameters to the Args array. This will have an impact on the bound parameter count of any subsequent WHERE clauses added. This is useful for things like subqueries where you're not directly matching against a single field.
func (*Builder) BuildWhere ¶ added in v1.0.27
BuildWhere just joins all the where strings. Join should be AND or OR
func (*Builder) WhereDistinct ¶ added in v1.0.27
WhereDistinct adds to the where clause a term that requires the value in the given field to be distinct from the given value. Note that depending on your use case, you may need to cast your val to be what you expect. e.g. casting a bool to an int.
func (*Builder) WhereExact ¶ added in v1.0.27
WhereExact adds to the where clause a term that requires the value in the given field to exactly match the given value. If you want to LOWER your field for matching, wrap the field name in LOWER() when passing it in (mssql, psql)
func (*Builder) WhereGreater ¶ added in v1.0.27
WhereGreater adds to the where clause a term that requires the value in the given field is greater than the value.
func (*Builder) WhereGreaterEq ¶ added in v1.0.27
WhereGreaterEq adds to the where clause a term that requires the value in the given field is greater than or equal to the value.
func (*Builder) WhereIn ¶ added in v1.0.27
WhereIn adds to the where clause a term that requires that the values in the given field exactly match one or more of the values given. If you want to LOWER your field for matching, wrap the field name in LOWER() when passing it in (mssql, psql).
func (*Builder) WhereLess ¶ added in v1.0.27
WhereLess adds to the where clause a term that requires the value in the given field is less than the value.
func (*Builder) WhereLessEq ¶ added in v1.0.27
WhereLessEq adds to the where clause a term that requires the value in the given field is less than or equal to the value.
func (*Builder) WhereLike ¶ added in v1.0.27
WhereLike adds to the where clause a term that requires the value in the given field to at least partially match the values given. If you want to LOWER your field for matching, wrap the field name in LOWER() when passing it in (mssql, psql).
func (*Builder) WhereNotDistinct ¶ added in v1.0.27
WhereNotDistinct adds to the where clause a term that requires the value in the given field to be NOT distinct from the given value. Note that depending on your use case, you may need to cast your val to be what you expect. e.g. casting a bool to an int.
func (*Builder) WhereNotExact ¶ added in v1.0.27
WhereExact adds to the where clause a term that requires the value in the given field to NOT exactly match the given. If you want to LOWER your field for matching, wrap the field name in LOWER() when passing it in (mssql, psql).
func (*Builder) WhereNotIn ¶ added in v1.0.27
WhereNotIn adds to the where clause a term that requires that the values in the given field exactly match none of the values given. If you want to LOWER your field for matching, wrap the field name in LOWER() when passing it in (mssql, psql).
func (*Builder) WhereNotLike ¶ added in v1.0.27
WhereNotLike adds to the where clause a term that requires that the value in the field does NOT partially match the values given. If you want to LOWER your field for matching, wrap the field name in LOWER() when passing it in (mssql, psql).
func (*Builder) WhereNotNull ¶ added in v1.0.27
WhereNotNull adds to the where clause a term that requires the value in the given field is not null.
type DBResult ¶ added in v1.0.6
type DBResult struct { Query string Args []interface{} Content []byte Error error Result SQLResult }
DBResult allows Exec/Fetch responses to be crafted.
type Database ¶
type Database interface { Shutdown(context.Context) error Pinger // contains filtered or unexported methods }
Database implements an interface for interacting with a database.
type Executer ¶ added in v1.0.6
type Executer interface { Pinger // contains filtered or unexported methods }
type Fetcher ¶ added in v1.0.6
type Fetcher interface { Pinger // contains filtered or unexported methods }
type JSONApi ¶ added in v1.0.8
type JSONApi struct {
// contains filtered or unexported fields
}
JSONApi is an implementation of the Fetcher and JSONFetcher interfaces()
func NewJSONApi ¶ added in v1.0.8
NewJSONApi configures and returns a usable JSONApi with a baseURL and pingPath. baseURL should include an appropriate scheme and hostname. pingPath is the path relative to the baseURL that can be used to verify the API is reachable; pingPath should always return an HTTP 200 OK status
func (*JSONApi) Fetch ¶ added in v1.0.8
func (j *JSONApi) Fetch(ctx context.Context, requestURI string, container interface{}, args ...interface{}) error
Fetch makes a request to baseURL/requestURI. RequestURI should be the full relative path + query string. Any args passed in will be passed to fmt.Sprintf(requestURI, args...)
func (*JSONApi) FetchJSON ¶ added in v1.0.8
func (j *JSONApi) FetchJSON(ctx context.Context, requestURI string, args ...interface{}) ([]byte, error)
FetchJSON makes a request to baseURL/requestURI. RequestURI should be the full relative path + query string. Any args passed in will be passed to fmt.Sprintf(requestURI, args...)
func (*JSONApi) FetchJSONWithMetrics ¶ added in v1.0.8
func (j *JSONApi) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, requestURI string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics makes a request to baseURL/requestURI. RequestURI should be the full relative path + query string. Any args passed in will be passed to fmt.Sprintf(requestURI, args...)
func (*JSONApi) FetchWithMetrics ¶ added in v1.0.8
func (j *JSONApi) FetchWithMetrics(ctx context.Context, r metrics.Recorder, requestURI string, container interface{}, args ...interface{}) error
Fetch makes a request to baseURL/requestURI. RequestURI should be the full relative path + query string. Any args passed in will be passed to fmt.Sprintf(requestURI, args...)
type JSONFetcher ¶ added in v1.0.6
type JSONFetcher interface { Pinger // contains filtered or unexported methods }
type MSSQLDatastore ¶
type MSSQLDatastore struct {
// contains filtered or unexported fields
}
MSSQLDatastore is an implementation of MSSQLDatastore datastore for golang.
func NewMSSQLDatastore ¶
func NewMSSQLDatastore(user, pass, dbName, host, port, appname string, maxOpen, maxIdle int) *MSSQLDatastore
NewMSSQLDatastore configures and returns a usable MSSQLDatastore from parameters.
func NewMSSQLDatastoreCS ¶
func NewMSSQLDatastoreCS(connectString string, maxOpen, maxIdle int) *MSSQLDatastore
NewMSSQLDatastoreCS configures and returns a usable MSSQLDatastore from a connect string.
func (*MSSQLDatastore) BeginTx ¶ added in v1.0.26
func (m *MSSQLDatastore) BeginTx(ctx context.Context) (Transaction, error)
Begin starts a single transaction. You MUST call Transaction.Rollback, or Transaction.Commit after calling Begin, or you WILL leak memory. It is safe to defer Transaction.Rollback immediately, even if you don't intend to rollback. Once you Commit, Rollback becomes a no-op.
func (*MSSQLDatastore) Exec ¶
func (m *MSSQLDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*MSSQLDatastore) ExecWithMetrics ¶ added in v1.0.6
func (m *MSSQLDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
ExecWithMetrics provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*MSSQLDatastore) Fetch ¶
func (m *MSSQLDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
Fetch provides a simple query-and-get operation. We will run your query and fill your container.
func (*MSSQLDatastore) FetchJSON ¶
func (m *MSSQLDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
FetchJSON provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*MSSQLDatastore) FetchJSONWithMetrics ¶ added in v1.0.6
func (m *MSSQLDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*MSSQLDatastore) FetchWithMetrics ¶ added in v1.0.6
func (m *MSSQLDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, args ...interface{}) error
FetchWithMetrics provides a simple query-and-get operation. We will run your query and fill your container.
func (*MSSQLDatastore) Ping ¶
func (m *MSSQLDatastore) Ping(ctx context.Context) error
Ping sends a ping to the server and returns an error if it cannot connect.
type MSSQLTx ¶ added in v1.0.24
type MSSQLTx struct {
// contains filtered or unexported fields
}
MSSQLTx implements the Transaction interface.
func (*MSSQLTx) Exec ¶ added in v1.0.24
Exec provides a simple no-return-expected query as part of a transaction. We will run your query and send you on your way. Great for inserts and updates.
func (*MSSQLTx) ExecWithMetrics ¶ added in v1.0.24
func (m *MSSQLTx) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
ExecWithMetrics provides a simple no-return-expected query as part of a transaction. We will run your query and send you on your way. Great for inserts and updates.
func (*MSSQLTx) Fetch ¶ added in v1.0.24
func (m *MSSQLTx) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
Fetch provides a simple query-and-get operation as part of a transaction. We will run your query and fill your container.
func (*MSSQLTx) FetchJSON ¶ added in v1.0.25
FetchJSON provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*MSSQLTx) FetchJSONWithMetrics ¶ added in v1.0.25
func (m *MSSQLTx) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*MSSQLTx) FetchWithMetrics ¶ added in v1.0.24
func (m *MSSQLTx) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, args ...interface{}) error
FetchWithMetrics provides a simple query-and-get operation as part of a transaction. We will run your query and fill your container.
func (*MSSQLTx) Ping ¶ added in v1.0.25
Ping sends a ping to the server and returns an error if it cannot connect.
type MockDB ¶ added in v1.0.6
type MockDB struct { FetchPointer int FetchExpected []DBResult FetchCount int FetchJSONPointer int FetchJSONExpected []DBResult FetchJSONCount int ExecPointer int ExecExpected []DBResult ExecCount int // contains filtered or unexported fields }
MockDB implements the Database interface and allows for database mocking.
func (*MockDB) AssertNoCalls ¶ added in v1.0.6
func (db *MockDB) AssertNoCalls()
AssertNoCalls asserts that there were no Fetch or Exec calls.
func (*MockDB) ExecWithMetrics ¶ added in v1.0.6
func (db *MockDB) ExecWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) (sql.Result, error)
ExecWithMetrics mocks ExecWithMetrics by simply ignoring the metrics during the unittest. This allows ExecWithMetrics to work exactly as Exec does during a unit test.
func (*MockDB) FetchJSON ¶ added in v1.0.6
FetchJSON allows for mocking the response from a fetch request.
func (*MockDB) FetchJSONWithMetrics ¶ added in v1.0.6
func (db *MockDB) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, q string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics mocks FetchJSONWithMetrics by simply ignoring the metrics during the unittest. This allows FetchJSONWithMetrics to work exactly as FetchJSON does during a unit test.
func (*MockDB) FetchWithMetrics ¶ added in v1.0.6
func (db *MockDB) FetchWithMetrics(ctx context.Context, r metrics.Recorder, q string, c interface{}, args ...interface{}) error
FetchWithMetrics mocks FetchWithMetrics by simply ignoring the metrics during the unittest. This allows FetchWithMetrics to work exactly as Fetch does during a unit test.
func (*MockDB) OnConsecutiveFetch ¶ added in v1.0.6
OnConsecutiveFetch returns the next defined value each time one of the fetch functions is called.
type MySQLDatastore ¶ added in v1.0.4
type MySQLDatastore struct {
// contains filtered or unexported fields
}
MySQLDatastore is an implementation of MySQLSQL datastore for golang.
func NewMySQLDatastore ¶ added in v1.0.4
func NewMySQLDatastore(user, pass, dbName, host, port string, maxOpen, maxIdle int) *MySQLDatastore
NewMySQLDatastore configures and returns a usable MySQLDatastore from parameters.
func NewMySQLDatastoreCS ¶ added in v1.0.4
func NewMySQLDatastoreCS(connectString string, maxOpen, maxIdle int) *MySQLDatastore
NewMySQLDatastoreCS configures and returns a usable MySQLDatastore from a connect string.
func (*MySQLDatastore) Exec ¶ added in v1.0.4
func (m *MySQLDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*MySQLDatastore) ExecWithMetrics ¶ added in v1.0.6
func (m *MySQLDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
ExecWithMetrics provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*MySQLDatastore) Fetch ¶ added in v1.0.4
func (m *MySQLDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
Fetch provides a simple query-and-get operation. We will run your query and fill your container.
func (*MySQLDatastore) FetchJSON ¶ added in v1.0.4
func (m *MySQLDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
FetchJSON provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*MySQLDatastore) FetchJSONWithMetrics ¶ added in v1.0.6
func (m *MySQLDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*MySQLDatastore) FetchWithMetrics ¶ added in v1.0.6
func (m *MySQLDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, args ...interface{}) error
FetchWithMetrics provides a simple query-and-get operation. We will run your query and fill your container.
func (*MySQLDatastore) Ping ¶ added in v1.0.4
func (m *MySQLDatastore) Ping(ctx context.Context) error
Ping sends a ping to the server and returns an error if it cannot connect.
type PostgresDatastore ¶
type PostgresDatastore struct {
// contains filtered or unexported fields
}
PostgresDatastore is an implementation of PostgresSQL datastore for golang.
func NewPostgresDatastore ¶
func NewPostgresDatastore(user, pass, dbName, host, port string, maxOpen, maxIdle int) *PostgresDatastore
NewPostgresDatastore configures and returns a usable PostgresDatastore from parameters.
func NewPostgresDatastoreCS ¶
func NewPostgresDatastoreCS(connectString string, maxOpen, maxIdle int) *PostgresDatastore
NewPostgresDatastoreCS configures and returns a usable PostgresDatastore from a connect string.
func (*PostgresDatastore) BeginTx ¶ added in v1.0.14
func (p *PostgresDatastore) BeginTx(ctx context.Context) (Transaction, error)
Begin starts a single transaction. You MUST call Transaction.Rollback, or Transaction.Commit after calling Begin, or you WILL leak memory. It is safe to defer Transaction.Rollback immediately, even if you don't intend to rollback. Once you Commit, Rollback becomes a no-op.
func (*PostgresDatastore) Exec ¶
func (p *PostgresDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*PostgresDatastore) ExecWithMetrics ¶ added in v1.0.6
func (p *PostgresDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
ExecWithMetrics provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*PostgresDatastore) Fetch ¶
func (p *PostgresDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
Fetch provides a simple query-and-get operation. We will run your query and fill your container.
func (*PostgresDatastore) FetchJSON ¶
func (p *PostgresDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
FetchJSON provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*PostgresDatastore) FetchJSONWithMetrics ¶ added in v1.0.6
func (p *PostgresDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*PostgresDatastore) FetchWithMetrics ¶ added in v1.0.6
func (p *PostgresDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, args ...interface{}) error
FetchWithMetrics provides a simple query-and-get operation. We will run your query and fill your container.
func (*PostgresDatastore) Ping ¶
func (p *PostgresDatastore) Ping(ctx context.Context) error
Ping sends a ping to the server and returns an error if it cannot connect.
type PostgresTx ¶ added in v1.0.14
type PostgresTx struct {
// contains filtered or unexported fields
}
PostgresTx implements the Transaction interface.
func (*PostgresTx) Commit ¶ added in v1.0.14
func (p *PostgresTx) Commit() error
Commit commits the transaction
func (*PostgresTx) Exec ¶ added in v1.0.14
func (p *PostgresTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec provides a simple no-return-expected query as part of a transaction. We will run your query and send you on your way. Great for inserts and updates.
func (*PostgresTx) ExecWithMetrics ¶ added in v1.0.14
func (p *PostgresTx) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
ExecWithMetrics provides a simple no-return-expected query as part of a transaction. We will run your query and send you on your way. Great for inserts and updates.
func (*PostgresTx) Fetch ¶ added in v1.0.14
func (p *PostgresTx) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
Fetch provides a simple query-and-get operation as part of a transaction. We will run your query and fill your container.
func (*PostgresTx) FetchJSON ¶ added in v1.0.25
func (p *PostgresTx) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
FetchJSON provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*PostgresTx) FetchJSONWithMetrics ¶ added in v1.0.25
func (p *PostgresTx) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*PostgresTx) FetchWithMetrics ¶ added in v1.0.14
func (p *PostgresTx) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, args ...interface{}) error
FetchWithMetrics provides a simple query-and-get operation as part of a transaction. We will run your query and fill your container.
func (*PostgresTx) Ping ¶ added in v1.0.25
func (p *PostgresTx) Ping(ctx context.Context) error
Ping sends a ping to the server and returns an error if it cannot connect.
func (*PostgresTx) Rollback ¶ added in v1.0.14
func (p *PostgresTx) Rollback() error
Rollback commits the transaction
type SQLResult ¶ added in v1.0.6
SQLResult allows Exec responses to be crafted.
func (*SQLResult) LastInsertId ¶ added in v1.0.6
LastInsertId returns the id of the last inserted row.
func (*SQLResult) RowsAffected ¶ added in v1.0.6
RowsAffected returns the number of rows affected by an exec query.
type SQLiteDatastore ¶
type SQLiteDatastore struct {
// contains filtered or unexported fields
}
SQLiteDatastore is an implementation of SQLiteSQL datastore for golang.
func NewSQLiteDatastore ¶
func NewSQLiteDatastore(file string, maxOpen, maxIdle int) *SQLiteDatastore
NewSQLiteDatastore configures and returns a usable SQLiteDatastore
func (*SQLiteDatastore) Exec ¶
func (s *SQLiteDatastore) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*SQLiteDatastore) ExecWithMetrics ¶ added in v1.0.6
func (s *SQLiteDatastore) ExecWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) (sql.Result, error)
ExecWithMetrics provides a simple no-return-expected query. We will run your query and send you on your way. Great for inserts and updates.
func (*SQLiteDatastore) Fetch ¶
func (s *SQLiteDatastore) Fetch(ctx context.Context, query string, container interface{}, args ...interface{}) error
Fetch provides a simple query-and-get operation. We will run your query and fill your container.
func (*SQLiteDatastore) FetchJSON ¶
func (s *SQLiteDatastore) FetchJSON(ctx context.Context, query string, args ...interface{}) ([]byte, error)
FetchJSON provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*SQLiteDatastore) FetchJSONWithMetrics ¶ added in v1.0.6
func (s *SQLiteDatastore) FetchJSONWithMetrics(ctx context.Context, r metrics.Recorder, query string, args ...interface{}) ([]byte, error)
FetchJSONWithMetrics provides a simple query-and-get operation. We will run your query and give you back the JSON representing your result set.
func (*SQLiteDatastore) FetchWithMetrics ¶ added in v1.0.6
func (s *SQLiteDatastore) FetchWithMetrics(ctx context.Context, r metrics.Recorder, query string, container interface{}, args ...interface{}) error
FetchWithMetrics provides a simple query-and-get operation. We will run your query and fill your container.
func (*SQLiteDatastore) Ping ¶
func (s *SQLiteDatastore) Ping(ctx context.Context) error
Ping sends a ping to the server and returns an error if it cannot connect.
type Transaction ¶ added in v1.0.14
type TransactionDB ¶ added in v1.0.14
type TransactionDB interface { BeginTx(context.Context) (Transaction, error) Database }