entdb

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package entdb extends the ent db library and satisfies matt's needs for consistency

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDriverLackingBeginTx is returned when the driver does not support BeginTx
	ErrDriverLackingBeginTx = errors.New("driver does not support BeginTx")
	// ErrShuttingDown is returned when operations are attempted during shutdown
	ErrShuttingDown = errors.New("database shutting down")
)

Functions

func BeginShutdown added in v0.18.1

func BeginShutdown()

BeginShutdown marks the system as shutting down. It is safe to call multiple times

func BlockHook added in v0.18.1

func BlockHook() ent.Hook

BlockHook returns an ent.Hook that prevents mutations after shutdown begins

func BlockHookWithFlag added in v0.18.1

func BlockHookWithFlag(f *ShutdownFlag) ent.Hook

BlockHookWithFlag returns an ent.Hook tied to the provided shutdown flag it's added as a global hook to the ent.Client, so it's attached to all mutations the hook wraps the next mutator in the chain; before allowing the mutation to proceed, it checks the shutdown flag, and returns an error and blocks the mutation if the flag is NOT set, it just calls the next mutator in the chain This function is intended to ensure data consistency and avoid partial writes or race conditions as the application is shutting down

func BlockInterceptor added in v0.18.1

func BlockInterceptor() ent.Interceptor

BlockInterceptor returns an ent.Interceptor that prevents queries once shutdown starts

func BlockInterceptorWithFlag added in v0.18.1

func BlockInterceptorWithFlag(f *ShutdownFlag) ent.Interceptor

BlockInterceptorWithFlag returns an interceptor tied to the provided shutdown flag it works similarly to BlockHook, but is used for intercepting queries it checks the shutdown flag before allowing the query to proceed if the flag is set, it returns ErrShuttingDown and blocks the query if the flag is NOT set, it allows the query to proceed this is useful for preventing new queries from being executed while the system is shutting down

func EnablePostgresExtensions added in v0.6.21

func EnablePostgresExtensions(db *sql.DB) error

EnablePostgresExtensions enables the postgres extensions needed when running migrations

func EnablePostgresOption added in v0.6.24

func EnablePostgresOption(db *sql.DB) schema.MigrateOption

EnablePostgresOption returns a schema.MigrateOption that will enable the Postgres extension if needed for running atlas migrations

func GracefulClose added in v0.18.1

func GracefulClose(ctx context.Context, c *ent.Client, interval time.Duration) error

GracefulClose waits for in-flight queries to finish before closing the database connections

func GracefulCloseWithFlag added in v0.18.1

func GracefulCloseWithFlag(ctx context.Context, c *ent.Client, interval time.Duration, f *ShutdownFlag) error

GracefulCloseWithFlag behaves like GracefulClose but uses the provided shutdown flag

func IsShuttingDown added in v0.18.1

func IsShuttingDown() bool

IsShuttingDown reports whether GracefulClose was invoked

func New added in v0.2.0

func New(ctx context.Context, c entx.Config, jobOpts []riverqueue.Option, opts ...ent.Option) (*ent.Client, error)

New returns a ent client with a primary and secondary, if configured, write database

func NewTestClient

func NewTestClient(ctx context.Context, ctr *testutils.TestFixture, jobOpts []riverqueue.Option, entOpts []ent.Option) (*ent.Client, error)

NewTestClient creates a entdb client that can be used for TEST purposes ONLY

func NewTestFixture

func NewTestFixture() *testutils.TestFixture

NewTestFixture creates a test container for testing purposes

func ResetShutdown added in v0.18.1

func ResetShutdown()

ResetShutdown clears the shutdown flag. It is intended for tests

func SQLDB added in v0.18.1

func SQLDB(c *ent.Client) *stdsql.DB

SQLDB unwraps the ent driver and returns the underlying *sql.DB

Types

type ShutdownFlag added in v0.18.1

type ShutdownFlag struct {
	// contains filtered or unexported fields
}

ShutdownFlag tracks whether a shutdown is in progress

func (*ShutdownFlag) Begin added in v0.18.1

func (s *ShutdownFlag) Begin()

Begin sets the shutdown flag to true, indicating that a shutdown is in progress

func (*ShutdownFlag) IsSet added in v0.18.1

func (s *ShutdownFlag) IsSet() bool

IsSet checks if the shutdown flag is set to true

func (*ShutdownFlag) Reset added in v0.18.1

func (s *ShutdownFlag) Reset()

Reset clears the shutdown flag, indicating that a shutdown is no longer in progress

Jump to

Keyboard shortcuts

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