database

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const QUERY_NAME = "relations"

Variables

This section is empty.

Functions

func Close

func Close()

Close closes the database connection

func Connect

func Connect(options *ConnectOption) *sqlx.DB

Connect initializes the database connection and sets up the circuit breaker

func DropDatabase

func DropDatabase(dbURL string) error

func ExecuteQuery

func ExecuteQuery(queryName string, data interface{}) (sql.Result, error)

ExecuteQuery is a general function to execute a write operation (INSERT, UPDATE, DELETE) with a circuit breaker

func Fetch

func Fetch(dest interface{}, ids ...interface{}) error

Get retrieves multiple records from the database with pagination

func Get

func Get(dest interface{}, queryName string, args ...interface{}) error

func GetDB

func GetDB() *sqlx.DB

GetDB returns the database connection

func LoadQuery

func LoadQuery(queryName string) (string, error)

LoadQuery reads the SQL query from the file and caches it.

func LoadRelations

func LoadRelations(model Model) error

func Query

func Query(ctx context.Context, queryName string, args ...interface{}) (*sqlx.Rows, error)

Query is a general function to execute a read operation that returns multiple rows with a circuit breaker

func QuerySelect

func QuerySelect(queryName string, dest interface{}, args ...interface{}) error

QuerSelect is a general function to execute a read operation that returns multiple rows with a circuit breaker

func Queryx

func Queryx(queryName string, args ...interface{}) (*sqlx.Rows, error)

Query is a general function to execute a read operation that returns multiple rows with a circuit breaker

func TxExecuteQuery

func TxExecuteQuery(tx *sqlx.Tx, queryName string, data interface{}) (sql.Result, error)

TxExecuteQuery is a general function to execute a write operation (INSERT, UPDATE, DELETE) with a circuit breaker

func TxQuery

func TxQuery(ctx context.Context, tx *sqlx.Tx, queryName string, args ...interface{}) (*sqlx.Rows, error)

func UnmarshalJSONTextFields

func UnmarshalJSONTextFields(input interface{}) error

UnmarshalJSONTextFields processes a single struct or a slice of structs to unmarshal fields of type types.JSONText into corresponding Go struct fields based on matching `db` and `json` tags.

Types

type ConnectOption

type ConnectOption struct {
	URL         string
	SqlDir      string
	MaxRequests uint32
	Interval    time.Duration
	Timeout     time.Duration
}

type FetchList

type FetchList struct {
	ID         uuid.UUID `db:"id"`
	TotalCount int       `db:"total_count"`
}

type Filter

type Filter struct {
	Key   string
	Value string
}

type Model

type Model interface {
	TableName() string
	// Scan(any) error
	FetchQuery() string
}

type Paginate

type Paginate struct {
	Limit   int
	Offet   int
	Filters []Filter
}

type Relation

type Relation struct {
	ConstraintName    string `db:"constraint_name"`
	TableName         string `db:"table_name"`
	ColumnName        string `db:"column_name"`
	ForeignTableName  string `db:"foreign_table_name"`
	ForeignColumnName string `db:"foreign_column_name"`
}

func GetRelations

func GetRelations(table string) ([]Relation, error)

Jump to

Keyboard shortcuts

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