Documentation ¶
Index ¶
- Constants
- Variables
- func IsQueryBuilderSetClauseError(err error) bool
- func KeyAccessServerProtoJSON(keyAccessServerJSON []byte) ([]*policy.KeyAccessServer, error)
- func MarshalCreateMetadata(metadata *common.MetadataMutable) ([]byte, *common.Metadata, error)
- func MarshalUpdateMetadata(m *common.MetadataMutable, b common.MetadataUpdateEnum, ...) ([]byte, *common.Metadata, error)
- func NewStatementBuilder() sq.StatementBuilderType
- func NewTable(schema string) func(name string) Table
- func NewUniqueAlreadyExistsError(value string) error
- func StatusifyError(err error, fallbackErr string, log ...any) error
- func WrapIfKnownInvalidQueryErr(err error) error
- type Client
- func (c *Client) Close()
- func (c Client) Exec(ctx context.Context, sql string, args []interface{}) error
- func (c *Client) MigrationDown(ctx context.Context, migrations *embed.FS) error
- func (c *Client) MigrationStatus(ctx context.Context) ([]*goose.MigrationStatus, error)
- func (c *Client) MigrationsEnabled() bool
- func (c Client) Query(ctx context.Context, sql string, args []interface{}) (pgx.Rows, error)
- func (c Client) QueryRow(ctx context.Context, sql string, args []interface{}) (pgx.Row, error)
- func (c *Client) RanMigrations() bool
- func (c *Client) RunMigrations(ctx context.Context, migrations *embed.FS) (int, error)
- func (c *Client) Schema() string
- type Config
- type OptsFunc
- type PgxIface
- type Table
Constants ¶
const ( ErrTextCreationFailed = "resource creation failed" ErrTextDeletionFailed = "resource deletion failed" ErrTextDeactivationFailed = "resource deactivation failed" ErrTextGetRetrievalFailed = "resource retrieval failed" ErrTextListRetrievalFailed = "resource list retrieval failed" ErrTextUpdateFailed = "resource update failed" ErrTextNotFound = "resource not found" ErrTextConflict = "resource unique field violation" ErrTextRelationInvalid = "resource relation invalid" ErrTextEnumValueInvalid = "enum value invalid" ErrTextUUIDInvalid = "invalid input syntax for type uuid" ErrTextRestrictViolation = "intended action would violate a restriction" ErrTextFqnMissingValue = "FQN must specify a valid value and be of format 'https://<namespace>/attr/<attribute name>/value/<value>'" )
Variables ¶
var ( ErrUniqueConstraintViolation = errors.New("ErrUniqueConstraintViolation: value must be unique") ErrNotNullViolation = errors.New("ErrNotNullViolation: value cannot be null") ErrForeignKeyViolation = errors.New("ErrForeignKeyViolation: value is referenced by another table") ErrRestrictViolation = errors.New("ErrRestrictViolation: value cannot be deleted due to restriction") ErrNotFound = errors.New("ErrNotFound: value not found") ErrEnumValueInvalid = errors.New("ErrEnumValueInvalid: not a valid enum value") ErrUUIDInvalid = errors.New("ErrUUIDInvalid: value not a valid UUID") ErrFqnMissingValue = errors.New("ErrFqnMissingValue: FQN must include a value") ErrMissingValue = errors.New("ErrMissingValue: value must be included") )
Functions ¶
func KeyAccessServerProtoJSON ¶
func KeyAccessServerProtoJSON(keyAccessServerJSON []byte) ([]*policy.KeyAccessServer, error)
func MarshalCreateMetadata ¶
func MarshalUpdateMetadata ¶
func NewStatementBuilder ¶
func NewStatementBuilder() sq.StatementBuilderType
Postgres uses $1, $2, etc. for placeholders
func WrapIfKnownInvalidQueryErr ¶
Get helpful error message for PostgreSQL violation
Types ¶
type Client ¶
type Client struct { Pgx PgxIface Logger *logger.Logger // This is the stdlib connection that is used for transactions SQLDB *sql.DB // contains filtered or unexported fields }
A wrapper around a pgxpool.Pool and sql.DB reference.
Each service should have a single instance of the Client to share a connection pool, schema (driven by the service namespace), and an embedded file system for migrations.
The 'search_path' is set to the schema on connection to the database.
If the database config 'runMigrations' is set to true, the client will run migrations on startup, once per namespace (as there should only be one embedded migrations FS per namespace).
Multiple pools, schemas, or migrations per service are not supported. Multiple databases per PostgreSQL instance or multiple PostgreSQL servers per platform instance are not supported.
func (*Client) MigrationDown ¶
func (*Client) MigrationStatus ¶
func (*Client) MigrationsEnabled ¶ added in v0.4.18
func (*Client) RanMigrations ¶ added in v0.4.18
func (*Client) RunMigrations ¶
RunMigrations runs the migrations for the schema Schema will be created if it doesn't exist
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" secret:"true"` RunMigrations bool `yaml:"runMigrations" default:"true"` SSLMode string `yaml:"sslmode" default:"prefer"` Schema string `yaml:"schema" default:"opentdf"` VerifyConnection bool `yaml:"verifyConnection" default:"true"` MigrationsFS *embed.FS }
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.