db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package db contains database interfaces and functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSQLConnection

func NewSQLConnection(p *ConnParams) (*sql.DB, error)

NewSQLConnection creates a new MySQL DB connection pool

Types

type Adapter

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

Adapter is an adapter for sql.DB so it follows the Conn interface

func NewAdapter

func NewAdapter(db *sql.DB) *Adapter

NewAdapter creates a new Adapter

func (*Adapter) Begin

func (a *Adapter) Begin() (Tx, error)

Begin starts a transaction

func (*Adapter) Exec

func (a *Adapter) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query and returns a Result object

func (*Adapter) Query

func (a *Adapter) Query(query string, args ...any) (Rows, error)

Query executes a query and returns a Rows object

func (*Adapter) QueryRow

func (a *Adapter) QueryRow(query string, args ...any) Row

QueryRow executes a query and returns a Row object

type Conn

type Conn interface {
	Begin() (Tx, error)
	Exec(query string, args ...any) (sql.Result, error)
	Query(query string, args ...any) (Rows, error)
	QueryRow(query string, args ...any) Row
}

Conn generalizes an sql.Conn object

type ConnParams

type ConnParams struct {
	Type     string
	Host     string
	Port     string
	User     string
	Password string
	Database string
}

ConnParams holds parameters for a MySQL DB connection

type MockAdapter

type MockAdapter[T any] struct {
	Conn *tst.Conn[T]
}

MockAdapter is an adapter for tst.Conn so it follows the Conn interface

func NewMockAdapter

func NewMockAdapter[T any](conn *tst.Conn[T]) *MockAdapter[T]

NewMockAdapter creates a new MockAdapter

func (*MockAdapter[T]) Begin

func (a *MockAdapter[T]) Begin() (Tx, error)

Begin starts a transaction

func (*MockAdapter[T]) Exec

func (a *MockAdapter[T]) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query and returns a Result object

func (*MockAdapter[T]) Query

func (a *MockAdapter[T]) Query(query string, args ...any) (Rows, error)

Query executes a query and returns a Rows object

func (*MockAdapter[T]) QueryRow

func (a *MockAdapter[T]) QueryRow(query string, args ...any) Row

QueryRow executes a query and returns a Row object

type Row

type Row interface {
	Scan(dest ...any) error
}

Row generalizes an sql.Row object

type RowScanner

type RowScanner interface {
	Scan(dest ...any) error
}

RowScanner unifies the Row and Rows interface

type Rows

type Rows interface {
	Scan(dest ...any) error
	Next() bool
	Err() error
	Close() error
}

Rows generalizes an sql.Rows object

type Tx

type Tx interface {
	Exec(query string, args ...any) (sql.Result, error)
	Commit() error
	Rollback() error
}

Tx generalizes an sql.Tx object

Jump to

Keyboard shortcuts

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