Documentation
¶
Overview ¶
Package sqlstore is connectionforge's [connectionforge.Store] and [connectionforge.Leaser] on SQLite or PostgreSQL, through Ent.
The host owns the database: it opens it, passes it to New, calls Store.Migrate, and applies its tenancy policy to Store.Tables. Every operation runs in its own transaction and calls the host's TxHook first, so a session setting such as the tenant for row-level security applies to it. Queries also filter by owner in code, so isolation does not depend on the hook alone.
This package imports no database driver; the host chooses one. For SQLite, give the store a database with one open connection or immediate transactions, so that concurrent writers queue instead of failing, and with foreign keys enabled, which Ent requires to migrate a SQLite database.
Index ¶
- Constants
- type Dialect
- type Option
- type Store
- func (s *Store) Acquire(ctx context.Context, key string, ttl time.Duration) (cf.Lease, error)
- func (s *Store) ActiveCredential(ctx context.Context, owner cf.OwnerID, id string) (cf.Credential, error)
- func (s *Store) CreateConnection(ctx context.Context, in cf.Connection) (cf.Connection, error)
- func (s *Store) DeleteConnection(ctx context.Context, owner cf.OwnerID, id string) error
- func (s *Store) DestroyCredentials(ctx context.Context, owner cf.OwnerID, id string) error
- func (s *Store) GetConnection(ctx context.Context, owner cf.OwnerID, id string) (cf.Connection, error)
- func (s *Store) ListBindings(ctx context.Context, owner cf.OwnerID, id string) ([]cf.Binding, error)
- func (s *Store) ListConnections(ctx context.Context, owner cf.OwnerID, f cf.Filter) ([]cf.Connection, error)
- func (s *Store) ListGrants(ctx context.Context, owner cf.OwnerID, id string) ([]cf.Grant, error)
- func (s *Store) Migrate(ctx context.Context) error
- func (s *Store) PutBinding(ctx context.Context, b cf.Binding) error
- func (s *Store) PutGrant(ctx context.Context, g cf.Grant) error
- func (s *Store) RemoveBinding(ctx context.Context, owner cf.OwnerID, id string, cons cf.Consumer, ...) error
- func (s *Store) RemoveGrant(ctx context.Context, owner cf.OwnerID, id string, p cf.Principal) error
- func (s *Store) SwapCredential(ctx context.Context, expectActive int, next cf.Credential) error
- func (s *Store) Tables() []string
- func (s *Store) UpdateConnection(ctx context.Context, in cf.Connection) (cf.Connection, error)
- type TxHook
Constants ¶
const ( ConnectionTable = "connectionforge_connections" CredentialTable = "connectionforge_credentials" GrantTable = "connectionforge_grants" BindingTable = "connectionforge_bindings" LeaseTable = "connectionforge_leases" )
Table names. Every table except LeaseTable has an owner_id column.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Store)
Option configures a Store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a connectionforge store in a SQL database. It is safe for concurrent use.
func New ¶
New returns a store over db. The caller owns db and closes it. It does not create the schema: call Store.Migrate.
func (*Store) Acquire ¶
Acquire implements cf.Leaser. An expired lease is taken over by a conditional update, and a new one is created; a unique index on the name decides between concurrent creators. Expiry uses the store's clock, so processes sharing a database should have synchronized clocks.
func (*Store) ActiveCredential ¶
func (s *Store) ActiveCredential(ctx context.Context, owner cf.OwnerID, id string) (cf.Credential, error)
ActiveCredential implements cf.CredentialStore.
func (*Store) CreateConnection ¶
func (s *Store) CreateConnection(ctx context.Context, in cf.Connection) (cf.Connection, error)
CreateConnection implements cf.ConnectionStore.
func (*Store) DeleteConnection ¶
DeleteConnection implements cf.ConnectionStore.
func (*Store) DestroyCredentials ¶
DestroyCredentials implements cf.CredentialStore.
func (*Store) GetConnection ¶
func (s *Store) GetConnection(ctx context.Context, owner cf.OwnerID, id string) (cf.Connection, error)
GetConnection implements cf.ConnectionStore.
func (*Store) ListBindings ¶
func (s *Store) ListBindings(ctx context.Context, owner cf.OwnerID, id string) ([]cf.Binding, error)
ListBindings implements cf.BindingStore.
func (*Store) ListConnections ¶
func (s *Store) ListConnections(ctx context.Context, owner cf.OwnerID, f cf.Filter) ([]cf.Connection, error)
ListConnections implements cf.ConnectionStore.
func (*Store) ListGrants ¶
ListGrants implements cf.GrantStore.
func (*Store) Migrate ¶
Migrate creates or updates the schema to match this version of the store. It is idempotent and runs outside the transaction hook, so the host runs it with a role allowed to change the schema.
func (*Store) PutBinding ¶
PutBinding implements cf.BindingStore.
func (*Store) PutGrant ¶
PutGrant implements cf.GrantStore.
func (*Store) RemoveBinding ¶
func (s *Store) RemoveBinding(ctx context.Context, owner cf.OwnerID, id string, cons cf.Consumer, purpose string) error
RemoveBinding implements cf.BindingStore.
func (*Store) RemoveGrant ¶
RemoveGrant implements cf.GrantStore.
func (*Store) SwapCredential ¶
SwapCredential implements cf.CredentialStore. The unique index on (owner, connection, version) decides between concurrent swaps.
func (*Store) Tables ¶
Tables returns the tables that hold owned records, each with an owner_id column, for the host's tenancy policy. The lease table is not among them.
func (*Store) UpdateConnection ¶
func (s *Store) UpdateConnection(ctx context.Context, in cf.Connection) (cf.Connection, error)
UpdateConnection implements cf.ConnectionStore.