hooks

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BunAdapter

func BunAdapter(p *Pool) *bunAdapter

BunAdapter returns an adapter that intercepts SQL for registered Whisker models. The returned value provides ExecContext, QueryContext, and QueryRowContext compatible with database/sql types, which Bun's SQL driver expects.

func EntDriver

func EntDriver(p *Pool) *entDriver

EntDriver returns an adapter that intercepts SQL for registered Whisker models. The returned value provides ExecContext and QueryContext compatible with database/sql types, which Ent's dialect drivers expect.

func OpenBun

func OpenBun(p *Pool) (*bun.DB, *bunAdapter)

OpenBun creates a *bun.DB backed by a Whisker pool. All queries executed through the returned DB are intercepted and rewritten for registered models.

func OpenGORM

func OpenGORM(p *Pool) (*gorm.DB, error)

OpenGORM opens a GORM database handle backed by the given Pool. SQL generated by GORM is intercepted and rewritten to target Whisker's JSONB document tables for any registered models.

func Register

func Register[T any](p *Pool, name string)

Register teaches the pool about a model so its SQL can be intercepted.

Types

type Pool

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

Pool wraps a Whisker store and presents a pgx-compatible query interface. SQL from ORMs targeting registered models is rewritten to use Whisker's JSONB document storage. Unregistered queries pass through unchanged.

func NewPool

func NewPool(store *whisker.Store) *Pool

NewPool creates a middleware pool backed by the given store.

func (*Pool) Exec

func (p *Pool) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

Exec intercepts INSERT/UPDATE/DELETE, rewrites for registered models, and passes through everything else.

func (*Pool) Query

func (p *Pool) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

Query intercepts SELECT, rewrites for registered models, and wraps results to unpack JSONB into individual columns.

func (*Pool) QueryRow

func (p *Pool) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

QueryRow wraps Query for single-row results.

Jump to

Keyboard shortcuts

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