database

package
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JoinTypeLeft joinType = "LEFT"
)

Variables

View Source
var (
	ErrNoChanges           = errors.New("update must contain a change")
	ErrInvalidChangeTarget = errors.New("change target must not be nil")
)

Functions

func And

func And(conditions ...Condition) *and

And combines multiple conditions with AND.

func BytesOperationStrings

func BytesOperationStrings() []string

BytesOperationStrings returns a slice of all String values of the enum

func Coalesce

func Coalesce(values ...any) *coalesce

func DialectKeysForEnv

func DialectKeysForEnv() []string

func IsNotNull

func IsNotNull(column Column) *isNotNull

IsNotNull creates a condition that checks if a column is NOT NULL.

func IsNull

func IsNull(column Column) *isNull

IsNull creates a condition that checks if a column is NULL.

func LowerValue

func LowerValue[T Value](v T) wrappedValue[T]

func MustRegisterDefaultConnector

func MustRegisterDefaultConnector(connector Connector)

MustRegisterDefaultConnector registers a default connector that is used when no dialect is configured. It panics on error.

func MustRegisterDialect

func MustRegisterDialect(name string, decoder DialectDecoder)

MustRegisterDialect is like RegisterDialect but panics on error.

func NewCheckError

func NewCheckError(table, constraint string, original error) error

func NewForeignKeyError

func NewForeignKeyError(table, constraint string, original error) error

func NewIncrementColumnChange

func NewIncrementColumnChange[V Value](col Column, value V) *incrementColumnChange[V]

func NewMissingConditionError

func NewMissingConditionError(col Column) error

func NewMultipleRowsFoundError

func NewMultipleRowsFoundError(original error) error

func NewNoRowFoundError

func NewNoRowFoundError(original error) error

func NewNotNullError

func NewNotNullError(table, constraint string, original error) error

func NewPermissionError

func NewPermissionError(original error) error

func NewScanError

func NewScanError(original error) error

func NewUniqueError

func NewUniqueError(table, constraint string, original error) error

func NewUnknownError

func NewUnknownError(original error) error

func NumberOperationStrings

func NumberOperationStrings() []string

NumberOperationStrings returns a slice of all String values of the enum

func Or

func Or(conditions ...Condition) *or

Or combines multiple conditions with OR.

func RegisterDialect

func RegisterDialect(name string, decoder DialectDecoder) error

RegisterDialect registers a decoder under a dialect name.

func SHA256Value

func SHA256Value[T Value](v T) wrappedValue[T]

func TextOperationStrings

func TextOperationStrings() []string

TextOperationStrings returns a slice of all String values of the enum

Types

type AccessMode

type AccessMode uint8
const (
	AccessModeReadWrite AccessMode = iota
	AccessModeReadOnly
)

type Beginner

type Beginner interface {
	Begin(ctx context.Context, opts *TransactionOptions) (Transaction, error)
}

Beginner can start a new transaction.

type Boolean

type Boolean interface {
	~bool
}

type Bytes

type Bytes interface {
	~[]byte
}

type BytesOperation

type BytesOperation uint8

BytesOperation are operations that can be performed on bytea values.

const (
	BytesOperationEqual    BytesOperation = iota + 1 // =
	BytesOperationNotEqual                           // <>
)

func BytesOperationString

func BytesOperationString(s string) (BytesOperation, error)

BytesOperationString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func BytesOperationValues

func BytesOperationValues() []BytesOperation

BytesOperationValues returns all values of the enum

func (BytesOperation) IsABytesOperation

func (i BytesOperation) IsABytesOperation() bool

IsABytesOperation returns "true" if the value is listed in the enum definition. "false" otherwise

func (BytesOperation) String

func (i BytesOperation) String() string

type CTEChange

type CTEChange interface {
	Change
	// WriteCTE writes the CTE part of the change to the given statement builder.
	// It writes the part inside the brackets meaning without the "WITH cte_name AS (" and the ending ")".
	WriteCTE(builder *StatementBuilder)
	// SetName sets the name of the CTE.
	// This is defined by the caller to ensure uniqueness.
	// The name is used to reference the CTE in the main change.
	SetName(name string)
}

CTEChange represents a change that uses a Common Table Expression (CTE). It intercepts the Write process to first write the CTE part, and then the main change part.

func NewCTEChange

func NewCTEChange(cte func(builder *StatementBuilder), change func(name string) Change) CTEChange

type Change

type Change interface {
	gomock.Matcher

	// Write writes the change to the given statement builder.
	Write(builder *StatementBuilder) error
	// IsOnColumn checks if the change is on the given column.
	IsOnColumn(col Column) bool
	// contains filtered or unexported methods
}

Change represents a change to a column in a database table. Its written in the SET clause of an UPDATE statement.

func NewChange

func NewChange[V Value](col Column, value V) Change

NewChange creates a new Change for the given column and value. If you want to set a column to NULL, use NewChangePtr.

func NewChangePtr

func NewChangePtr[V Value](col Column, value *V) Change

NewChangePtr creates a new Change for the given column and value pointer. If the value pointer is nil, the column will be set to NULL.

func NewChangeToColumn

func NewChangeToColumn(to, from Column) Change

func NewChangeToNull

func NewChangeToNull(col Column) Change

func NewChangeToStatement

func NewChangeToStatement(col Column, stmt func(builder *StatementBuilder)) Change

type Changes

type Changes []Change

func NewChanges

func NewChanges(cols ...Change) Changes

func (Changes) IsOnColumn

func (c Changes) IsOnColumn(col Column) bool

IsOnColumn implements Change.

func (Changes) Matches

func (c Changes) Matches(x any) bool

Matches implements gomock.Matcher.

func (Changes) NoChange

func (c Changes) NoChange() bool

NoChange implements NoChange. It returns false if any of the changes writes to the builder.

func (Changes) String

func (c Changes) String() string

String implements gomock.Matcher.

func (Changes) Write

func (c Changes) Write(builder *StatementBuilder) error

Write implements Change.

func (Changes) WriteArg

func (c Changes) WriteArg(builder *StatementBuilder)

WriteArg implements Change.

type CheckError

type CheckError struct {
	IntegrityViolationError
}

CheckError is returned when a check constraint fails. It wraps the IntegrityViolationError to provide more context. It is used to indicate that a check constraint was violated during an insert or update operation.

func (*CheckError) Is

func (e *CheckError) Is(target error) bool

func (*CheckError) Unwrap

func (e *CheckError) Unwrap() error

type CollectableRows

type CollectableRows interface {
	// Collect collects all rows and scans them into dest.
	// dest must be a pointer to a slice of pointer to structs
	// e.g. *[]*MyStruct
	// Rows are closed after this call.
	Collect(dest any) error
	// CollectFirst collects the first row and scans it into dest.
	// dest must be a pointer to a struct
	// e.g. *MyStruct{}
	// Rows are closed after this call.
	CollectFirst(dest any) error
	// CollectExactlyOneRow collects exactly one row and scans it into dest.
	// e.g. *MyStruct{}
	// Rows are closed after this call.
	CollectExactlyOneRow(dest any) error
}

type Column

type Column interface {
	gomock.Matcher

	// WriteQualified writes the column with the table name as prefix.
	WriteQualified(builder *StatementBuilder)
	// WriteUnqualified writes the column without the table name as prefix.
	WriteUnqualified(builder *StatementBuilder)
	// Equals checks if two columns are equal.
	Equals(col Column) bool
	// contains filtered or unexported methods
}

Column represents a column in a database table.

func LowerColumn

func LowerColumn(col Column) Column

LowerColumn returns a column that represents LOWER(col).

func NewColumn

func NewColumn(table, name string) Column

func SHA256Column

func SHA256Column(col Column) Column

SHA256Column returns a column that represents SHA256(col).

type Columns

type Columns []Column

func (Columns) Equals

func (c Columns) Equals(col Column) bool

Equals implements Column.

func (Columns) Matches

func (c Columns) Matches(x any) bool

Matches implements Column.

func (Columns) String

func (c Columns) String() string

String implements Column.

func (Columns) WriteArg

func (c Columns) WriteArg(builder *StatementBuilder)

WriteArg implements Column.

func (Columns) WriteQualified

func (c Columns) WriteQualified(builder *StatementBuilder)

WriteQualified implements Column. Columns are separated by ", ".

func (Columns) WriteUnqualified

func (c Columns) WriteUnqualified(builder *StatementBuilder)

WriteUnqualified implements Column. Columns are separated by ", ".

type Condition

type Condition interface {
	gomock.Matcher
	Write(builder *StatementBuilder)
	// IsRestrictingColumn is used to check if the condition filters for a specific column.
	// It acts as a safeguard database operations that should be specific on the given column.
	IsRestrictingColumn(col Column) bool
}

Condition represents a SQL condition. Its written after the WHERE keyword in a SQL statement.

func Exists

func Exists(table string, condition Condition) Condition

Exists creates a condition that checks for the existence of rows in a subquery.

func ForceRestrictingColumn

func ForceRestrictingColumn(cond Condition, isRestriction bool) Condition

func NewBooleanCondition

func NewBooleanCondition[V Boolean](col Column, value V) Condition

NewBooleanCondition creates a condition that compares a boolean column with a value.

func NewBytesCondition

func NewBytesCondition[V Bytes](col Column, op BytesOperation, value any) Condition

NewBytesCondition creates a condition that compares a BYTEA column with a value.

func NewColumnCondition

func NewColumnCondition(col1, col2 Column) Condition

NewColumnCondition creates a condition that compares two columns on equality.

func NewIdentityEqualCondition

func NewIdentityEqualCondition(col Column, id string) Condition

NewIdentityEqualCondition compares an ephemeral BIGINT/INT64 column with a decimal string id.

func NewNumberCondition

func NewNumberCondition[V Number](col Column, op NumberOperation, value V) Condition

NewNumberCondition creates a condition that compares a numeric column with a value.

func NewTextCondition

func NewTextCondition[T Text](col Column, op TextOperation, value T) Condition

NewTextCondition creates a condition that compares a text column with a value. if `op.IsIgnoreCaseOperation()` is true the response is created using NewTextIgnoreCaseCondition

func NewTextIgnoreCaseCondition

func NewTextIgnoreCaseCondition[T Text](col Column, op TextOperation, value T) Condition

NewTextIgnoreCaseCondition creates a condition that compares a text column with a value, ignoring case by lowercasing both.

type Config

type Config struct {
	Raw map[string]any `mapstructure:",remain" yaml:",inline"`
}

Config contains one configured database dialect.

Example:

database:
  postgres: postgres://user:pass@host:5432/db

or

database:
  spanner: projects/my-project/instances/my-instance/databases/my-database

We might need to document how or where the client gets the authentication credentials for spanner, but for now we can assume that the application is running in an environment where the default credentials work (e.g. GCE, GKE, Cloud Run, etc.). It might be possible that we want to add more fields later, see https://pkg.go.dev/cloud.google.com/go/spanner@v1.91.0#ClientConfig. In that case the config might look like this:

database:
  spanner:
    database: projects/my-project/instances/my-instance/databases/my-database
    option1: value1
    option2: value2

The configured dialect key/value is captured in Raw.

func (Config) Build

func (c Config) Build() (Connector, error)

Build resolves the configured dialect and returns its connector.

type Connection

type Connection interface {
	Beginner
	QueryExecutor
	Migrator

	Release(ctx context.Context) error

	Ping(ctx context.Context) error
}

Connection is a single database connection which can be released back to the pool.

type Connector

type Connector interface {
	Connect(ctx context.Context) (Pool, error)
}

Connector abstracts the database driver.

type DialectDecoder

type DialectDecoder func(value any) (Connector, error)

DialectDecoder decodes a raw configuration value into a database connector.

type Executor

type Executor interface {
	Exec(ctx context.Context, stmt string, args ...any) (int64, error)
}

Executor is a database client that can execute statements. It returns the number of rows affected or an error

type ForeignKeyError

type ForeignKeyError struct {
	IntegrityViolationError
}

ForeignKeyError is returned when a foreign key constraint fails. It wraps the IntegrityViolationError to provide more context. It is used to indicate that a foreign key constraint was violated during an insert or update operation

func (*ForeignKeyError) Is

func (e *ForeignKeyError) Is(target error) bool

func (*ForeignKeyError) Unwrap

func (e *ForeignKeyError) Unwrap() error

type Identity

type Identity string

Identity is the canonical string form of a resource identifier in Go. Storage may persist it as BIGINT (ephemeral, database-generated) or TEXT/STRING (managed).

func (Identity) IsNumeric

func (id Identity) IsNumeric() bool

IsNumeric reports whether id is a non-empty signed integer decimal suitable for BIGINT binding.

func (*Identity) Scan

func (id *Identity) Scan(src any) error

Scan implements sql.Scanner.

func (Identity) String

func (id Identity) String() string

String implements fmt.Stringer.

func (Identity) Value

func (id Identity) Value() (driver.Value, error)

Value implements driver.Valuer.

type Instruction

type Instruction string
const (
	DefaultInstruction          Instruction = "DEFAULT"
	NowInstruction              Instruction = "NOW()"
	CurrentTimestampInstruction Instruction = "CURRENT_TIMESTAMP()"
	NullInstruction             Instruction = "NULL"
	GenRandomUUIDInstruction    Instruction = "gen_random_uuid()"
)

type IntegrityType

type IntegrityType string
const (
	IntegrityTypeCheck   IntegrityType = "check"
	IntegrityTypeUnique  IntegrityType = "unique"
	IntegrityTypeForeign IntegrityType = "foreign"
	IntegrityTypeNotNull IntegrityType = "not null"
)

type IntegrityViolationError

type IntegrityViolationError struct {
	// contains filtered or unexported fields
}

IntegrityViolationError represents a generic integrity violation error. It wraps the dialect specific original error to provide more context.

func (*IntegrityViolationError) Error

func (e *IntegrityViolationError) Error() string

func (*IntegrityViolationError) Is

func (e *IntegrityViolationError) Is(target error) bool

func (*IntegrityViolationError) Unwrap

func (e *IntegrityViolationError) Unwrap() error

type IsolationLevel

type IsolationLevel uint8
const (
	IsolationLevelSerializable IsolationLevel = iota
	IsolationLevelReadCommitted
)

type Migrator

type Migrator interface {
	// Migrate executes migrations to set up the database.
	// The method can be called once per running Zitadel.
	Migrate(ctx context.Context) error
}

type MissingConditionError

type MissingConditionError struct {
	// contains filtered or unexported fields
}

func (*MissingConditionError) Error

func (e *MissingConditionError) Error() string

func (*MissingConditionError) Is

func (e *MissingConditionError) Is(target error) bool

type MultipleRowsFoundError

type MultipleRowsFoundError struct {
	// contains filtered or unexported fields
}

MultipleRowsFoundError is returned when QueryRow finds multiple rows. It wraps the dialect specific original error to provide more context.

func (*MultipleRowsFoundError) Error

func (e *MultipleRowsFoundError) Error() string

func (*MultipleRowsFoundError) Is

func (e *MultipleRowsFoundError) Is(target error) bool

func (*MultipleRowsFoundError) Unwrap

func (e *MultipleRowsFoundError) Unwrap() error

type NoChange

type NoChange interface {
	NoChange() bool
}

NoChange can be implemented by Changes that might not result in any actual change, resp. when the change has no set statement, e.g. CTEChange with no change function.

type NoRowFoundError

type NoRowFoundError struct {
	// contains filtered or unexported fields
}

NoRowFoundError is returned when QueryRow does not find any row. It wraps the dialect specific original error to provide more context.

func (*NoRowFoundError) Error

func (e *NoRowFoundError) Error() string

func (*NoRowFoundError) Is

func (e *NoRowFoundError) Is(target error) bool

func (*NoRowFoundError) Unwrap

func (e *NoRowFoundError) Unwrap() error

type NotNullError

type NotNullError struct {
	IntegrityViolationError
}

NotNullError is returned when a not null constraint fails. It wraps the IntegrityViolationError to provide more context. It is used to indicate that a not null constraint was violated during an insert or update operation.

func (*NotNullError) Is

func (e *NotNullError) Is(target error) bool

func (*NotNullError) Unwrap

func (e *NotNullError) Unwrap() error

type Null

type Null[T any] = sql.Null[T]

Null is a type alias for sql.Null[T] to avoid importing the sql package into repositories.

type NumberOperation

type NumberOperation uint8

NumberOperation are operations that can be performed on number values.

const (
	// NumberOperationEqual compares two numbers for equality.
	NumberOperationEqual NumberOperation = iota + 1 // =
	// NumberOperationNotEqual compares two numbers for inequality.
	NumberOperationNotEqual // <>
	// NumberOperationLessThan compares two numbers to check if the first is less than the second.
	NumberOperationLessThan // <
	// NumberOperationLessThanOrEqual compares two numbers to check if the first is less than or equal to the second.
	NumberOperationLessThanOrEqual // <=
	// NumberOperationGreaterThan compares two numbers to check if the first is greater than the second.
	NumberOperationGreaterThan // >
	// NumberOperationGreaterThanOrEqual compares two numbers to check if the first is greater than or equal to the second.
	NumberOperationGreaterThanOrEqual // >=
)

func NumberOperationString

func NumberOperationString(s string) (NumberOperation, error)

NumberOperationString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func NumberOperationValues

func NumberOperationValues() []NumberOperation

NumberOperationValues returns all values of the enum

func (NumberOperation) IsANumberOperation

func (i NumberOperation) IsANumberOperation() bool

IsANumberOperation returns "true" if the value is listed in the enum definition. "false" otherwise

func (NumberOperation) String

func (i NumberOperation) String() string

type Operation

type Operation interface {
	NumberOperation | TextOperation | BytesOperation
}

type Order

type Order interface {
	Write(builder *StatementBuilder)
}

Order represents a SQL condition. It's written after the ORDER BY keyword in a SQL statement.

func OrderBy

func OrderBy(column Column) Order

type OrderDirection

type OrderDirection uint8
const (
	OrderDirectionAsc OrderDirection = iota
	OrderDirectionDesc
)

type PermissionError

type PermissionError struct {
	// contains filtered or unexported fields
}

func (*PermissionError) Error

func (e *PermissionError) Error() string

func (*PermissionError) Is

func (e *PermissionError) Is(target error) bool

func (*PermissionError) Unwrap

func (e *PermissionError) Unwrap() error

type Pool

type Pool interface {
	Beginner
	QueryExecutor
	Migrator

	Acquire(ctx context.Context) (Connection, error)
	Close(ctx context.Context) error

	Ping(ctx context.Context) error
}

Pool is a connection pool. e.g. pgxpool

type PoolTest

type PoolTest interface {
	Pool
	// MigrateTest is the same as [Migrator] but executes the migrations multiple times instead of only once.
	MigrateTest(ctx context.Context) error
	// RawDB returns an *[sql.DB] handle backed by the same database as the [PoolTest].
	// The returned handle is intended for use in tests, and the caller is responsible for closing it when done.
	RawDB() *sql.DB
}

type Querier

type Querier interface {
	Query(ctx context.Context, stmt string, args ...any) (Rows, error)
	QueryRow(ctx context.Context, stmt string, args ...any) Row
}

Querier is a database client that can execute queries and return rows.

type QueryExecutor

type QueryExecutor interface {
	Querier
	Executor
}

QueryExecutor is a database client that can execute queries and statements.

type QueryOption

type QueryOption func(opts *QueryOpts)

func WithCondition

func WithCondition(condition Condition) QueryOption

WithCondition sets the condition for the query.

func WithExtra

func WithExtra(extra any) QueryOption

WithExtra attaches repository-specific data to QueryOpts (QueryOpts.Extra).

func WithGroupBy

func WithGroupBy(groupBy ...Column) QueryOption

WithGroupBy sets the columns to group the results by.

func WithLeftJoin

func WithLeftJoin(table string, columns Condition) QueryOption

WithLeftJoin adds a LEFT JOIN to the query.

func WithLimit

func WithLimit(limit uint32) QueryOption

WithLimit sets the maximum number of results to return.

func WithOffset

func WithOffset(offset uint32) QueryOption

WithOffset sets the number of results to skip before returning the results.

func WithOrderBy

func WithOrderBy(ordering OrderDirection, orderBy ...Column) QueryOption

WithOrderBy sets the columns to order the results by.

func WithOrderByAscending

func WithOrderByAscending(columns ...Column) QueryOption

func WithOrderByDescending

func WithOrderByDescending(columns ...Column) QueryOption

func WithPermissionCheck

func WithPermissionCheck(permission string) QueryOption

WithPermissionCheck enables a check if the authenticated user has the passed permission to read or write a resource.

func WithResultLock

func WithResultLock() QueryOption

WithResultLock locks the results of the query during the transaction.

type QueryOpts

type QueryOpts struct {
	// Condition is the condition to filter the results.
	// It is used to build the WHERE clause of the SQL statement.
	Condition Condition
	// Extra holds optional structured data decoded by repositories (e.g. user list filters).
	Extra any
	// OrderBy is the columns to order the results by.
	// It is used to build the ORDER BY clause of the SQL statement.
	OrderBy Columns
	// Ordering defines if the columns should be ordered ascending or descending.
	// Default is ascending.
	Ordering OrderDirection
	// Limit is the maximum number of results to return.
	// It is used to build the LIMIT clause of the SQL statement.
	Limit uint32
	// Offset is the number of results to skip before returning the results.
	// It is used to build the OFFSET clause of the SQL statement.
	Offset uint32
	// GroupBy is the columns to group the results by.
	// It is used to build the GROUP BY clause of the SQL statement.
	GroupBy Columns
	// Joins is a list of joins to be applied to the query.
	// It is used to build the JOIN clauses of the SQL statement.
	Joins []join
	// Permission required to read or write the resource.
	// When unset, no permission check is made.
	Permission string
	// ShouldLock the results during the transaction.
	ShouldLock bool
}

QueryOpts holds the options for a query. It is used to build the SQL SELECT statement.

func (*QueryOpts) Matches

func (q *QueryOpts) Matches(x any) bool

Matches implements gomock.Matcher.

func (*QueryOpts) String

func (q *QueryOpts) String() string

String implements gomock.Matcher.

func (*QueryOpts) Write

func (opts *QueryOpts) Write(builder *StatementBuilder)

func (*QueryOpts) WriteCondition

func (opts *QueryOpts) WriteCondition(builder *StatementBuilder)

func (*QueryOpts) WriteGroupBy

func (opts *QueryOpts) WriteGroupBy(builder *StatementBuilder)

func (*QueryOpts) WriteLeftJoins

func (opts *QueryOpts) WriteLeftJoins(builder *StatementBuilder)

func (*QueryOpts) WriteLimit

func (opts *QueryOpts) WriteLimit(builder *StatementBuilder)

func (*QueryOpts) WriteLock

func (opts *QueryOpts) WriteLock(builder *StatementBuilder)

func (*QueryOpts) WriteOffset

func (opts *QueryOpts) WriteOffset(builder *StatementBuilder)

func (*QueryOpts) WriteOrderBy

func (opts *QueryOpts) WriteOrderBy(builder *StatementBuilder)

type Row

type Row interface {
	Scanner
}

Row is an abstraction of sql.Row.

type Rows

type Rows interface {
	Scanner
	Next() bool
	Close() error
	Err() error
}

Rows is an abstraction of sql.Rows.

type ScanError

type ScanError struct {
	// contains filtered or unexported fields
}

ScanError is returned when scanning rows into objects failed. It wraps the original error to provide more context.

func (*ScanError) Error

func (e *ScanError) Error() string

func (*ScanError) Is

func (e *ScanError) Is(target error) bool

func (*ScanError) Unwrap

func (e *ScanError) Unwrap() error

type Scanner

type Scanner interface {
	Scan(dest ...any) error
}

Scanner scans a single row of data into the destination.

type StatementBuilder

type StatementBuilder struct {
	strings.Builder
	// contains filtered or unexported fields
}

StatementBuilder is a helper to build SQL statement.

func NewStatementBuilder

func NewStatementBuilder(baseQuery string, baseArgs ...any) *StatementBuilder

func (*StatementBuilder) AppendArg

func (b *StatementBuilder) AppendArg(arg any) (placeholder string)

AppendArg adds the argument to the statement and returns the placeholder.

func (*StatementBuilder) AppendArgs

func (b *StatementBuilder) AppendArgs(args ...any)

AppendArgs adds the arguments to the statement and doesn't return the placeholders.

func (*StatementBuilder) Args

func (b *StatementBuilder) Args() []any

Args returns the arguments added to the statement.

func (*StatementBuilder) WriteArg

func (b *StatementBuilder) WriteArg(arg any)

WriteArgs adds the argument to the statement and writes the placeholder to the query.

func (*StatementBuilder) WriteArgs

func (b *StatementBuilder) WriteArgs(args ...any)

WriteArgs adds the arguments to the statement and writes the placeholders to the query. The placeholders are comma separated.

type Text

type Text interface {
	~string | Bytes
}

type TextOperation

type TextOperation uint8

TextOperation are operations that can be performed on text values.

const (
	// TextOperationEqual compares two strings for equality.
	TextOperationEqual TextOperation = iota + 1 // =
	// TextOperationNotEqual compares two strings for inequality.
	TextOperationNotEqual // <>
	// TextOperationStartsWith checks if the first string starts with the second.
	TextOperationStartsWith // LIKE
	// TextOperationContains checks if the first string contains the second
	TextOperationContains // LIKE
	// TextOperationEndsWith checks if the first string ends with the second.
	TextOperationEndsWith // LIKE

	// TextOperationContainsIgnoreCase checks if the first string contains the second ignoring case
	TextOperationContainsIgnoreCase // LIKE
	// TextOperationEndsWithIgnoreCase checks if the first string ends with the second ignoring case
	TextOperationEndsWithIgnoreCase // LIKE
	// TextOperationStartsWithIgnoreCase checks if the first string starts with the second ignoring case
	TextOperationStartsWithIgnoreCase // LIKE
	// TextOperationEqualIgnoreCase compares two strings for equality ignoring case
	TextOperationEqualIgnoreCase // =
	// TextOperationNotEqualIgnoreCase compares two strings for inequality ignoring case
	TextOperationNotEqualIgnoreCase // <>
)

func TextOperationString

func TextOperationString(s string) (TextOperation, error)

TextOperationString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TextOperationValues

func TextOperationValues() []TextOperation

TextOperationValues returns all values of the enum

func (TextOperation) IsATextOperation

func (i TextOperation) IsATextOperation() bool

IsATextOperation returns "true" if the value is listed in the enum definition. "false" otherwise

func (TextOperation) IsIgnoreCaseOperation

func (op TextOperation) IsIgnoreCaseOperation() bool

func (TextOperation) String

func (i TextOperation) String() string

func (TextOperation) Value

func (op TextOperation) Value() TextOperation

type Transaction

type Transaction interface {
	Beginner

	// Commit marks a transaction as successful and commits it to the database.
	Commit(ctx context.Context) error
	// Rollback undoes all changes made in the transaction.
	Rollback(ctx context.Context) error
	// End commits the transaction if err is nil, otherwise rollbacks.
	//
	// If err is nil the returned error is from Commit.
	// If err is not nil, and rollback is successful, the original err is returned.
	// If err is not nil, and rollback fails, the two errors are joined using [errors.Join].
	End(ctx context.Context, err error) error

	QueryExecutor
}

Transaction is an SQL transaction.

Beginner on Transaction starts a sub transaction (for example a savepoint).

type TransactionOptions

type TransactionOptions struct {
	IsolationLevel IsolationLevel
	AccessMode     AccessMode
}

type UniqueError

type UniqueError struct {
	IntegrityViolationError
}

UniqueError is returned when a unique constraint fails. It wraps the IntegrityViolationError to provide more context. It is used to indicate that a unique constraint was violated during an insert or update operation.

func (*UniqueError) Is

func (e *UniqueError) Is(target error) bool

func (*UniqueError) Unwrap

func (e *UniqueError) Unwrap() error

type UnknownError

type UnknownError struct {
	// contains filtered or unexported fields
}

UnknownError is returned when an unknown error occurs. It wraps the dialect specific original error to provide more context. It is used to indicate that an error occurred that does not fit into any of the other categories.

func (*UnknownError) Error

func (e *UnknownError) Error() string

func (*UnknownError) Is

func (e *UnknownError) Is(target error) bool

func (*UnknownError) Unwrap

func (e *UnknownError) Unwrap() error

type Value

type Value interface {
	Boolean | Number | Text | Instruction | Bytes | any
}

Directories

Path Synopsis
Package dbmock is a generated GoMock package.
Package dbmock is a generated GoMock package.
Package dbtest provides shared bring-up of a database for the integration test suites.
Package dbtest provides shared bring-up of a database for the integration test suites.
dialect
all
pgxcommon
Package pgxcommon provides Row, Rows, and Transaction wrappers shared by all pgx-based database dialect implementations (Postgres, Spanner via PGAdapter, …).
Package pgxcommon provides Row, Rows, and Transaction wrappers shared by all pgx-based database dialect implementations (Postgres, Spanner via PGAdapter, …).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL