Documentation
¶
Index ¶
- Constants
- func ExecSQL(ctx context.Context, sql string) (err error)
- func ExecSQLFile(ctx context.Context, filename string) (err error)
- func InitializeDB(ctx context.Context, connStr string, dbName ...string) (err error)
- func NewPGBool(b bool) pgtype.Bool
- func NewPGText(s string) pgtype.Text
- func NewPGTimestamp(t time.Time) pgtype.Timestamp
- func SetDB(newDB *DB)
- type DB
- func (db *DB) Close(ctx context.Context) (err error)
- func (db *DB) Execute(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)
- func (db *DB) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
- func (db *DB) QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row
- type Querier
- type SQLSnippet
Constants ¶
const (
ErrorLogArg = "error"
)
Variables ¶
This section is empty.
Functions ¶
func InitializeDB ¶
Types ¶
type DB ¶
type DB struct {
Querier
// contains filtered or unexported fields
}
func (*DB) Query ¶
Query sends a query to the server and returns a list of rows as pgx.Rows to read the results. Only errors encountered sending the query and initializing Rows will be returned. Err() on the returned Rows must be checked after the Rows is closed to determine if the query executed successfully.
The returned Rows must be closed before the connection can be used again. It is safe to attempt to read from the returned Rows even if an error is returned. The error will be the available in rows.Err() after rows are closed. It is allowed to ignore the error returned from Query and handle it in Rows.
It is possible for a call of FieldDescriptions on the returned Rows to return nil even if the Query call did not return an error.
It is possible for a query to return one or more rows before encountering an error. In most cases the rows should be collected before processing rather than processed while receiving each row. This avoids the possibility of the application processing rows from a query that the server rejected. The CollectRows function is useful here.