entdb

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package entdb extends the ent db library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntClientConfig

type EntClientConfig struct {
	// Debug to print debug database logs
	Debug bool
	// SQL Driver name from dialect.Driver
	DriverName string
	// Logger used for debug logs
	Logger zap.SugaredLogger
	// Primary write database source (required)
	PrimaryDBSource string
	// Secondary write databsae source (optional)
	SecondaryDBSource string
}

EntClientConfig configures the entsql drivers

func (*EntClientConfig) NewEntDBDriver added in v0.1.1

func (c *EntClientConfig) NewEntDBDriver(ctx context.Context) (*ent.Client, error)

NewEntDBDriver returns a ent db client

func (*EntClientConfig) NewMultiDriverDBClient

func (c *EntClientConfig) NewMultiDriverDBClient(ctx context.Context) (*ent.Client, error)

NewMultiDriverDBClient returns a ent client with a primary and secondary write database

type MultiWriteDriver

type MultiWriteDriver struct {
	// Wp (write-primary), Ws (write-secondary) Drivers
	Wp, Ws dialect.Driver
}

MultiWriteDriver allows you to write to a primary and secondary database

func (*MultiWriteDriver) BeginTx

func (d *MultiWriteDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)

BeginTx adds an log-id for the transaction and calls the underlying driver BeginTx command if it is supported.

func (*MultiWriteDriver) Close

func (d *MultiWriteDriver) Close() error

Close the underlying connections

func (*MultiWriteDriver) Dialect

func (d *MultiWriteDriver) Dialect() string

Dialect returns the dialect name of the primary driver

func (*MultiWriteDriver) Exec

func (d *MultiWriteDriver) Exec(ctx context.Context, query string, args, v any) error

Exec logs its params and calls the underlying driver Exec method for both write drivers

func (*MultiWriteDriver) Query

func (d *MultiWriteDriver) Query(ctx context.Context, query string, args, v any) error

Query will query the primary write database

func (*MultiWriteDriver) Tx

Tx wraps the Exec and Query operations in transaction.

Jump to

Keyboard shortcuts

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