Documentation
¶
Overview ¶
Package stdent provides re-usable code for interacting with the Ent orm.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAccessibleOrganizations ¶ added in v0.0.28
func WithAccessibleOrganizations(ctx context.Context, ors ...OrganizationRole) context.Context
WithAccessibleOrganizations declares on the context that any calls carrying the context has access to these organizations with the provided role.
Types ¶
type OrganizationRole ¶ added in v0.0.28
type OrganizationRole struct { OrganizationID string `json:"organization_id"` Role string `json:"role"` }
OrganizationRole describes a role in an organization. Both fields are encoded as strings such that RLS policies can easily cast it to a type that is relevant in the schema at hand, such as UUID or an enum.
func AccessibleOrganizations ¶ added in v0.0.28
func AccessibleOrganizations(ctx context.Context) (ors []OrganizationRole)
AccessibleOrganizations returns the organization and roles from the context or panic.
type TxHookDriver ¶ added in v0.0.28
type TxHookDriver struct { entdialect.Driver // contains filtered or unexported fields }
TxHookDriver is an Ent driver that wraps a base driver to allow a hook to be configured for every transaction that is started. Useful for sql settings scoped to the transaction such as the current_user_id, or the role.
func NewTxHookDriver ¶
func NewTxHookDriver(base entdialect.Driver, hook TxHookFunc) *TxHookDriver
func (TxHookDriver) BeginTx ¶ added in v0.0.28
func (d TxHookDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (entdialect.Tx, error)
BeginTx calls the base driver's method if it's supported and calls our hook.
func (TxHookDriver) Tx ¶ added in v0.0.28
func (d TxHookDriver) Tx(ctx context.Context) (entdialect.Tx, error)
Tx calls the base driver's method with the same symbol and invokes our hook.
type TxHookFunc ¶
type TxHookFunc func(ctx context.Context, tx entdialect.Tx) error
func NewAccessibleOrganizationsTxHook ¶ added in v0.0.28
func NewAccessibleOrganizationsTxHook(setting string) TxHookFunc
NewAccessibleOrganizationsTxHook is transaction hook that sets a setting on the transaction for supporting RLS policies that follow the design outlined over here: https://www.flightcontrol.dev/blog/ultimate-guide-to-multi-tenant-saas-data-modeling