Documentation ¶
Index ¶
- Variables
- func CreateTransaction(db *sql.DB, fn func(tx *sql.Tx) error) error
- func Disconnect(db *sql.DB) error
- func RunQueriesConcurrently(db *sql.DB, queries ...func(db *sql.DB) error) *[]error
- func RunQueriesConcurrentlyWithCancel(db *sql.DB, queries ...func(db *sql.DB, ctx context.Context) error) *[]error
- type Config
- type ConnConfig
- type ConnHandler
- type DefaultConnHandler
- type DefaultService
- func (d *DefaultService) CreateTransaction(fn func(tx *sql.Tx) error) error
- func (d *DefaultService) DB() *sql.DB
- func (d *DefaultService) Exec(query *string, params ...interface{}) (sql.Result, error)
- func (d *DefaultService) Migrate(queries ...string) error
- func (d *DefaultService) QueryRow(query *string, params ...interface{}) *sql.Row
- func (d *DefaultService) ScanRow(row *sql.Row, destinations ...interface{}) error
- type Service
Constants ¶
This section is empty.
Variables ¶
var (
ErrNilService = errors.New("service cannot be nil")
)
Functions ¶
func CreateTransaction ¶
CreateTransaction creates a transaction for the database
func Disconnect ¶ added in v0.5.0
Disconnect closes the SQL connection
func RunQueriesConcurrently ¶ added in v0.4.8
RunQueriesConcurrently runs multiple queries concurrently
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
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
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
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