stdent

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 5 Imported by: 0

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 AuthenticatedUser added in v0.0.30

func AuthenticatedUser(ctx context.Context) (string, bool)

AuthenticatedUser returns the user that the context is authenticated for.

func WithAuthenticatedOrganizations added in v0.0.30

func WithAuthenticatedOrganizations(
	ctx context.Context, first OrganizationRole, more ...OrganizationRole,
) context.Context

WithAuthenticatedOrganizations declares on the context that any calls carrying the context has access to these organizations with the provided role.

func WithAuthenticatedUser added in v0.0.30

func WithAuthenticatedUser(ctx context.Context, userID string) context.Context

WithAuthenticatedUser declares on the context that it is has access to a user with the provided id.

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 AuthenticatedOrganizations added in v0.0.30

func AuthenticatedOrganizations(ctx context.Context) (ors []OrganizationRole, ok bool)

AuthenticatedOrganizations 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

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 NewAuthenticatedTxHook added in v0.0.30

func NewAuthenticatedTxHook(
	authenticatedUserSetting string,
	authenticatedOrganizationsSetting string,
	anonymousUserID string,
) TxHookFunc

NewAuthenticatedTxHook is transaction hook that sets a setting on the transaction for supporting RLS policies that follow a standard multi-tenancy design outlined here: https://www.flightcontrol.dev/blog/ultimate-guide-to-multi-tenant-saas-data-modeling

Jump to

Keyboard shortcuts

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