db

package
v0.0.0-...-ab689eb Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: BSD-3-Clause-Clear Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewTable func(name string) Table

Functions

func IsQueryBuilderSetClauseError

func IsQueryBuilderSetClauseError(err error) bool

func KeyAccessServerProtoJSON

func KeyAccessServerProtoJSON(keyAccessServerJSON []byte) ([]*kasr.KeyAccessServer, error)

func MarshalCreateMetadata

func MarshalCreateMetadata(metadata *common.MetadataMutable) ([]byte, *common.Metadata, error)

func MarshalUpdateMetadata

func MarshalUpdateMetadata(m *common.MetadataMutable, b common.MetadataUpdateEnum, getExtendableMetadata func() (*common.Metadata, error)) ([]byte, *common.Metadata, error)

func NewStatementBuilder

func NewStatementBuilder() sq.StatementBuilderType

Postgres uses $1, $2, etc. for placeholders

func NewTableWithSchema

func NewTableWithSchema(schema string) func(name string) Table

func NewUniqueAlreadyExistsError

func NewUniqueAlreadyExistsError(value string) error

func WrapIfKnownInvalidQueryErr

func WrapIfKnownInvalidQueryErr(err error) error

Get helpful error message for PostgreSQL violation

Types

type Client

type Client struct {
	Pgx PgxIface

	// This is the stdlib connection that is used for transactions
	SqlDB *sql.DB
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (Client) Exec

func (c Client) Exec(ctx context.Context, sql string, args []interface{}) error

Common function for all exec calls

func (*Client) MigrationDown

func (c *Client) MigrationDown(ctx context.Context) error

func (*Client) MigrationStatus

func (c *Client) MigrationStatus(ctx context.Context) ([]*goose.MigrationStatus, error)

func (Client) Query

func (c Client) Query(ctx context.Context, sql string, args []interface{}) (pgx.Rows, error)

Common function for all query calls

func (Client) QueryRow

func (c Client) QueryRow(ctx context.Context, sql string, args []interface{}) (pgx.Row, error)

Common function for all queryRow calls

func (*Client) RunMigrations

func (c *Client) RunMigrations(ctx context.Context) (int, error)

type Config

type Config struct {
	Host          string `yaml:"host" default:"localhost"`
	Port          int    `yaml:"port" default:"5432"`
	Database      string `yaml:"database" default:"opentdf"`
	User          string `yaml:"user" default:"postgres"`
	Password      string `yaml:"password" default:"changeme"`
	RunMigrations bool   `yaml:"runMigrations" default:"true"`
	SSLMode       string `yaml:"sslmode" default:"prefer"`
	Schema        string `yaml:"schema" default:"opentdf"`
}

type DbError

type DbError string
const (
	ErrUniqueConstraintViolation DbError = "ErrUniqueConstraintViolation: value must be unique"
	ErrNotNullViolation          DbError = "ErrNotNullViolation: value cannot be null"
	ErrForeignKeyViolation       DbError = "ErrForeignKeyViolation: value is referenced by another table"
	ErrRestrictViolation         DbError = "ErrRestrictViolation: value cannot be deleted due to restriction"
	ErrNotFound                  DbError = "ErrNotFound: value not found"
	ErrEnumValueInvalid          DbError = "ErrEnumValueInvalid: not a valid enum value"
	ErrUuidInvalid               DbError = "ErrUuidInvalid: value not a valid UUID"
	ErrFqnMissingValue           DbError = "ErrFqnMissingValue: FQN must include a value"
	ErrMissingValue              DbError = "ErrMissingValue: value must be included"
)

func (DbError) Error

func (e DbError) Error() string

type PgxIface

type PgxIface interface {
	Acquire(ctx context.Context) (*pgxpool.Conn, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	QueryRow(context.Context, string, ...any) pgx.Row
	Query(context.Context, string, ...any) (pgx.Rows, error)
	Ping(context.Context) error
	Close()
	Config() *pgxpool.Config
}

We can rename this but wanted to get mocks working.

type Table

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

func (Table) Field

func (t Table) Field(field string) string

func (Table) Name

func (t Table) Name() string

func (Table) WithoutSchema

func (t Table) WithoutSchema() Table

Jump to

Keyboard shortcuts

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