Documentation
¶
Overview ¶
Package postgresstore is the flag source of a PostgreSQL database: a flag set file is one table, read with one SELECT, and the store answers with a virtual flag set file that it builds from the rows of the table (one flag for each row, the way GO Feature Flag stores them). It is the only package of the flag sources that imports the PostgreSQL driver.
Index ¶
Constants ¶
const (
// KeySuffix ends the key of a flag set: the table is the key without it.
KeySuffix = ".json"
)
Variables ¶
var ( // ErrURI is the cause of a URI that the driver cannot parse. The cause of the driver is dropped: it may quote a // part of the URI. ErrURI = fmt.Errorf("%w: the URI cannot be parsed", objectstore.ErrInvalidConfig) // ErrTLS is the cause of a TLS setting that cannot be used (a CA bundle that holds no certificate). ErrTLS = fmt.Errorf("%w: the TLS setting cannot be used", objectstore.ErrInvalidConfig) // ErrClient is the cause of a pool that the driver cannot build from the setting. ErrClient = fmt.Errorf("%w: the PostgreSQL pool cannot be built", objectstore.ErrInvalidConfig) // ErrKeyRefused is the cause of a key that is no table name followed by ".json". ErrKeyRefused = errors.New("objectstore: the key is no table name with the .json suffix") // ErrAccessRefused is the cause of an answer that refuses the login or the permission (an authentication error, or // "permission denied"). ErrAccessRefused = errors.New("objectstore: PostgreSQL access refused") // ErrColumn is the cause of an answer that says a column of the setting is not in the table. ErrColumn = errors.New("objectstore: PostgreSQL table has no such column") // error. The driver error is dropped: it names the host and the user. ErrUnavailable = errors.New("objectstore: PostgreSQL is not available") )
The causes of a refused setting or key. None of them holds a host, a name or a credential.
Functions ¶
This section is empty.
Types ¶
type Columns ¶
type Columns struct {
// FlagName holds the name of the flag; the default is flag_name.
FlagName string
// Flagset holds the flag set of the row; the default is flagset. It is read only for a key with a flag set.
Flagset string
// Config holds the JSON definition of the flag; the default is config.
Config string
}
Columns are the names of the columns of the tables. An empty name is the default of GO Feature Flag.
type Config ¶
type Config struct {
// Tracing are the OpenTelemetry providers of the store: with them enabled every query and connection has a client
// span, from the stock instrumentation of the driver (otelpgx). The span carries the server address and port and the
// database; never the statement, a parameter or a row, and never the URI. The zero value instruments nothing.
Tracing tracing.Providers
// Logger receives the one line about rows that are not flags. Nil discards it.
Logger *slog.Logger
// URI is the connection string. It holds the user and the password, and is never printed.
URI storekit.Secret
// Columns are the column names of the tables.
Columns Columns
// CABundlePEM are the certificate authorities that sign the server, instead of the system roots. It turns TLS on
// and verifies the name of the server.
CABundlePEM []byte
// MinTLSVersion is the lowest TLS version of a TLS connection; zero means TLS 1.2.
MinTLSVersion uint16
// RequestTimeout bounds one Get from the request to the last row. Zero means [storekit.DefaultCloudRequestTimeout].
RequestTimeout time.Duration
}
Config is the setting of a Store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an objectstore.ObjectStore on the tables of one PostgreSQL database. A key is the name of a table and ".json" (flags.json reads the table flags, app.flags.json the table flags of the schema app), and the store answers with one JSON document, the flag file, built from every row of the table. See Store.Get for the rules.
func New ¶
New checks the setting and returns the store. The pool opens no connection before the first Get. ctx is for the start of the pool only: the reads take their own.
func (*Store) Close ¶
Close closes the pool: the connections are closed, and its background check stops.
func (*Store) CloseIdleConnections ¶
func (*Store) CloseIdleConnections()
CloseIdleConnections does nothing: the pool owns its connections and closes the idle ones by itself.
func (*Store) Format ¶
Format implements fmt.Formatter: every verb prints the name of the type and nothing of the setting.
func (*Store) Get ¶
func (s *Store) Get(ctx context.Context, req objectstore.GetRequest) (objectstore.Object, error)
Get implements objectstore.ObjectStore. The answer is the flag file of the table.
- The ETag is the SHA-256 of that document, so an unchanged table is objectstore.ErrNotModified. The document is rebuilt with its names in order and its definitions in canonical form: rows that differ only in the order they are read in, or in the order of the members of their JSON, give the same ETag.
- PostgreSQL keeps no modification time for a table, and the time of a replica would differ between readers: Modified is the zero time, the same for every reader.
- A table that does not exist is objectstore.ErrNotFound; one that exists and holds no row is the empty flag set.
- The table is read with one SELECT. A statement sees one snapshot of the table, so the answer is the table as it was at one moment, never a mix of two transactions.