sqlxtenant

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sqlxtenant provides tenant-filtered helpers for simple sqlx-style SELECT, UPDATE, and DELETE statements.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsafeSQL = errors.New("gotenancy/sqlx: unsafe sql")
)

Functions

func ExecContext

func ExecContext(ctx context.Context, db Execer, baseSQL string, baseArgs []any, opts ...data.FilterOption) (sql.Result, error)

ExecContext runs a tenant-filtered write statement.

func GetContext

func GetContext(ctx context.Context, db Queryer, dest interface{}, baseSQL string, baseArgs []any, opts ...data.FilterOption) error

GetContext runs a tenant-filtered single-row SELECT.

func Query

func Query(ctx context.Context, baseSQL string, opts ...data.FilterOption) (string, []any, error)

Query adds the tenant filter to a base SQL statement.

func QueryWithArgs

func QueryWithArgs(ctx context.Context, baseSQL string, baseArgs []any, opts ...data.FilterOption) (string, []any, error)

QueryWithArgs adds the tenant filter to a base SQL statement and preserves existing args.

func SelectContext

func SelectContext(ctx context.Context, db Queryer, dest interface{}, baseSQL string, baseArgs []any, opts ...data.FilterOption) error

SelectContext runs a tenant-filtered SELECT.

func TenantCondition added in v0.1.6

func TenantCondition(ctx context.Context, opts ...data.FilterOption) (data.Condition, error)

TenantCondition returns a parameterized tenant condition for explicit placement in complex SQL.

Use this helper for JOIN, GROUP BY, ORDER BY, LIMIT, or locking queries where Query cannot safely rewrite SQL. The returned condition is empty for host contexts.

Types

type Execer

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

Execer is implemented by *sqlx.DB and *sqlx.Tx.

type Queryer

type Queryer interface {
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

Queryer is implemented by *sqlx.DB and *sqlx.Tx.

Jump to

Keyboard shortcuts

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