Documentation
¶
Index ¶
- func Module() fx.Option
- type Client
- func (c *Client) Close() error
- func (c *Client) LockWithWait(ctx context.Context, req LockRequest) error
- func (c *Client) Reader(ctx context.Context) *ent.Client
- func (c *Client) TxFromContext(ctx context.Context) *ent.Tx
- func (c *Client) WithTx(ctx context.Context, fn func(ctx context.Context) error) error
- func (c *Client) Writer(ctx context.Context) *ent.Client
- type EntClients
- type IClient
- type LockRequest
- type SentryClient
- func (c *SentryClient) Close() error
- func (c *SentryClient) LockWithWait(ctx context.Context, req LockRequest) error
- func (c *SentryClient) Reader(ctx context.Context) *ent.Client
- func (c *SentryClient) TxFromContext(ctx context.Context) *ent.Tx
- func (c *SentryClient) WithTx(ctx context.Context, fn func(context.Context) error) error
- func (c *SentryClient) Writer(ctx context.Context) *ent.Client
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps ent.Client to provide transaction management and read/write routing
func (*Client) LockWithWait ¶ added in v1.0.60
func (c *Client) LockWithWait(ctx context.Context, req LockRequest) error
LockWithWait acquires an advisory lock based on the provided request. If Timeout is nil, defaults to 30 seconds. The key should be the entity ID (e.g., wallet ID). Auto released on tx commit/rollback. Must be called inside a transaction.
func (*Client) Reader ¶ added in v1.0.32
Reader returns the appropriate client for read operations. Intelligently routes to ensure consistency when needed.
Use this for: Get, List, Count, Query operations
func (*Client) TxFromContext ¶
TxFromContext returns the transaction from context if it exists
type EntClients ¶ added in v1.0.32
EntClients holds both writer and reader ENT clients
func NewEntClients ¶ added in v1.0.32
func NewEntClients(config *config.Configuration, logger *logger.Logger) (*EntClients, error)
NewEntClients creates both writer and reader Ent clients
type IClient ¶
type IClient interface {
// WithTx wraps the given function in a transaction
WithTx(ctx context.Context, fn func(context.Context) error) error
// TxFromContext returns the transaction from context if it exists
TxFromContext(ctx context.Context) *ent.Tx
// Writer returns the writer client for write operations.
// Always routes to the primary database (writer endpoint).
//
// Routing:
// - Inside transaction: returns transaction client (writer)
// - Outside transaction: returns writer client
//
// Use for: Create, Update, Delete, Save, Exec operations
Writer(ctx context.Context) *ent.Client
// Reader returns the appropriate client for read operations.
// Intelligently routes based on context to ensure consistency when needed.
//
// Routing:
// - Inside transaction: returns transaction client (writer) for read-your-writes consistency
// - Force writer flag set: returns writer client for read-after-write consistency
// - Otherwise: returns reader client (read replica if available)
//
// Use for: Get, List, Count, Query operations
Reader(ctx context.Context) *ent.Client
// LockWithWait acquires an advisory lock with a default timeout of 30 seconds.
// The key should be the entity ID (e.g., wallet ID).
// Must be called inside a transaction. Lock is automatically released on commit/rollback.
LockWithWait(ctx context.Context, req LockRequest) error
// Close closes the database connection
Close() error
}
IClient defines the interface for postgres client operations
func NewSentryClient ¶ added in v1.0.17
NewSentryClient creates a new Sentry-instrumented Postgres client
type LockRequest ¶ added in v1.0.60
type LockRequest struct {
// Key is the entity ID (e.g., wallet ID) to lock
Key string
// Timeout is the maximum time to wait for the lock.
// If nil, defaults to 30 seconds. Must be positive.
Timeout *time.Duration
}
LockRequest represents a request to acquire an advisory lock
func (*LockRequest) GetTimeout ¶ added in v1.0.60
func (r *LockRequest) GetTimeout() time.Duration
GetTimeout returns the timeout duration, defaulting to 30 seconds if nil. Ensures the returned duration is always positive (minimum 1ms).
type SentryClient ¶ added in v1.0.17
type SentryClient struct {
// contains filtered or unexported fields
}
SentryClient wraps the standard postgres client with Sentry monitoring
func (*SentryClient) Close ¶ added in v1.0.32
func (c *SentryClient) Close() error
Close closes the database connection
func (*SentryClient) LockWithWait ¶ added in v1.0.60
func (c *SentryClient) LockWithWait(ctx context.Context, req LockRequest) error
LockWithWait acquires an advisory lock with wait
func (*SentryClient) Reader ¶ added in v1.0.32
func (c *SentryClient) Reader(ctx context.Context) *ent.Client
Reader returns the appropriate client for read operations
func (*SentryClient) TxFromContext ¶ added in v1.0.17
func (c *SentryClient) TxFromContext(ctx context.Context) *ent.Tx
TxFromContext returns the transaction from context if it exists