database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = errors.New("no rows")

Functions

This section is empty.

Types

type ConfigFunc added in v0.1.0

type ConfigFunc func(dbal *DBAL) error

func WithConnectionAdjuster added in v0.1.0

func WithConnectionAdjuster(callback func(connection *sql.DB) error) ConfigFunc

func WithLogger added in v0.1.0

func WithLogger(logger *log.Logger) ConfigFunc

func WithPostRunFunc added in v0.1.0

func WithPostRunFunc(postRunFunc ConfigPostRunFunc) ConfigFunc

func WithPreRunFunc added in v0.1.0

func WithPreRunFunc(preRunFunc ConfigPreRunFunc) ConfigFunc

type ConfigPostRunFunc added in v0.1.0

type ConfigPostRunFunc func(ctx context.Context) error

type ConfigPreRunFunc added in v0.1.0

type ConfigPreRunFunc func(ctx context.Context, statement string, args []any) error

type DBAL

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

func NewDBAL

func NewDBAL(driver Driver, configFuncs ...ConfigFunc) (*DBAL, error)

func (*DBAL) AutoMigrate added in v0.1.0

func (dbal *DBAL) AutoMigrate(ctx context.Context, entities []Entity) error

func (*DBAL) Ping added in v0.0.2

func (dbal *DBAL) Ping() error

func (*DBAL) RawExecute

func (dbal *DBAL) RawExecute(
	ctx context.Context,
	query string,
	parameters map[string]any,
) (sql.Result, error)

func (*DBAL) RawSelect

func (dbal *DBAL) RawSelect(
	ctx context.Context,
	query string,
	parameters map[string]any,
	targetPointer any,
) error

type Driver added in v0.0.5

type Driver interface {
	// Connection Methods
	Driver() string
	DSN() string
	// Migration Methods
	ShowCreateTable(tableName string) string
	ParseCreateTable(s string) Table
	TableFromEntity(e Entity) Table
	CreateTable(t Table) string
	RenameTable(t Table) string
	DropTable(t Table) string
	AddColumn(t Table, c TableColumn) string
	AlterColumn(t Table, c TableColumn) string
	DropColumn(t Table, c TableColumn) string
	AddIndex(t Table, c TableIndex) string
	DropIndex(t Table, c TableIndex) string
	AddForeignKey(t Table, c TableForeignKey) string
	DropForeignKey(t Table, c TableForeignKey) string
	// CRUD Methods
	Insert(e Entity) (string, map[string]any, error)
	Update(e Entity) (string, map[string]any, error)
	Save(e Entity) (string, map[string]any, error)
	Select(e Entity) (Query, error)
	Delete(e Entity) (string, map[string]any, error)
}

type DriverMySQL added in v0.1.0

type DriverMySQL struct {
	Hostname string
	Port     int
	Username string
	Password string
	Name     string
}

func (DriverMySQL) AddColumn added in v0.1.0

func (driver DriverMySQL) AddColumn(t Table, c TableColumn) string

func (DriverMySQL) AddForeignKey added in v0.1.0

func (driver DriverMySQL) AddForeignKey(t Table, c TableForeignKey) string

func (DriverMySQL) AddIndex added in v0.1.0

func (driver DriverMySQL) AddIndex(t Table, c TableIndex) string

func (DriverMySQL) AlterColumn added in v0.1.0

func (driver DriverMySQL) AlterColumn(t Table, c TableColumn) string

func (DriverMySQL) CreateTable added in v0.1.0

func (driver DriverMySQL) CreateTable(t Table) string

func (DriverMySQL) DSN added in v0.1.0

func (driver DriverMySQL) DSN() string

func (DriverMySQL) Delete added in v0.1.0

func (driver DriverMySQL) Delete(entity Entity) (string, map[string]any, error)

func (DriverMySQL) Driver added in v0.1.0

func (driver DriverMySQL) Driver() string

func (DriverMySQL) DropColumn added in v0.1.0

func (driver DriverMySQL) DropColumn(t Table, c TableColumn) string

func (DriverMySQL) DropForeignKey added in v0.1.0

func (driver DriverMySQL) DropForeignKey(t Table, c TableForeignKey) string

func (DriverMySQL) DropIndex added in v0.1.0

func (driver DriverMySQL) DropIndex(t Table, c TableIndex) string

func (DriverMySQL) DropTable added in v0.1.0

func (driver DriverMySQL) DropTable(t Table) string

func (DriverMySQL) Insert added in v0.1.0

func (driver DriverMySQL) Insert(entity Entity) (string, map[string]any, error)

func (DriverMySQL) ParseCreateTable added in v0.1.0

func (driver DriverMySQL) ParseCreateTable(s string) Table

func (DriverMySQL) RenameTable added in v0.1.0

func (driver DriverMySQL) RenameTable(t Table) string

func (DriverMySQL) Save added in v0.1.0

func (driver DriverMySQL) Save(entity Entity) (string, map[string]any, error)

func (DriverMySQL) Select added in v0.1.0

func (driver DriverMySQL) Select(entity Entity) (Query, error)

func (DriverMySQL) ShowCreateTable added in v0.1.0

func (driver DriverMySQL) ShowCreateTable(tableName string) string

func (DriverMySQL) TableFromEntity added in v0.1.0

func (driver DriverMySQL) TableFromEntity(e Entity) Table

func (DriverMySQL) Update added in v0.1.0

func (driver DriverMySQL) Update(entity Entity) (string, map[string]any, error)

type DriverPostgres added in v0.1.0

type DriverPostgres struct {
	Hostname string
	Port     int
	Username string
	Password string
	Name     string
}

func (DriverPostgres) AddColumn added in v0.1.0

func (driver DriverPostgres) AddColumn(t Table, c TableColumn) string

func (DriverPostgres) AddForeignKey added in v0.1.0

func (driver DriverPostgres) AddForeignKey(t Table, c TableForeignKey) string

func (DriverPostgres) AddIndex added in v0.1.0

func (driver DriverPostgres) AddIndex(t Table, c TableIndex) string

func (DriverPostgres) AlterColumn added in v0.1.0

func (driver DriverPostgres) AlterColumn(t Table, c TableColumn) string

func (DriverPostgres) CreateTable added in v0.1.0

func (driver DriverPostgres) CreateTable(t Table) string

func (DriverPostgres) DSN added in v0.1.0

func (driver DriverPostgres) DSN() string

func (DriverPostgres) Delete added in v0.1.0

func (driver DriverPostgres) Delete(entity Entity) (string, map[string]any, error)

func (DriverPostgres) Driver added in v0.1.0

func (driver DriverPostgres) Driver() string

func (DriverPostgres) DropColumn added in v0.1.0

func (driver DriverPostgres) DropColumn(t Table, c TableColumn) string

func (DriverPostgres) DropForeignKey added in v0.1.0

func (driver DriverPostgres) DropForeignKey(t Table, c TableForeignKey) string

func (DriverPostgres) DropIndex added in v0.1.0

func (driver DriverPostgres) DropIndex(t Table, c TableIndex) string

func (DriverPostgres) DropTable added in v0.1.0

func (driver DriverPostgres) DropTable(t Table) string

func (DriverPostgres) Insert added in v0.1.0

func (driver DriverPostgres) Insert(entity Entity) (string, map[string]any, error)

func (DriverPostgres) ParseCreateTable added in v0.1.0

func (driver DriverPostgres) ParseCreateTable(s string) Table

func (DriverPostgres) RenameTable added in v0.1.0

func (driver DriverPostgres) RenameTable(t Table) string

func (DriverPostgres) Save added in v0.1.0

func (driver DriverPostgres) Save(entity Entity) (string, map[string]any, error)

func (DriverPostgres) Select added in v0.1.0

func (driver DriverPostgres) Select(entity Entity) (Query, error)

func (DriverPostgres) ShowCreateTable added in v0.1.0

func (driver DriverPostgres) ShowCreateTable(tableName string) string

func (DriverPostgres) TableFromEntity added in v0.1.0

func (driver DriverPostgres) TableFromEntity(entity Entity) Table

func (DriverPostgres) Update added in v0.1.0

func (driver DriverPostgres) Update(entity Entity) (string, map[string]any, error)

type DriverSQLite added in v0.1.0

type DriverSQLite struct {
	Path string
}

func (DriverSQLite) AddColumn added in v0.1.0

func (driver DriverSQLite) AddColumn(t Table, c TableColumn) string

func (DriverSQLite) AddForeignKey added in v0.1.0

func (driver DriverSQLite) AddForeignKey(t Table, c TableForeignKey) string

func (DriverSQLite) AddIndex added in v0.1.0

func (driver DriverSQLite) AddIndex(t Table, c TableIndex) string

func (DriverSQLite) AlterColumn added in v0.1.0

func (driver DriverSQLite) AlterColumn(t Table, c TableColumn) string

func (DriverSQLite) CreateTable added in v0.1.0

func (driver DriverSQLite) CreateTable(t Table) string

func (DriverSQLite) DSN added in v0.1.0

func (driver DriverSQLite) DSN() string

func (DriverSQLite) Delete added in v0.1.0

func (driver DriverSQLite) Delete(entity Entity) (string, map[string]any, error)

func (DriverSQLite) Driver added in v0.1.0

func (driver DriverSQLite) Driver() string

func (DriverSQLite) DropColumn added in v0.1.0

func (driver DriverSQLite) DropColumn(t Table, c TableColumn) string

func (DriverSQLite) DropForeignKey added in v0.1.0

func (driver DriverSQLite) DropForeignKey(t Table, c TableForeignKey) string

func (DriverSQLite) DropIndex added in v0.1.0

func (driver DriverSQLite) DropIndex(t Table, c TableIndex) string

func (DriverSQLite) DropTable added in v0.1.0

func (driver DriverSQLite) DropTable(t Table) string

func (DriverSQLite) Insert added in v0.1.0

func (driver DriverSQLite) Insert(entity Entity) (string, map[string]any, error)

func (DriverSQLite) ParseCreateTable added in v0.1.0

func (driver DriverSQLite) ParseCreateTable(s string) Table

func (DriverSQLite) RenameTable added in v0.1.0

func (driver DriverSQLite) RenameTable(t Table) string

func (DriverSQLite) Save added in v0.1.0

func (driver DriverSQLite) Save(entity Entity) (string, map[string]any, error)

func (DriverSQLite) Select added in v0.1.0

func (driver DriverSQLite) Select(entity Entity) (Query, error)

func (DriverSQLite) ShowCreateTable added in v0.1.0

func (driver DriverSQLite) ShowCreateTable(tableName string) string

func (DriverSQLite) TableFromEntity added in v0.1.0

func (driver DriverSQLite) TableFromEntity(entity Entity) Table

func (DriverSQLite) Update added in v0.1.0

func (driver DriverSQLite) Update(entity Entity) (string, map[string]any, error)

type Entity

type Entity interface {
	EntityInformation() EntityInformation
}

type EntityInformation

type EntityInformation struct {
	TableName  string
	Indexes    []TableIndex
	ForeignKey []TableForeignKey
}

type Query

type Query struct {
	Select  []string
	From    string
	Joins   []string
	Where   string
	GroupBy string
	OrderBy string
	Limit   struct {
		Count  int
		Offset int
	}
	Parameters map[string]any
}

func ParseQuery

func ParseQuery(query string) (Query, error)

func (Query) String

func (q Query) String() string

type QueryModifier

type QueryModifier func(query Query) Query

func WithAdditionalWhere added in v0.0.2

func WithAdditionalWhere(where string, parameters map[string]any) QueryModifier

func WithLimitOverride

func WithLimitOverride(size int, offset int) QueryModifier

type Repository

type Repository[ID ~uint64, T Entity] struct {
	Selector[T]
}

func NewRepository

func NewRepository[ID ~uint64, T Entity](dbal *DBAL) Repository[ID, T]

func (*Repository[ID, T]) GetByID added in v0.1.0

func (q *Repository[ID, T]) GetByID(ctx context.Context, id ID) (T, error)

func (*Repository[ID, T]) Insert

func (q *Repository[ID, T]) Insert(ctx context.Context, entity T) (ID, error)

func (*Repository[ID, T]) Save

func (q *Repository[ID, T]) Save(ctx context.Context, entity T) error

func (*Repository[ID, T]) Update

func (q *Repository[ID, T]) Update(ctx context.Context, entity T) error

type Selector

type Selector[T any] struct {
	// contains filtered or unexported fields
}

func NewSelector

func NewSelector[T any](connection *DBAL, query Query) Selector[T]

func (*Selector[T]) SelectMultiple

func (q *Selector[T]) SelectMultiple(ctx context.Context, mods ...QueryModifier) ([]T, error)

func (*Selector[T]) SelectSingle

func (q *Selector[T]) SelectSingle(ctx context.Context, mods ...QueryModifier) (T, error)

type Table added in v0.1.0

type Table struct {
	Name    string
	Columns []TableColumn
}

type TableColumn added in v0.1.0

type TableColumn struct {
	Name          string
	Type          string
	AutoIncrement bool
	PrimaryKey    bool
	HasDefault    bool
	Default       string
	Nullable      bool
	Index         []TableIndex
	ForeignKey    *TableForeignKey
}

type TableForeignKey added in v0.1.0

type TableForeignKey struct{}

type TableIndex added in v0.1.0

type TableIndex struct{}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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