godb

package module
v1.0.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 25 Imported by: 2

README

GoDB

An experiment in simple database access without a lot of bells and whistles. Sometimes, you just want to fetch some rows and dump them into a struct.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func ToJSON

func ToJSON(rows *sql.Rows) ([]byte, error)

ToJSON extracts a given SQL Rows result as json.

func Unmarshal

func Unmarshal(rows *sql.Rows, v interface{}) error

Unmarshal extracts a given SQL Rows result into a given container.

func UnmarshalWithMetrics added in v1.0.6

func UnmarshalWithMetrics(r metrics.Recorder, rows *sql.Rows, v interface{}) error

UnmarshalWithMetrics extracts a given SQL Rows result into a given container.

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

func (db *AsyncMockDB) Exec(ctx context.Context, q string, args ...interface{}) (sql.Result, error)

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.

func (*AsyncMockDB) Shutdown added in v1.0.6

func (db *AsyncMockDB) Shutdown(ctx context.Context) error

Shutdown satisfies the Database interface.

func (*AsyncMockDB) Stats added in v1.0.16

func (db *AsyncMockDB) Stats(context.Context) sql.DBStats

Stats satisfies the Database interface.

type Builder added in v1.0.27

type Builder struct {
	Dialect Dialect

	Where []string
	Args  []interface{}
}

func NewBuilder added in v1.0.20

func NewBuilder(d Dialect) *Builder

func (*Builder) AddToArgs added in v1.0.27

func (b *Builder) AddToArgs(vals ...interface{}) *Builder

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

func (b *Builder) BuildWhere(join string) string

BuildWhere just joins all the where strings. Join should be AND or OR

func (*Builder) WhereDistinct added in v1.0.27

func (b *Builder) WhereDistinct(field string, val interface{}) *Builder

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

func (b *Builder) WhereExact(field string, val interface{}) *Builder

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

func (b *Builder) WhereGreater(field string, val interface{}) *Builder

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

func (b *Builder) WhereGreaterEq(field string, val interface{}) *Builder

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

func (b *Builder) WhereIn(field string, vals ...interface{}) *Builder

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

func (b *Builder) WhereLess(field string, val interface{}) *Builder

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

func (b *Builder) WhereLessEq(field string, val interface{}) *Builder

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

func (b *Builder) WhereLike(field string, vals ...string) *Builder

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

func (b *Builder) WhereNotDistinct(field string, val interface{}) *Builder

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

func (b *Builder) WhereNotExact(field string, val interface{}) *Builder

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

func (b *Builder) WhereNotIn(field string, vals ...interface{}) *Builder

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

func (b *Builder) WhereNotLike(field string, vals ...string) *Builder

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

func (b *Builder) WhereNotNull(field string) *Builder

WhereNotNull adds to the where clause a term that requires the value in the given field is not null.

func (*Builder) WhereNull added in v1.0.27

func (b *Builder) WhereNull(field string) *Builder

WhereNull adds to the where clause a term that requires the value in the given field is 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 Dialect added in v1.0.20

type Dialect string
const (
	DialectMSSQL    Dialect = "mssql"
	DialectPostgres Dialect = "postgresql"
)

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

func NewJSONApi(baseURL, pingPath string, requestTimeout time.Duration) *JSONApi

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...)

func (*JSONApi) Ping added in v1.0.8

func (j *JSONApi) Ping(ctx context.Context) error

Ping sends a ping to the server and returns an error if it cannot connect.

type JSONFetcher added in v1.0.6

type JSONFetcher interface {
	Pinger
	// contains filtered or unexported methods
}

type Join added in v1.0.20

type Join string

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.

func (*MSSQLDatastore) Shutdown

func (m *MSSQLDatastore) Shutdown(context.Context) error

Shutdown performs any closing operations. Best called as deferred from main after the datastore is initialized.

func (*MSSQLDatastore) Stats added in v1.0.16

Stats returns statistics about the current DB connection.

type MSSQLTx added in v1.0.24

type MSSQLTx struct {
	// contains filtered or unexported fields
}

MSSQLTx implements the Transaction interface.

func (*MSSQLTx) Commit added in v1.0.24

func (m *MSSQLTx) Commit() error

Commit commits the transaction

func (*MSSQLTx) Exec added in v1.0.24

func (m *MSSQLTx) 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 (*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

func (m *MSSQLTx) 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 (*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

func (m *MSSQLTx) Ping(ctx context.Context) error

Ping sends a ping to the server and returns an error if it cannot connect.

func (*MSSQLTx) Rollback added in v1.0.24

func (m *MSSQLTx) Rollback() error

Rollback commits the transaction

func (*MSSQLTx) Shutdown added in v1.0.25

func (*MSSQLTx) Shutdown(context.Context) error

Shutdown has no context during a transaction currently, but is provided to implement the Database interface.

func (*MSSQLTx) Stats added in v1.0.25

func (*MSSQLTx) Stats(context.Context) sql.DBStats

Stats has no context during a transaction currently, but is provided to implement the Database interface.

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 NewMockDB added in v1.0.6

func NewMockDB(t *testing.T) *MockDB

NewMockDB returns a ready to use MockDB struct.

func (*MockDB) AssertNoCalls added in v1.0.6

func (db *MockDB) AssertNoCalls()

AssertNoCalls asserts that there were no Fetch or Exec calls.

func (*MockDB) Exec added in v1.0.6

func (db *MockDB) Exec(ctx context.Context, q string, args ...interface{}) (sql.Result, error)

Exec allows for mocking the response from an exec request.

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) Fetch added in v1.0.6

func (db *MockDB) Fetch(ctx context.Context, q string, c interface{}, args ...interface{}) error

Fetch allows for mocking the response from a fetch request.

func (*MockDB) FetchJSON added in v1.0.6

func (db *MockDB) FetchJSON(ctx context.Context, q string, args ...interface{}) ([]byte, error)

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

func (db *MockDB) OnConsecutiveFetch(fc []DBResult)

OnConsecutiveFetch returns the next defined value each time one of the fetch functions is called.

func (*MockDB) Ping added in v1.0.6

func (db *MockDB) Ping(context.Context) error

Ping satisfies the Database interface.

func (*MockDB) Shutdown added in v1.0.6

func (db *MockDB) Shutdown(context.Context) error

Shutdown satisfies the Database interface.

func (*MockDB) Stats added in v1.0.16

func (db *MockDB) Stats(context.Context) sql.DBStats

Stats satisfies the Database interface.

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.

func (*MySQLDatastore) Shutdown added in v1.0.4

func (m *MySQLDatastore) Shutdown(context.Context) error

Shutdown performs any closing operations. Best called as deferred from main after the datastore is initialized.

func (*MySQLDatastore) Stats added in v1.0.16

Stats returns statistics about the current DB connection.

type Pinger added in v1.0.17

type Pinger interface {
	Ping(context.Context) error
}

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.

func (*PostgresDatastore) Shutdown

func (p *PostgresDatastore) Shutdown(context.Context) error

Shutdown performs any closing operations. Best called as deferred from main after the datastore is initialized.

func (*PostgresDatastore) Stats added in v1.0.16

Stats returns statistics about the current DB connection.

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

func (*PostgresTx) Shutdown added in v1.0.25

func (*PostgresTx) Shutdown(context.Context) error

Shutdown has no context during a transaction currently, but is provided to implement the Database interface.

func (*PostgresTx) Stats added in v1.0.25

Stats has no context during a transaction currently, but is provided to implement the Database interface.

type SQLResult added in v1.0.6

type SQLResult struct {
	Affected    int64
	AffectedErr error
}

SQLResult allows Exec responses to be crafted.

func (*SQLResult) LastInsertId added in v1.0.6

func (r *SQLResult) LastInsertId() (int64, error)

LastInsertId returns the id of the last inserted row.

func (*SQLResult) RowsAffected added in v1.0.6

func (r *SQLResult) RowsAffected() (int64, error)

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.

func (*SQLiteDatastore) Shutdown

func (s *SQLiteDatastore) Shutdown(context.Context) error

Shutdown performs any closing operations. Best called as deferred from main after the datastore is initialized.

func (*SQLiteDatastore) Stats added in v1.0.16

Stats returns statistics about the current DB connection.

type Transaction added in v1.0.14

type Transaction interface {
	Commit() error
	Rollback() error

	Database
}

type TransactionDB added in v1.0.14

type TransactionDB interface {
	BeginTx(context.Context) (Transaction, error)

	Database
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL