database

package
v0.0.0-...-21d0996 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("not found")
	ErrInvalidID             = errors.New("ID is not in its proper form")
	ErrAuthenticationFailure = errors.New("authentication failed")
	ErrForbidden             = errors.New("attempted action is not allowed")
)

Set of error variables for CRUD operations.

Functions

func NamedCountQuery

func NamedCountQuery(ctx context.Context, db *sqlx.DB, query string, data interface{}) (int, error)

NamedCountQuery is a helper function for executing queries that return a count.

@param ctx - context
@param db - database connection
@param query - query to execute
@param data - data to bind to the query
@return int - integer value returned from the query
@return error - error if any

func NamedExecQuery

func NamedExecQuery(ctx context.Context, db *sqlx.DB, query string, data interface{}) error

NamedExecQuery - helper function for executing queries that return no rows. Most of the time, this will be used for INSERT, UPDATE, and DELETE queries.

@param ctx - context
@param db - database connection
@param query - query to execute
@param data - data to bind to the query
@return error - error if any

func NamedSliceQuery

func NamedSliceQuery(ctx context.Context, db *sqlx.DB, query string, data interface{}, dest interface{}) error

NamedSliceQuery - helper function for executing queries that return a slice of rows. Most of the time, this will be used for SELECT queries.

@param ctx - context
@param db - database connection
@param query - query to execute
@param data - data to bind to the query
@param dest - destination to scan the rows into
@return error - error if any

func NamedStructQuery

func NamedStructQuery(ctx context.Context, db *sqlx.DB, query string, data interface{}, dest interface{}) error

NamedStructQuery - helper function for executing queries that return a single row. Most of the time, this will be used for SELECT queries.

@param ctx - context
@param db - database connection
@param query - query to execute
@param data - data to bind to the query
@param dest - destination to scan the row into
@return error - error if any

func Open

func Open(config Config) (*sqlx.DB, error)

Open opens the database connection

@param config - Config
@return sqlx.DB
@return error

func Status

func Status(ctx context.Context, db *sqlx.DB) error

Status - check the database connection status and return an error if the connection is not available.

 @param ctx - context
	@param db - database connection
	@return error - error if any

Types

type Config

type Config struct {
	User         string
	Password     string
	Host         string
	Name         string
	MaxIdleConns int
	MaxOpenConns int
	DisableTLS   bool
}

Config is the database configuration Config is the required properties to use the database.

Jump to

Keyboard shortcuts

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