Documentation ¶
Overview ¶
Package pgutil contains utilities for postgres
Index ¶
- func ByteaArray(bytesArray [][]byte) *pgtype.ByteaArray
- func ConnstrWithSchema(connstr, schema string) string
- func CreateRandomTestingSchemaName(n int) string
- func CreateSchema(ctx context.Context, db Execer, schema string) (err error)
- func DateArray(timeSlice []time.Time) *pgtype.DateArray
- func DropSchema(ctx context.Context, db Execer, schema string) error
- func EnsureApplicationName(s string, app string) (string, error)
- func Float8Array(floats []float64) *pgtype.Float8Array
- func Int2Array(ints []int16) *pgtype.Int2Array
- func Int4Array(ints []int32) *pgtype.Int4Array
- func Int8Array(bigInts []int64) *pgtype.Int8Array
- func NodeIDArray(nodeIDs []storj.NodeID) *pgtype.ByteaArray
- func NullByteaArray(bytesArray [][]byte) *pgtype.ByteaArray
- func NullTimestampTZArray(timeSlice []*time.Time) *pgtype.TimestamptzArray
- func OpenUnique(ctx context.Context, connstr string, schemaPrefix string) (*dbutil.TempDatabase, error)
- func ParseSchemaFromConnstr(connstr string) (string, error)
- func PlacementConstraintArray(constraints []storj.PlacementConstraint) *pgtype.Int2Array
- func QueryData(ctx context.Context, db dbschema.Queryer, schema *dbschema.Schema) (*dbschema.Data, error)
- func QuerySchema(ctx context.Context, db dbschema.Queryer) (*dbschema.Schema, error)
- func QuerySnapshot(ctx context.Context, db dbschema.Queryer) (*dbschema.Snapshot, error)
- func QuoteIdentifier(ident string) string
- func QuoteSchema(schema string) string
- func RoughInlinePlaceholders(query string, args ...any) (string, error)
- func TextArray(stringSlice []string) *pgtype.TextArray
- func TimestampTZArray(timeSlice []time.Time) *pgtype.TimestamptzArray
- func UUIDArray(uuids []uuid.UUID) *pgtype.ByteaArray
- func UnquoteIdentifier(quotedIdent string) string
- type Execer
- type Explanation
- type ExplanationEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteaArray ¶
func ByteaArray(bytesArray [][]byte) *pgtype.ByteaArray
ByteaArray returns an object usable by pg drivers for passing a [][]byte slice into a database as type BYTEA[].
If any elements of bytesArray are nil, they will be represented in the database as an empty bytes array (not NULL). See also NullByteaArray.
func ConnstrWithSchema ¶
ConnstrWithSchema adds schema to a connection string.
func CreateRandomTestingSchemaName ¶
CreateRandomTestingSchemaName creates a random schema name string.
func CreateSchema ¶
CreateSchema creates a schema if it doesn't exist.
func DateArray ¶
DateArray returns an object usable by pg drivers for passing a []time.Time slice into a database as type Date[].
func DropSchema ¶
DropSchema drops the named schema.
func EnsureApplicationName ¶ added in v1.112.2
EnsureApplicationName ensures that the Connection String contains an application name.
func Float8Array ¶
func Float8Array(floats []float64) *pgtype.Float8Array
Float8Array returns an object usable by pg drivers for passing a []float64 slice into a database as type FLOAT8[].
func Int2Array ¶
Int2Array returns an object usable by pg drivers for passing a []int16 slice into a database as type INT2[].
func Int4Array ¶
Int4Array returns an object usable by pg drivers for passing a []int32 slice into a database as type INT4[].
func Int8Array ¶
Int8Array returns an object usable by pg drivers for passing a []int64 slice into a database as type INT8[].
func NodeIDArray ¶
func NodeIDArray(nodeIDs []storj.NodeID) *pgtype.ByteaArray
NodeIDArray returns an object usable by pg drivers for passing a []storj.NodeID slice into a database as type BYTEA[].
func NullByteaArray ¶
func NullByteaArray(bytesArray [][]byte) *pgtype.ByteaArray
NullByteaArray returns an object usable by pg drivers for passing a [][]byte slice into a database as type BYTEA[]. It allows for elements of bytesArray to be nil, which will correspond to a NULL value in the database.
This is probably the way that ByteaArray should have worked all along, but we won't change it now in case some things depend on the existing behavior.
func NullTimestampTZArray ¶
func NullTimestampTZArray(timeSlice []*time.Time) *pgtype.TimestamptzArray
NullTimestampTZArray returns an object usable by pg drivers for passing a []*time.Time slice into a database as type TIMESTAMPTZ[].
func OpenUnique ¶
func OpenUnique(ctx context.Context, connstr string, schemaPrefix string) (*dbutil.TempDatabase, error)
OpenUnique opens a postgres database with a temporary unique schema, which will be cleaned up when closed. It is expected that this should normally be used by way of "storj.io/storj/shared/dbutil/tempdb".OpenUnique() instead of calling it directly.
func ParseSchemaFromConnstr ¶
ParseSchemaFromConnstr returns the name of the schema parsed from the connection string if one is provided.
func PlacementConstraintArray ¶
func PlacementConstraintArray(constraints []storj.PlacementConstraint) *pgtype.Int2Array
PlacementConstraintArray returns an object usable by pg drivers for passing a []storj.PlacementConstraint slice into a database as type INT2[].
func QueryData ¶
func QueryData(ctx context.Context, db dbschema.Queryer, schema *dbschema.Schema) (*dbschema.Data, error)
QueryData loads all data from tables.
func QuerySchema ¶
QuerySchema loads the schema from postgres database.
func QuerySnapshot ¶
QuerySnapshot loads snapshot from database.
func QuoteIdentifier ¶
QuoteIdentifier quotes an identifier for use in an interpolated SQL string.
func RoughInlinePlaceholders ¶
RoughInlinePlaceholders does a very rough replacement of $N arguments. It does not properly parse the SQL query.
func TextArray ¶
TextArray returns an object usable by pg drivers for passing a []string slice into a database as type TEXT[].
func TimestampTZArray ¶
func TimestampTZArray(timeSlice []time.Time) *pgtype.TimestamptzArray
TimestampTZArray returns an object usable by pg drivers for passing a []time.Time slice into a database as type TIMESTAMPTZ[].
func UUIDArray ¶
func UUIDArray(uuids []uuid.UUID) *pgtype.ByteaArray
UUIDArray returns an object usable by pg drivers for passing a []uuid.UUID slice into a database as type BYTEA[].
func UnquoteIdentifier ¶
UnquoteIdentifier is the analog of QuoteIdentifier.
Types ¶
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Execer is for executing sql.
type Explanation ¶
type Explanation struct {
Entries []ExplanationEntry
}
Explanation contains the result of a EXPLAIN.
func Explain ¶
func Explain(ctx context.Context, db tagsql.DB, query string, args ...any) (_ Explanation, err error)
Explain explains the query.
func (*Explanation) Add ¶
func (e *Explanation) Add(key, value string)
Add adds a new entry to an Explanation.
func (*Explanation) Select ¶
func (e *Explanation) Select(keys ...string) Explanation
Select returns a new explanation containing only the specific keys.
func (Explanation) String ¶
func (e Explanation) String() string
String formats the explanation as a string.
func (*Explanation) Without ¶
func (e *Explanation) Without(keys ...string) Explanation
Without returns a new explanation without the specified keys.
type ExplanationEntry ¶
ExplanationEntry is a single attribute of EXPLAIN query.