database

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetModelColumns

func GetModelColumns(model any) []string

GetModelColumns extracts all column names from a model using reflection It checks bun tags first, then gorm tags, then json tags, and finally falls back to lowercase field names

func GetPrimaryKeyName

func GetPrimaryKeyName(model any) string

GetPrimaryKeyName extracts the primary key column name from a model It first checks if the model implements PrimaryKeyNameProvider (GetIDName method) Falls back to reflection to find bun:",pk" tag, then gorm:"primaryKey" tag

Types

type BunAdapter

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

BunAdapter adapts Bun to work with our Database interface This demonstrates how the abstraction works with different ORMs

func NewBunAdapter

func NewBunAdapter(db *bun.DB) *BunAdapter

NewBunAdapter creates a new Bun adapter

func (*BunAdapter) BeginTx

func (b *BunAdapter) BeginTx(ctx context.Context) (common.Database, error)

func (*BunAdapter) CommitTx

func (b *BunAdapter) CommitTx(ctx context.Context) error

func (*BunAdapter) Exec

func (b *BunAdapter) Exec(ctx context.Context, query string, args ...interface{}) (common.Result, error)

func (*BunAdapter) NewDelete

func (b *BunAdapter) NewDelete() common.DeleteQuery

func (*BunAdapter) NewInsert

func (b *BunAdapter) NewInsert() common.InsertQuery

func (*BunAdapter) NewSelect

func (b *BunAdapter) NewSelect() common.SelectQuery

func (*BunAdapter) NewUpdate

func (b *BunAdapter) NewUpdate() common.UpdateQuery

func (*BunAdapter) Query

func (b *BunAdapter) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*BunAdapter) RollbackTx

func (b *BunAdapter) RollbackTx(ctx context.Context) error

func (*BunAdapter) RunInTransaction

func (b *BunAdapter) RunInTransaction(ctx context.Context, fn func(common.Database) error) error

type BunDeleteQuery

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

BunDeleteQuery implements DeleteQuery for Bun

func (*BunDeleteQuery) Exec

func (b *BunDeleteQuery) Exec(ctx context.Context) (common.Result, error)

func (*BunDeleteQuery) Model

func (b *BunDeleteQuery) Model(model interface{}) common.DeleteQuery

func (*BunDeleteQuery) Table

func (b *BunDeleteQuery) Table(table string) common.DeleteQuery

func (*BunDeleteQuery) Where

func (b *BunDeleteQuery) Where(query string, args ...interface{}) common.DeleteQuery

type BunInsertQuery

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

BunInsertQuery implements InsertQuery for Bun

func (*BunInsertQuery) Exec

func (b *BunInsertQuery) Exec(ctx context.Context) (common.Result, error)

func (*BunInsertQuery) Model

func (b *BunInsertQuery) Model(model interface{}) common.InsertQuery

func (*BunInsertQuery) OnConflict

func (b *BunInsertQuery) OnConflict(action string) common.InsertQuery

func (*BunInsertQuery) Returning

func (b *BunInsertQuery) Returning(columns ...string) common.InsertQuery

func (*BunInsertQuery) Table

func (b *BunInsertQuery) Table(table string) common.InsertQuery

func (*BunInsertQuery) Value

func (b *BunInsertQuery) Value(column string, value interface{}) common.InsertQuery

type BunResult

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

BunResult implements Result for Bun

func (*BunResult) LastInsertId

func (b *BunResult) LastInsertId() (int64, error)

func (*BunResult) RowsAffected

func (b *BunResult) RowsAffected() int64

type BunSelectQuery

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

BunSelectQuery implements SelectQuery for Bun

func (*BunSelectQuery) Column

func (b *BunSelectQuery) Column(columns ...string) common.SelectQuery

func (*BunSelectQuery) Count

func (b *BunSelectQuery) Count(ctx context.Context) (int, error)

func (*BunSelectQuery) Exists

func (b *BunSelectQuery) Exists(ctx context.Context) (bool, error)

func (*BunSelectQuery) Group

func (b *BunSelectQuery) Group(group string) common.SelectQuery

func (*BunSelectQuery) Having

func (b *BunSelectQuery) Having(having string, args ...interface{}) common.SelectQuery

func (*BunSelectQuery) Join

func (b *BunSelectQuery) Join(query string, args ...interface{}) common.SelectQuery

func (*BunSelectQuery) LeftJoin

func (b *BunSelectQuery) LeftJoin(query string, args ...interface{}) common.SelectQuery

func (*BunSelectQuery) Limit

func (b *BunSelectQuery) Limit(n int) common.SelectQuery

func (*BunSelectQuery) Model

func (b *BunSelectQuery) Model(model interface{}) common.SelectQuery

func (*BunSelectQuery) Offset

func (b *BunSelectQuery) Offset(n int) common.SelectQuery

func (*BunSelectQuery) Order

func (b *BunSelectQuery) Order(order string) common.SelectQuery

func (*BunSelectQuery) Preload

func (b *BunSelectQuery) Preload(relation string, conditions ...interface{}) common.SelectQuery

func (*BunSelectQuery) Scan

func (b *BunSelectQuery) Scan(ctx context.Context, dest interface{}) error

func (*BunSelectQuery) Table

func (b *BunSelectQuery) Table(table string) common.SelectQuery

func (*BunSelectQuery) Where

func (b *BunSelectQuery) Where(query string, args ...interface{}) common.SelectQuery

func (*BunSelectQuery) WhereOr

func (b *BunSelectQuery) WhereOr(query string, args ...interface{}) common.SelectQuery

type BunTxAdapter

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

BunTxAdapter wraps a Bun transaction to implement the Database interface

func (*BunTxAdapter) BeginTx

func (b *BunTxAdapter) BeginTx(ctx context.Context) (common.Database, error)

func (*BunTxAdapter) CommitTx

func (b *BunTxAdapter) CommitTx(ctx context.Context) error

func (*BunTxAdapter) Exec

func (b *BunTxAdapter) Exec(ctx context.Context, query string, args ...interface{}) (common.Result, error)

func (*BunTxAdapter) NewDelete

func (b *BunTxAdapter) NewDelete() common.DeleteQuery

func (*BunTxAdapter) NewInsert

func (b *BunTxAdapter) NewInsert() common.InsertQuery

func (*BunTxAdapter) NewSelect

func (b *BunTxAdapter) NewSelect() common.SelectQuery

func (*BunTxAdapter) NewUpdate

func (b *BunTxAdapter) NewUpdate() common.UpdateQuery

func (*BunTxAdapter) Query

func (b *BunTxAdapter) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*BunTxAdapter) RollbackTx

func (b *BunTxAdapter) RollbackTx(ctx context.Context) error

func (*BunTxAdapter) RunInTransaction

func (b *BunTxAdapter) RunInTransaction(ctx context.Context, fn func(common.Database) error) error

type BunUpdateQuery

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

BunUpdateQuery implements UpdateQuery for Bun

func (*BunUpdateQuery) Exec

func (b *BunUpdateQuery) Exec(ctx context.Context) (common.Result, error)

func (*BunUpdateQuery) Model

func (b *BunUpdateQuery) Model(model interface{}) common.UpdateQuery

func (*BunUpdateQuery) Returning

func (b *BunUpdateQuery) Returning(columns ...string) common.UpdateQuery

func (*BunUpdateQuery) Set

func (b *BunUpdateQuery) Set(column string, value interface{}) common.UpdateQuery

func (*BunUpdateQuery) SetMap

func (b *BunUpdateQuery) SetMap(values map[string]interface{}) common.UpdateQuery

func (*BunUpdateQuery) Table

func (b *BunUpdateQuery) Table(table string) common.UpdateQuery

func (*BunUpdateQuery) Where

func (b *BunUpdateQuery) Where(query string, args ...interface{}) common.UpdateQuery

type GormAdapter

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

GormAdapter adapts GORM to work with our Database interface

func NewGormAdapter

func NewGormAdapter(db *gorm.DB) *GormAdapter

NewGormAdapter creates a new GORM adapter

func (*GormAdapter) BeginTx

func (g *GormAdapter) BeginTx(ctx context.Context) (common.Database, error)

func (*GormAdapter) CommitTx

func (g *GormAdapter) CommitTx(ctx context.Context) error

func (*GormAdapter) Exec

func (g *GormAdapter) Exec(ctx context.Context, query string, args ...interface{}) (common.Result, error)

func (*GormAdapter) NewDelete

func (g *GormAdapter) NewDelete() common.DeleteQuery

func (*GormAdapter) NewInsert

func (g *GormAdapter) NewInsert() common.InsertQuery

func (*GormAdapter) NewSelect

func (g *GormAdapter) NewSelect() common.SelectQuery

func (*GormAdapter) NewUpdate

func (g *GormAdapter) NewUpdate() common.UpdateQuery

func (*GormAdapter) Query

func (g *GormAdapter) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*GormAdapter) RollbackTx

func (g *GormAdapter) RollbackTx(ctx context.Context) error

func (*GormAdapter) RunInTransaction

func (g *GormAdapter) RunInTransaction(ctx context.Context, fn func(common.Database) error) error

type GormDeleteQuery

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

GormDeleteQuery implements DeleteQuery for GORM

func (*GormDeleteQuery) Exec

func (*GormDeleteQuery) Model

func (g *GormDeleteQuery) Model(model interface{}) common.DeleteQuery

func (*GormDeleteQuery) Table

func (g *GormDeleteQuery) Table(table string) common.DeleteQuery

func (*GormDeleteQuery) Where

func (g *GormDeleteQuery) Where(query string, args ...interface{}) common.DeleteQuery

type GormInsertQuery

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

GormInsertQuery implements InsertQuery for GORM

func (*GormInsertQuery) Exec

func (*GormInsertQuery) Model

func (g *GormInsertQuery) Model(model interface{}) common.InsertQuery

func (*GormInsertQuery) OnConflict

func (g *GormInsertQuery) OnConflict(action string) common.InsertQuery

func (*GormInsertQuery) Returning

func (g *GormInsertQuery) Returning(columns ...string) common.InsertQuery

func (*GormInsertQuery) Table

func (g *GormInsertQuery) Table(table string) common.InsertQuery

func (*GormInsertQuery) Value

func (g *GormInsertQuery) Value(column string, value interface{}) common.InsertQuery

type GormResult

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

GormResult implements Result for GORM

func (*GormResult) LastInsertId

func (g *GormResult) LastInsertId() (int64, error)

func (*GormResult) RowsAffected

func (g *GormResult) RowsAffected() int64

type GormSelectQuery

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

GormSelectQuery implements SelectQuery for GORM

func (*GormSelectQuery) Column

func (g *GormSelectQuery) Column(columns ...string) common.SelectQuery

func (*GormSelectQuery) Count

func (g *GormSelectQuery) Count(ctx context.Context) (int, error)

func (*GormSelectQuery) Exists

func (g *GormSelectQuery) Exists(ctx context.Context) (bool, error)

func (*GormSelectQuery) Group

func (g *GormSelectQuery) Group(group string) common.SelectQuery

func (*GormSelectQuery) Having

func (g *GormSelectQuery) Having(having string, args ...interface{}) common.SelectQuery

func (*GormSelectQuery) Join

func (g *GormSelectQuery) Join(query string, args ...interface{}) common.SelectQuery

func (*GormSelectQuery) LeftJoin

func (g *GormSelectQuery) LeftJoin(query string, args ...interface{}) common.SelectQuery

func (*GormSelectQuery) Limit

func (g *GormSelectQuery) Limit(n int) common.SelectQuery

func (*GormSelectQuery) Model

func (g *GormSelectQuery) Model(model interface{}) common.SelectQuery

func (*GormSelectQuery) Offset

func (g *GormSelectQuery) Offset(n int) common.SelectQuery

func (*GormSelectQuery) Order

func (g *GormSelectQuery) Order(order string) common.SelectQuery

func (*GormSelectQuery) Preload

func (g *GormSelectQuery) Preload(relation string, conditions ...interface{}) common.SelectQuery

func (*GormSelectQuery) Scan

func (g *GormSelectQuery) Scan(ctx context.Context, dest interface{}) error

func (*GormSelectQuery) Table

func (g *GormSelectQuery) Table(table string) common.SelectQuery

func (*GormSelectQuery) Where

func (g *GormSelectQuery) Where(query string, args ...interface{}) common.SelectQuery

func (*GormSelectQuery) WhereOr

func (g *GormSelectQuery) WhereOr(query string, args ...interface{}) common.SelectQuery

type GormUpdateQuery

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

GormUpdateQuery implements UpdateQuery for GORM

func (*GormUpdateQuery) Exec

func (*GormUpdateQuery) Model

func (g *GormUpdateQuery) Model(model interface{}) common.UpdateQuery

func (*GormUpdateQuery) Returning

func (g *GormUpdateQuery) Returning(columns ...string) common.UpdateQuery

func (*GormUpdateQuery) Set

func (g *GormUpdateQuery) Set(column string, value interface{}) common.UpdateQuery

func (*GormUpdateQuery) SetMap

func (g *GormUpdateQuery) SetMap(values map[string]interface{}) common.UpdateQuery

func (*GormUpdateQuery) Table

func (g *GormUpdateQuery) Table(table string) common.UpdateQuery

func (*GormUpdateQuery) Where

func (g *GormUpdateQuery) Where(query string, args ...interface{}) common.UpdateQuery

Jump to

Keyboard shortcuts

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