Documentation
¶
Index ¶
- type Bridge
- func (b *Bridge) Begin(ctx context.Context) (any, error)
- func (b *Bridge) Close(context.Context) (any, error)
- func (b *Bridge) Commit(context.Context) (any, error)
- func (b *Bridge) Connect(ctx context.Context) (any, error)
- func (b *Bridge) Get(ctx context.Context, query string, args ...any) (any, error)
- func (b *Bridge) GetAll(ctx context.Context, query string, args ...any) (any, error)
- func (b *Bridge) Insert(ctx context.Context, table string, value any) (any, error)
- func (b *Bridge) InsertID(context.Context) (any, error)
- func (b *Bridge) Query(ctx context.Context, query string, args ...any) (any, error)
- func (b *Bridge) Replace(ctx context.Context, table string, value any) (any, error)
- func (b *Bridge) Rollback(context.Context) (any, error)
- func (b *Bridge) RowsAffected(context.Context) (any, error)
- func (b *Bridge) Update(ctx context.Context, table string, value any, keyColumns ...any) (any, error)
- func (b *Bridge) WithObserver(fn ObserveFunc)
- type Client
- func (p *Client) Begin(ctx context.Context) error
- func (p *Client) Close() error
- func (p *Client) Commit() error
- func (p *Client) Connect(ctx context.Context) error
- func (p *Client) Exec(ctx context.Context, query string, args ...any) error
- func (p *Client) Get(ctx context.Context, dest any, query string, args ...any) error
- func (p *Client) Insert(ctx context.Context, table string, value any) error
- func (p *Client) InsertID() int64
- func (p *Client) Query(ctx context.Context, query string, args ...any) error
- func (p *Client) Replace(ctx context.Context, table string, value any) error
- func (p *Client) Rollback() error
- func (p *Client) RowsAffected() int64
- func (p *Client) Select(ctx context.Context, dest any, query string, args ...any) error
- func (p *Client) Update(ctx context.Context, table string, value any, keyCols ...string) error
- func (p *Client) WithObserver(fn ObserveFunc)
- type ObserveFunc
- type Observer
- type QueryLogEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge exposes dynamically typed methods for language runtimes. Every method accepts a context and returns a value plus an error so runtimes can inject the context and surface errors consistently.
func (*Bridge) RowsAffected ¶
Rows_affected returns the affected row count from the last write.
func (*Bridge) Update ¶
func (b *Bridge) Update(ctx context.Context, table string, value any, keyColumns ...any) (any, error)
Update updates a row using dynamically typed named values and key columns.
func (*Bridge) WithObserver ¶
func (b *Bridge) WithObserver(fn ObserveFunc)
WithObserver sets an observer on the underlying client.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an *sqlx.DB and provides a PHP-PDO-like API.
Concurrency: The underlying *sqlx.DB is safe for concurrent use, so multiple PDO instances can share the same database connection pool. A single *Client value is NOT safe for concurrent use: write operations mutate lastInsertID and rowsAffected, and transaction methods mutate transaction state. For stateless HTTP handlers, create a new *Client per request that shares the underlying *sql.DB pool (see OpenDB).
func (*Client) Begin ¶
Begin starts a transaction. Returns an error if a transaction is already in progress (nested transactions are not supported).
func (*Client) Close ¶
Close closes the underlying exclusive connection. Only needed does something if `Connect()` is called.
func (*Client) Commit ¶
Commit commits the current transaction. Returns nil when no transaction is in progress.
func (*Client) Exec ¶
Exec executes a query with args (positional, map, or struct for named params).
func (*Client) Insert ¶
Insert inserts a struct with `db` tags or a string-keyed map into the table. Uses NamedExecContext to bind fields to :name placeholders.
func (*Client) Replace ¶
Replace performs a REPLACE INTO operation with a struct or string-keyed map.
func (*Client) Rollback ¶
Rollback rolls back the current transaction. Returns nil when no transaction is in progress.
func (*Client) RowsAffected ¶
RowsAffected returns the number of rows affected by the last write operation.
func (*Client) Update ¶
Update updates rows using a struct or string-keyed map. keyCols specify WHERE columns.
func (*Client) WithObserver ¶
func (p *Client) WithObserver(fn ObserveFunc)
WithObserver sets an observer to the client.
type ObserveFunc ¶
type ObserveFunc func(ctx context.Context, entry QueryLogEntry)
ObserveFunc is the callback signature for query observation.