Documentation
¶
Overview ¶
Package gpabun provides a Bun adapter for the Go Persistence API (GPA)
Index ¶
- func GetRepository[T any](p *Provider) gpa.SQLRepository[T]
- type Provider
- func (p *Provider) BeginTx(ctx context.Context, opts *gpa.TxOptions) (interface{}, error)
- func (p *Provider) Close() error
- func (p *Provider) Configure(config gpa.Config) error
- func (p *Provider) DB() interface{}
- func (p *Provider) Health() error
- func (p *Provider) Migrate(models ...interface{}) error
- func (p *Provider) ProviderInfo() gpa.ProviderInfo
- func (p *Provider) RawExec(ctx context.Context, query string, args ...interface{}) (gpa.Result, error)
- func (p *Provider) RawQuery(ctx context.Context, query string, args ...interface{}) (interface{}, error)
- func (p *Provider) SupportedFeatures() []gpa.Feature
- type Repository
- func (r *Repository[T]) Close() error
- func (r *Repository[T]) Count(ctx context.Context, opts ...gpa.QueryOption) (int64, error)
- func (r *Repository[T]) Create(ctx context.Context, entity *T) error
- func (r *Repository[T]) CreateBatch(ctx context.Context, entities []*T) error
- func (r *Repository[T]) Delete(ctx context.Context, id interface{}) error
- func (r *Repository[T]) DeleteByCondition(ctx context.Context, condition gpa.Condition) error
- func (r *Repository[T]) Exists(ctx context.Context, opts ...gpa.QueryOption) (bool, error)
- func (r *Repository[T]) FindAll(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
- func (r *Repository[T]) FindByID(ctx context.Context, id interface{}) (*T, error)
- func (r *Repository[T]) GetEntityInfo() (*gpa.EntityInfo, error)
- func (r *Repository[T]) Query(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
- func (r *Repository[T]) QueryOne(ctx context.Context, opts ...gpa.QueryOption) (*T, error)
- func (r *Repository[T]) RawExec(ctx context.Context, query string, args []interface{}) (gpa.Result, error)
- func (r *Repository[T]) RawQuery(ctx context.Context, query string, args []interface{}) ([]*T, error)
- func (r *Repository[T]) Transaction(ctx context.Context, fn gpa.TransactionFunc[T]) error
- func (r *Repository[T]) Update(ctx context.Context, entity *T) error
- func (r *Repository[T]) UpdatePartial(ctx context.Context, id interface{}, updates map[string]interface{}) error
- type Result
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRepository ¶
func GetRepository[T any](p *Provider) gpa.SQLRepository[T]
GetRepository returns a type-safe repository for any entity type T This enables the unified provider API: userRepo := gpabun.GetRepository[User](provider)
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements gpa.Provider and gpa.SQLProvider using Bun
func NewProvider ¶
NewProvider creates a new Bun provider instance
func (*Provider) BeginTx ¶ added in v0.1.1
BeginTx starts a transaction with specific isolation level
func (*Provider) DB ¶ added in v0.1.1
func (p *Provider) DB() interface{}
DB returns the underlying database/sql.DB instance
func (*Provider) ProviderInfo ¶
func (p *Provider) ProviderInfo() gpa.ProviderInfo
ProviderInfo returns information about this provider
func (*Provider) RawExec ¶ added in v0.1.1
func (p *Provider) RawExec(ctx context.Context, query string, args ...interface{}) (gpa.Result, error)
RawExec executes raw SQL without returning results
func (*Provider) RawQuery ¶ added in v0.1.1
func (p *Provider) RawQuery(ctx context.Context, query string, args ...interface{}) (interface{}, error)
RawQuery executes raw SQL and returns results
func (*Provider) SupportedFeatures ¶
SupportedFeatures returns the list of supported features
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
Repository implements gpa.Repository[T] using Bun
func (*Repository[T]) Count ¶
func (r *Repository[T]) Count(ctx context.Context, opts ...gpa.QueryOption) (int64, error)
Count returns the number of entities matching the query options
func (*Repository[T]) Create ¶
func (r *Repository[T]) Create(ctx context.Context, entity *T) error
Create inserts a new entity
func (*Repository[T]) CreateBatch ¶
func (r *Repository[T]) CreateBatch(ctx context.Context, entities []*T) error
CreateBatch inserts multiple entities
func (*Repository[T]) Delete ¶
func (r *Repository[T]) Delete(ctx context.Context, id interface{}) error
Delete removes an entity by ID
func (*Repository[T]) DeleteByCondition ¶
DeleteByCondition removes entities matching the condition
func (*Repository[T]) Exists ¶
func (r *Repository[T]) Exists(ctx context.Context, opts ...gpa.QueryOption) (bool, error)
Exists checks if any entities match the query options
func (*Repository[T]) FindAll ¶
func (r *Repository[T]) FindAll(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
FindAll retrieves all entities
func (*Repository[T]) FindByID ¶
func (r *Repository[T]) FindByID(ctx context.Context, id interface{}) (*T, error)
FindByID retrieves a single entity by ID
func (*Repository[T]) GetEntityInfo ¶
func (r *Repository[T]) GetEntityInfo() (*gpa.EntityInfo, error)
GetEntityInfo returns metadata about the entity
func (*Repository[T]) Query ¶
func (r *Repository[T]) Query(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
Query retrieves entities based on query options
func (*Repository[T]) QueryOne ¶
func (r *Repository[T]) QueryOne(ctx context.Context, opts ...gpa.QueryOption) (*T, error)
QueryOne retrieves a single entity based on query options
func (*Repository[T]) RawExec ¶
func (r *Repository[T]) RawExec(ctx context.Context, query string, args []interface{}) (gpa.Result, error)
RawExec executes a raw command
func (*Repository[T]) RawQuery ¶
func (r *Repository[T]) RawQuery(ctx context.Context, query string, args []interface{}) ([]*T, error)
RawQuery executes a raw query and returns results
func (*Repository[T]) Transaction ¶
func (r *Repository[T]) Transaction(ctx context.Context, fn gpa.TransactionFunc[T]) error
Transaction executes a function within a transaction
func (*Repository[T]) Update ¶
func (r *Repository[T]) Update(ctx context.Context, entity *T) error
Update modifies an existing entity
func (*Repository[T]) UpdatePartial ¶
func (r *Repository[T]) UpdatePartial(ctx context.Context, id interface{}, updates map[string]interface{}) error
UpdatePartial modifies specific fields of an entity
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result implements gpa.Result
func (*Result) LastInsertId ¶
LastInsertId returns the last insert ID
func (*Result) RowsAffected ¶
RowsAffected returns the number of affected rows
type Transaction ¶
type Transaction[T any] struct { *Repository[T] }
Transaction implements gpa.Transaction[T]
func (*Transaction[T]) Commit ¶
func (t *Transaction[T]) Commit() error
Commit commits the transaction
func (*Transaction[T]) Rollback ¶
func (t *Transaction[T]) Rollback() error
Rollback rolls back the transaction
func (*Transaction[T]) RollbackToSavepoint ¶
func (t *Transaction[T]) RollbackToSavepoint(name string) error
RollbackToSavepoint rolls back to a savepoint
func (*Transaction[T]) SetSavepoint ¶
func (t *Transaction[T]) SetSavepoint(name string) error
SetSavepoint creates a savepoint