sql

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilService = errors.New("service cannot be nil")
)

Functions

func CreateTransaction

func CreateTransaction(db *sql.DB, fn func(tx *sql.Tx) error) error

CreateTransaction creates a transaction for the database

func Disconnect added in v0.5.0

func Disconnect(db *sql.DB) error

Disconnect closes the SQL connection

func RunQueriesConcurrently added in v0.4.8

func RunQueriesConcurrently(
	db *sql.DB,
	queries ...func(db *sql.DB) error,
) *[]error

RunQueriesConcurrently runs multiple queries concurrently

func RunQueriesConcurrentlyWithCancel added in v0.4.12

func RunQueriesConcurrentlyWithCancel(
	db *sql.DB,
	queries ...func(db *sql.DB, ctx context.Context) error,
) *[]error

RunQueriesConcurrentlyWithCancel runs multiple queries concurrently with a cancel context

Types

type Config added in v0.4.6

type Config interface {
	DriverName() string
	DataSourceName() string
	MaxOpenConnections() int
	MaxIdleConnections() int
	ConnectionMaxLifetime() time.Duration
	ConnectionMaxIdleTime() time.Duration
}

Config interface

type ConnConfig added in v0.5.0

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

ConnConfig struct

func NewConnConfig added in v0.5.0

func NewConnConfig(
	driverName,
	dataSourceName string,
	maxOpenConnections,
	maxIdleConnections int,
	connectionMaxIdleTime,
	connectionMaxLifetime time.Duration,
) (*ConnConfig, error)

NewConnConfig creates a new configuration for the connection

func (*ConnConfig) ConnectionMaxIdleTime added in v0.5.0

func (c *ConnConfig) ConnectionMaxIdleTime() time.Duration

ConnectionMaxIdleTime returns the connection max idle time

func (*ConnConfig) ConnectionMaxLifetime added in v0.5.0

func (c *ConnConfig) ConnectionMaxLifetime() time.Duration

ConnectionMaxLifetime returns the connection max lifetime

func (*ConnConfig) DataSourceName added in v0.5.0

func (c *ConnConfig) DataSourceName() string

DataSourceName returns the data source name

func (*ConnConfig) DriverName added in v0.5.0

func (c *ConnConfig) DriverName() string

DriverName returns the driver name

func (*ConnConfig) MaxIdleConnections added in v0.5.0

func (c *ConnConfig) MaxIdleConnections() int

MaxIdleConnections returns the maximum idle connections

func (*ConnConfig) MaxOpenConnections added in v0.5.0

func (c *ConnConfig) MaxOpenConnections() int

MaxOpenConnections returns the maximum open connections

type ConnHandler added in v0.5.0

type ConnHandler interface {
	Connect() (*sql.DB, error)
	DB() (*sql.DB, error)
	Disconnect()
}

ConnHandler interface

type DefaultConnHandler added in v0.5.0

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

DefaultConnHandler struct

func NewDefaultConnHandler added in v0.5.0

func NewDefaultConnHandler(
	driverName, dataSourceName string,
	config Config,
) (*DefaultConnHandler, error)

NewDefaultConnHandler creates a new connection

func (*DefaultConnHandler) Connect added in v0.5.0

func (d *DefaultConnHandler) Connect() (*sql.DB, error)

Connect returns a new SQL connection

func (*DefaultConnHandler) DB added in v0.5.0

func (d *DefaultConnHandler) DB() (*sql.DB, error)

DB returns the SQL connection

type DefaultService added in v0.5.0

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

DefaultService is the default service struct

func NewDefaultService added in v0.5.0

func NewDefaultService(db *sql.DB) (
	instance *DefaultService,
	err error,
)

NewDefaultService creates a new default service

func (*DefaultService) CreateTransaction added in v0.5.0

func (d *DefaultService) CreateTransaction(fn func(tx *sql.Tx) error) error

CreateTransaction creates a transaction for the database

func (*DefaultService) DB added in v0.5.0

func (d *DefaultService) DB() *sql.DB

DB returns the database

func (*DefaultService) Exec added in v0.5.0

func (d *DefaultService) Exec(query *string, params ...interface{}) (
	sql.Result,
	error,
)

Exec executes a query with parameters and returns the result

func (*DefaultService) Migrate added in v0.5.0

func (d *DefaultService) Migrate(queries ...string) error

Migrate migrates the database

func (*DefaultService) QueryRow added in v0.5.0

func (d *DefaultService) QueryRow(
	query *string,
	params ...interface{},
) *sql.Row

QueryRow runs a query row with parameters and returns the result row

func (*DefaultService) ScanRow added in v0.5.0

func (d *DefaultService) ScanRow(
	row *sql.Row,
	destinations ...interface{},
) error

ScanRow scans a row

type Service added in v0.5.0

type Service interface {
	DB() *sql.DB
	Migrate(queries ...string) error
	CreateTransaction(fn func(tx *sql.Tx) error) error
	Exec(query *string, params ...interface{}) (sql.Result, error)
	QueryRow(query *string, params ...interface{}) *sql.Row
	ScanRow(row *sql.Row, destinations ...interface{}) error
}

Service is the interface for the service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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