storage

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedConnectionString = errors.New(
		"malformed database connection parameters provided",
	)
	ErrUnableToConnect   = errors.New("unable to open connection to database")
	ErrUnsupportedDriver = fmt.Errorf(
		"unsupported driver, supported drivers are %s",
		[]string{
			postgresqlDriverName,
			mysqlDriverName,
			mssqlDriverName,
			sqliteDriverName,
		},
	)
)

Functions

This section is empty.

Types

type DB added in v0.5.0

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

func NewDB added in v0.5.0

func NewDB(cfg configloader.ConnectionConfig) (DB, error)

NewDB establishes a connection to the database using the connection configuration.

The following errors may be returned:

  • ErrMalformedConnectionString: The provided connection parameters are not in a valid format.
  • ErrUnableToConnect: Unable to make a connection to the database with the provided connection parameters.
  • ErrUnsupportedDriver: The provided driver is not supported.

func (DB) Close added in v0.5.0

func (db DB) Close() error

Close closes the database connection. Any further queries will result in errors, and you should call NewDB again after if you'd like to run more.

func (DB) Exec added in v0.5.0

func (db DB) Exec(query string, args ...any) (sql.Result, error)

Exec is a wrapper around the sql.DB Exec.

func (DB) Query added in v0.5.0

func (db DB) Query(query string, args ...any) (*sql.Rows, error)

Query is a wrapper around the sql.DB Query.

func (DB) QueryRow added in v0.5.0

func (db DB) QueryRow(query string, args ...any) *sql.Row

QueryRow is a wrapper around the sql.DB QueryRow.

func (DB) TableExists added in v0.5.0

func (db DB) TableExists(tableName string) (bool, error)

TableExists checks if the tableName exists within the database currently connected to.

func (*DB) Tx added in v0.5.0

func (db *DB) Tx(fn txFunc) error

Tx executes fn within a transaction block. If fn returns an error, the transaction will be rolled back. Otherwise, it will be committed.

type DBAdapter added in v0.5.0

type DBAdapter interface {
	// ConvertGenericPlaceholders replaces any generic `?` placeholders
	// in `query` for the database driver specific placeholders and returns
	// the updated query.
	ConvertGenericPlaceholders(query string, argsCount int) string
	// TableExists checks if the tableName exists within the
	// database currently connected to.
	TableExists(executor sqlExecutor, tableName string) (bool, error)
	// DatabaseName retrieves the currently selected database name.
	DatabaseName(executor sqlExecutor) (string, error)
	// CreateDSN creates a DSN to be used with sql.Open in the database
	// driver specific format.
	CreateDSN(cfg configloader.ConnectionConfig) string
}

type MSSQLAdapter added in v0.6.0

type MSSQLAdapter struct{}

func (MSSQLAdapter) ConvertGenericPlaceholders added in v0.6.0

func (m MSSQLAdapter) ConvertGenericPlaceholders(
	query string,
	argsCount int,
) string

func (MSSQLAdapter) CreateDSN added in v0.6.0

func (MSSQLAdapter) DatabaseName added in v0.6.0

func (m MSSQLAdapter) DatabaseName(executor sqlExecutor) (string, error)

func (MSSQLAdapter) TableExists added in v0.6.0

func (m MSSQLAdapter) TableExists(
	executor sqlExecutor,
	tableName string,
) (bool, error)

type MySQLAdapter added in v0.5.0

type MySQLAdapter struct{}

func (MySQLAdapter) ConvertGenericPlaceholders added in v0.5.0

func (m MySQLAdapter) ConvertGenericPlaceholders(query string, argsCount int) string

func (MySQLAdapter) CreateDSN added in v0.5.0

func (MySQLAdapter) DatabaseName added in v0.5.0

func (m MySQLAdapter) DatabaseName(executor sqlExecutor) (string, error)

func (MySQLAdapter) TableExists added in v0.5.0

func (m MySQLAdapter) TableExists(
	executor sqlExecutor,
	tableName string,
) (bool, error)

type PostgresqlAdapter added in v0.5.0

type PostgresqlAdapter struct{}

func (PostgresqlAdapter) ConvertGenericPlaceholders added in v0.5.0

func (p PostgresqlAdapter) ConvertGenericPlaceholders(
	query string,
	argsCount int,
) string

func (PostgresqlAdapter) CreateDSN added in v0.5.0

func (PostgresqlAdapter) DatabaseName added in v0.5.0

func (p PostgresqlAdapter) DatabaseName(executor sqlExecutor) (string, error)

func (PostgresqlAdapter) TableExists added in v0.5.0

func (p PostgresqlAdapter) TableExists(
	executor sqlExecutor,
	tableName string,
) (bool, error)

type SqliteAdapter added in v0.6.0

type SqliteAdapter struct{}

func (SqliteAdapter) ConvertGenericPlaceholders added in v0.6.0

func (s SqliteAdapter) ConvertGenericPlaceholders(
	query string,
	argsCount int,
) string

func (SqliteAdapter) CreateDSN added in v0.6.0

func (SqliteAdapter) DatabaseName added in v0.6.0

func (s SqliteAdapter) DatabaseName(executor sqlExecutor) (string, error)

func (SqliteAdapter) TableExists added in v0.6.0

func (s SqliteAdapter) TableExists(
	executor sqlExecutor,
	tableName string,
) (bool, error)

Jump to

Keyboard shortcuts

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