postgres

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FieldEventAttrName  = "attribute.name"
	FieldEventAttrValue = "attribute.value"
	FieldEventTXHash    = "event.tx_hash"
	FieldEventType      = "event.type"
)
View Source
const (
	DefaultPort = 5432
	DefaultHost = "127.0.0.1"
)
View Source
const SchemasDir = "schemas"

SchemasDir defines the name for the embedded schema directory.

Variables

View Source
var (
	ErrUnknownEntity    = errors.New("unknown query entity")
	ErrInvalidSortOrder = errors.New("invalid query sort order")
)
View Source
var ErrClosed = errors.New("no database connection")

ErrClosed is returned when database connection is not open.

Functions

func CastJSONToNumeric

func CastJSONToNumeric(f string) string

CastJSONToNumeric modifier casts a JSON/JSONB field to numeric.

func CastJSONToText

func CastJSONToText(f string) string

CastJSONToText modifier casts a JSON/JSONB field to text.

Types

type Adapter

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

Adapter implements a data backend adapter for PostgreSQL.

func NewAdapter

func NewAdapter(database string, options ...Option) (Adapter, error)

NewAdapter creates a new PostgreSQL adapter.

func (Adapter) GetLatestHeight

func (a Adapter) GetLatestHeight(ctx context.Context) (height int64, err error)

func (Adapter) GetType

func (a Adapter) GetType() string

func (Adapter) Init

func (a Adapter) Init(ctx context.Context) error

func (Adapter) Query

func (a Adapter) Query(ctx context.Context, q query.Query) (query.Cursor, error)

func (Adapter) QueryEvents

func (a Adapter) QueryEvents(ctx context.Context, q query.EventQuery) ([]query.Event, error)

func (Adapter) Save

func (a Adapter) Save(ctx context.Context, txs []cosmosclient.TX) error

func (Adapter) UpdateSchema

func (a Adapter) UpdateSchema(ctx context.Context, s Schemas) error

UpdateSchema updates the database schema to the latest version available. It applies all available schemas that were not applied already.

type Filter

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

Filter defines a generic equality filter.

func FilterByEventAttrName

func FilterByEventAttrName(name string) Filter

FilterByEventAttrName creates a new filter to match events by attribute name.

func FilterByEventAttrValue

func FilterByEventAttrValue(v string) Filter

FilterByEventAttrValue creates a new filter to match events by attribute value.

func FilterByEventAttrValueInt

func FilterByEventAttrValueInt(v int64) Filter

FilterByEventAttrValueInt creates a new filter to match events by attribute value.

func FilterByEventType

func FilterByEventType(eventType string) Filter

FilterByEventType creates a new filter to match events by type.

func NewFilter

func NewFilter(field string, value any, options ...FilterOption) Filter

NewFilter creates a new generic equality filter.

func (Filter) Field

func (f Filter) Field() string

func (Filter) String

func (f Filter) String() string

func (Filter) Value

func (f Filter) Value() any

type FilterOption

type FilterOption func(*Filter)

FilterOption defines an option for filters.

func WithModifiers

func WithModifiers(m ...Modifier) FilterOption

WithModifiers assigns one or more field modifier functions to the filter. Field modifiers can be used to change the behavior of a filtered field.

type Modifier

type Modifier func(field string) string

Modifier defines a function that can be used to modify a field name or value.

type Option

type Option func(*Adapter)

Option defines an option for the adapter.

func WithHost

func WithHost(host string) Option

WithHost configures a database host name or IP.

func WithParams

func WithParams(params map[string]string) Option

WithParams configures extra database parameters.

func WithPassword

func WithPassword(password string) Option

WithPassword configures a database password.

func WithPort

func WithPort(port uint) Option

WithPort configures a database port.

func WithUser

func WithUser(user string) Option

WithUser configures a database user.

type Schemas

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

Schemas defines a type to manage versioning of embedded SQL schemas. Each schema file must live inside the embedded schemas directory and the name of each schema file must be numeric, where the number represents the version.

func NewSchemas

func NewSchemas(fs fs.FS, namespace string) Schemas

NewSchemas creates a new embedded SQL schema manager. The embedded FS is used to iterate the schema files. By default, the applied schema versions are stored in the "schema" table but the name can have a prefix namespace when different packages are storing the schemas in the same database.

func (Schemas) GetSchemaVersionSQL

func (s Schemas) GetSchemaVersionSQL() string

GetSchemaVersionSQL returns the SQL query to get the current schema version.

func (Schemas) GetTableDDL

func (s Schemas) GetTableDDL() string

GetTableDDL returns the DDL to create the schemas table.

func (Schemas) WalkFrom

func (s Schemas) WalkFrom(fromVersion uint64, fn SchemasWalkFunc) error

WalkFrom calls a function for SQL schemas starting from a specific version. This is useful to apply newer schemas that are not yet applied.

type SchemasWalkFunc

type SchemasWalkFunc func(version uint64, script []byte) error

SchemasWalkFunc is the type of the function called by WalkFrom.

type ScriptBuilder

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

ScriptBuilder builds database DDL/SQL scripts that execute multiple commands.

func (*ScriptBuilder) AppendCommand

func (b *ScriptBuilder) AppendCommand(cmd string)

AppendCommand appends a command to the script.

func (*ScriptBuilder) AppendScript

func (b *ScriptBuilder) AppendScript(s []byte)

AppendScript appends a database DDL/SQL script.

func (*ScriptBuilder) BeginTX

func (b *ScriptBuilder) BeginTX()

BeginTX appends a command to start a database transaction.

func (*ScriptBuilder) Bytes

func (b *ScriptBuilder) Bytes() []byte

Bytes returns the whole script as bytes.

func (*ScriptBuilder) CommitTX

func (b *ScriptBuilder) CommitTX()

CommitTX appends a command to commit a database transaction.

type SliceFilter

type SliceFilter struct {
	Filter
}

SliceFilter defines a generic slice/array equality filter.

func FilterByEventTXs

func FilterByEventTXs(hashes ...string) SliceFilter

FilterByEventTXs creates a new filter to match events by TX hashes.

func NewIntSliceFilter

func NewIntSliceFilter(field string, values []int64) SliceFilter

NewIntSliceFilter creates a new int64 slice equality filter.

func NewStringSliceFilter

func NewStringSliceFilter(field string, values []string) SliceFilter

NewStringSliceFilter creates a new string slice equality filter.

func (SliceFilter) String

func (f SliceFilter) String() string

func (SliceFilter) Value

func (f SliceFilter) Value() any

Jump to

Keyboard shortcuts

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