Documentation ¶
Index ¶
- func IsConstraintViolationError(err error) bool
- func IsDatabaseError(err error) bool
- func IsDuplicateKeyError(err error) bool
- func IsNetworkError(err error) bool
- func IsNoRowsError(err error) bool
- func IsPostgresURL(rawUrl string) bool
- type Conn
- func (c *Conn) Copy(ctx context.Context, tableName string, columnNames []string, ...) (int64, error)
- func (c *Conn) DB() *Database
- func (c *Conn) Exec(ctx context.Context, sql string, args ...interface{}) (int64, error)
- func (c *Conn) QueryRow(ctx context.Context, sql string, args ...interface{}) Row
- func (c *Conn) QueryRows(ctx context.Context, sql string, args ...interface{}) Rows
- func (c *Conn) WithinTx(ctx context.Context, cb WithinTxCallback) error
- type CopyCallback
- type Database
- func (db *Database) Close()
- func (db *Database) Copy(ctx context.Context, tableName string, columnNames []string, ...) (int64, error)
- func (db *Database) Exec(ctx context.Context, sql string, args ...interface{}) (int64, error)
- func (db *Database) QueryRow(ctx context.Context, sql string, args ...interface{}) Row
- func (db *Database) QueryRows(ctx context.Context, sql string, args ...interface{}) Rows
- func (db *Database) RunMigrations(ctx context.Context, tableName string, cb MigrationStepCallback) error
- func (db *Database) SetEventHandler(handler ErrorHandler)
- func (db *Database) WithinConn(ctx context.Context, cb WithinConnCallback) error
- func (db *Database) WithinTx(ctx context.Context, cb WithinTxCallback) error
- type Error
- type ErrorDetails
- type ErrorHandler
- type MigrationStep
- type MigrationStepCallback
- type NoRowsError
- type Options
- type Row
- type Rows
- type SSLMode
- type ScanRowsCallback
- type Tx
- func (tx *Tx) Copy(ctx context.Context, tableName string, columnNames []string, ...) (int64, error)
- func (tx *Tx) DB() *Database
- func (tx *Tx) Exec(ctx context.Context, sql string, args ...interface{}) (int64, error)
- func (tx *Tx) QueryRow(ctx context.Context, sql string, args ...interface{}) Row
- func (tx *Tx) QueryRows(ctx context.Context, sql string, args ...interface{}) Rows
- func (tx *Tx) WithinTx(ctx context.Context, cb WithinTxCallback) error
- type WithinConnCallback
- type WithinTxCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConstraintViolationError ¶ added in v1.3.1
func IsDatabaseError ¶
IsDatabaseError returns true if the given error object is a database error.
func IsDuplicateKeyError ¶ added in v1.3.1
func IsNetworkError ¶
IsNetworkError returns true if the error is related to a network issue.
func IsNoRowsError ¶
IsNoRowsError returns true if the given error is the result of returning an empty result set.
func IsPostgresURL ¶ added in v1.3.0
IsPostgresURL returns true if the url schema is postgres
Types ¶
type Conn ¶ added in v1.3.0
type Conn struct {
// contains filtered or unexported fields
}
Conn encloses a single connection object.
func (*Conn) Copy ¶ added in v1.3.0
func (c *Conn) Copy(ctx context.Context, tableName string, columnNames []string, callback CopyCallback) (int64, error)
Copy executes a SQL copy query within the single connection.
type CopyCallback ¶
CopyCallback defines a callback that is called for each record being copied to the database
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database represents a PostgreSQL database accessor.
func NewFromURL ¶ added in v1.2.0
NewFromURL creates a new postgresql database driver from an URL
func (*Database) Copy ¶
func (db *Database) Copy(ctx context.Context, tableName string, columnNames []string, callback CopyCallback) (int64, error)
Copy executes a SQL copy query within the transaction.
func (*Database) QueryRow ¶
QueryRow executes a SQL query on a new connection
NOTES: ~~~~~
- Most of the commonly used types in Postgres can be mapped to standard Golang type including time.Time for timestamps (except time with tz which is not supported)
- When reading JSON/JSONB fields, the underlying library (PGX) tries to unmarshall it into the destination variable. In order to just retrieve the json string, add the `::text` suffix to the field in the query.
- To avoid overflows on high uint64 values, store them in NUMERIC(24,0) fields.
- For time-only fields, date is set to Jan 1, 2000 by PGX in time.Time variables.
func (*Database) RunMigrations ¶ added in v1.3.0
func (*Database) SetEventHandler ¶
func (db *Database) SetEventHandler(handler ErrorHandler)
SetEventHandler sets a new error handler callback
func (*Database) WithinConn ¶ added in v1.3.0
func (db *Database) WithinConn(ctx context.Context, cb WithinConnCallback) error
WithinConn executes a callback function within the context of a single connection
type Error ¶
type Error struct { Details *ErrorDetails // contains filtered or unexported fields }
Error is the error type usually returned by us.
func (*Error) IsConstraintViolationError ¶ added in v1.3.1
func (*Error) IsDuplicateKeyError ¶ added in v1.3.1
type ErrorDetails ¶ added in v1.1.0
type MigrationStep ¶ added in v1.3.0
type MigrationStep struct { // Name is a user defined name for this migration step. I.e.: "v1->v2" Name string // The index of the SQL sentence within a named block. SequenceNo int // Actual SQL sentence to execute in this migration step. Sql string }
MigrationStep contains details about the SQL sentence to execute in this step. Pass an empty struct to indicate the end.
func CreateMigrationStepsFromSqlContent ¶ added in v1.3.0
func CreateMigrationStepsFromSqlContent(content string) ([]MigrationStep, error)
CreateMigrationStepsFromSqlContent creates an array of migration steps based on the provided content
The expected format is the following: # a comment with the step name (starting and ending spaces and dashes will be removed) A single SQL sentence (extra comment/sql sentence pairs)
type MigrationStepCallback ¶ added in v1.3.0
type MigrationStepCallback func(ctx context.Context, stepIdx int) (MigrationStep, error)
MigrationStepCallback is called to get the migration step details at stepIdx position (starting from 1)
type NoRowsError ¶
type NoRowsError struct { }
NoRowsError is the error we return if the query does not return any row.
func (*NoRowsError) Error ¶
func (e *NoRowsError) Error() string
type Options ¶
type Options struct { Host string `json:"host"` Port uint16 `json:"port"` User string `json:"user"` Password string `json:"password"` Name string `json:"name"` MaxConns int32 `json:"maxConns"` SSLMode SSLMode ExtendedSettings map[string]string `json:"extendedSettings"` }
Options defines the database connection options.
type Row ¶
type Row interface { // Scan saves the content of the current row in the destination variables. Scan(dest ...interface{}) error }
Row defines a returned record.
type Rows ¶
type Rows interface { // Do calls the provided callback for each row returned by the executed query. Do(callback ScanRowsCallback) error }
Rows defines a set of returned records.
type SSLMode ¶
type SSLMode int
SSLMode states if secure communication with the server is optional or mandatory.
type ScanRowsCallback ¶
ScanRowsCallback defines a callback that is called on each row returned by the executed query.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx encloses a transaction object.
func (*Tx) Copy ¶
func (tx *Tx) Copy(ctx context.Context, tableName string, columnNames []string, callback CopyCallback) (int64, error)
Copy executes a SQL copy query within the transaction.
type WithinConnCallback ¶ added in v1.3.0
WithinConnCallback defines a callback called in the context of a single connection.