Documentation ¶
Index ¶
- Constants
- Variables
- func ErrNotFoundInTable(table string) error
- func IsForeignKeyViolation(e error) bool
- func IsUniqueViolation(e error) bool
- func Now() time.Time
- type Context
- type Database
- func (d *Database) Atomic(cxt Context, h TransactionHandler) error
- func (d *Database) Begin() (*sql.Tx, error)
- func (d *Database) Database() *sql.DB
- func (d *Database) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *Database) Migrate() error
- func (d *Database) MigrateToVersion(v int) error
- func (d *Database) MigrationVersion() (int, error)
- func (d *Database) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *Database) QueryRow(query string, args ...interface{}) *sql.Row
- func (d *Database) Transaction(h TransactionHandler) error
- type DebugContext
- type Option
- type Range
- type TransactionHandler
Constants ¶
const ( PG_ERROR_UNIQUE_VIOLATION = "23505" PG_ERROR_FOREIGN_KEY_VIOLATION = "23503" )
Postgres errors from: https://github.com/lib/pq/blob/master/error.go#L78
const ( RESULT_COUNT_MAX = 250 RESULT_COUNT_DEFAULT = 25 CACHE_ELEMENTS_DEFAULT = 1024 )
Variables ¶
var ( ErrNotFound = fmt.Errorf("Not found") ErrTransient = fmt.Errorf("Transient") ErrImmutable = fmt.Errorf("Immutable") ErrInconvertible = fmt.Errorf("Inconvertible") ErrForbidden = fmt.Errorf("Forbidden") ErrInvalidEntity = fmt.Errorf("Invalid Entity") )
var InvalidRange = Range{0, -1}
var ZeroRange = Range{0, 0}
Functions ¶
func ErrNotFoundInTable ¶
func IsForeignKeyViolation ¶
Is the error a Postgres foreign key violation?
func IsUniqueViolation ¶
Is the error a Postgres unique violation?
Types ¶
type Context ¶
type Context interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
An SQL executable context
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
The store client
func (*Database) Atomic ¶
func (d *Database) Atomic(cxt Context, h TransactionHandler) error
Execute in a new transaction and commit or roll-back as necessary on completion if the provided transation is nil. Otherwise, use the provided transaction and assume it is managed externally.
func (*Database) MigrateToVersion ¶
Migrate to a specific version
func (*Database) MigrationVersion ¶
Determine the current migration version
func (*Database) Transaction ¶
func (d *Database) Transaction(h TransactionHandler) error
Execute in a transaction. A transaction is created and the handler is invoked. If the handler returns a non-nil error the transaction is rolled back, otherwise the transaction is committed.
type DebugContext ¶
type DebugContext struct {
// contains filtered or unexported fields
}
A debug context which logs out statements
func NewDebugContextWithPrefix ¶
func NewDebugContextWithPrefix(prefix string, cxt Context) DebugContext
Create a debug context
func (DebugContext) Exec ¶
func (d DebugContext) Exec(query string, args ...interface{}) (sql.Result, error)