Documentation
¶
Index ¶
- func IsDatabaseError(err error) bool
- func IsNetworkError(err error) bool
- func IsNoRowsError(err error) bool
- 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) SetEventHandler(handler ErrorHandler)
- func (db *Database) WithinTx(ctx context.Context, callback WithinTxCallback) error
- type Error
- type ErrorDetails
- type ErrorHandler
- 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
- type WithinTxCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDatabaseError ¶
IsDatabaseError returns true if the given error object is a database error.
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.
Types ¶
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) SetEventHandler ¶
func (db *Database) SetEventHandler(handler ErrorHandler)
SetEventHandler sets a new error handler callback
type Error ¶
type Error struct { Details *ErrorDetails // contains filtered or unexported fields }
Error is the error type usually returned by us.
type ErrorDetails ¶ added in v1.1.0
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 }
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 transation 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.