sql

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDialect added in v0.3.1

func RegisterDialect(name string, dialect Dialect)

RegisterDialect allows registering custom SQL dialects.

Types

type Builder

type Builder struct {
	Schema              *ast.Schema
	Logger              log.Logger
	TableNameGenerator  builders.TableNameGenerator
	Operators           map[string]builders.Operator
	AggregatorOperators map[string]builders.AggregatorOperator
	CaseConverter       builders.ColumnCaseConverter
	Dialect             string
}

func NewBuilder

func NewBuilder(config *builders.Config) Builder

func (Builder) Capabilities added in v0.3.1

func (b Builder) Capabilities() builders.Capabilities

Capabilities returns what this SQL database supports.

func (Builder) Create

func (b Builder) Create(field builders.Field) (string, []any, error)

Create generates an SQL create query based on graphql ast.

func (Builder) Delete

func (b Builder) Delete(field builders.Field) (string, []any, error)

Delete generates an SQL delete query based on graphql ast.

func (Builder) Query

func (b Builder) Query(field builders.Field) (string, []any, error)

Query generates an SQL read query based on graphql ast.

func (Builder) Update

func (b Builder) Update(field builders.Field) (string, []any, error)

Update generates an SQL update query based on graphql ast.

type Dialect added in v0.3.1

type Dialect interface {
	// JSONBuildObject creates a JSON object from key-value pairs
	JSONBuildObject(args ...any) exp.SQLFunctionExpression
	// JSONAgg aggregates rows into a JSON array
	JSONAgg(expr exp.Expression) exp.SQLFunctionExpression
	// CoalesceJSON returns a fallback value if the expression is null
	CoalesceJSON(expr exp.Expression, fallback string) exp.SQLFunctionExpression
}

Dialect provides dialect-specific SQL functions. Different databases have different syntax for JSON operations.

func GetSQLDialect added in v0.3.1

func GetSQLDialect(name string) Dialect

GetSQLDialect returns the Dialect for a given dialect name. Returns PostgresDialect as the default if the dialect is not found.

type Executor added in v0.3.1

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

Executor implements execution.Executor for PostgreSQL databases.

func NewExecutor added in v0.3.1

func NewExecutor(pool *pgxpool.Pool, config *builders.Config) *Executor

NewExecutor creates a new SQL Executor with the given pool and config.

func (*Executor) Dialect added in v0.3.1

func (e *Executor) Dialect() string

Dialect returns the SQL dialect name. This is a helper method for introspection, not part of the Executor interface.

func (*Executor) Mutate added in v0.3.1

func (e *Executor) Mutate(ctx context.Context, dest any) error

Mutate executes a create/update/delete mutation and scans results into dest.

func (*Executor) Query added in v0.3.1

func (e *Executor) Query(ctx context.Context, dest any) error

Query executes a read query and scans results into dest.

func (*Executor) QueryWithTypes added in v0.3.1

func (e *Executor) QueryWithTypes(ctx context.Context, dest any, types map[string]reflect.Type, typeKey string) error

QueryWithTypes handles interface types that need type discrimination.

type PostgresDialect added in v0.3.1

type PostgresDialect struct{}

PostgresDialect implements Dialect for PostgreSQL.

func (PostgresDialect) CoalesceJSON added in v0.3.1

func (PostgresDialect) CoalesceJSON(expr exp.Expression, fallback string) exp.SQLFunctionExpression

func (PostgresDialect) JSONAgg added in v0.3.1

func (PostgresDialect) JSONBuildObject added in v0.3.1

func (PostgresDialect) JSONBuildObject(args ...any) exp.SQLFunctionExpression

type SQLQuery added in v0.3.1

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

SQLQuery implements builders.Query for SQL databases. It wraps the SQL string and prepared statement arguments.

func NewSQLQuery added in v0.3.1

func NewSQLQuery(sql string, args []any) SQLQuery

NewSQLQuery creates a new SQLQuery with the given SQL and arguments.

func (SQLQuery) Args added in v0.3.1

func (q SQLQuery) Args() []any

Args returns the prepared statement arguments.

func (SQLQuery) Native added in v0.3.1

func (q SQLQuery) Native() any

Native returns the SQLQuery itself as the native query object. This allows type assertion: query.Native().(SQLQuery)

func (SQLQuery) SQL added in v0.3.1

func (q SQLQuery) SQL() string

SQL returns the SQL query string.

func (SQLQuery) String added in v0.3.1

func (q SQLQuery) String() string

String returns the SQL query string for logging/debugging.

type TypeNameScanner added in v0.3.1

type TypeNameScanner[T any] struct {
	// contains filtered or unexported fields
}

TypeNameScanner is a scanner for interface types that determines the concrete type based on a type discriminator field in the result. This is PostgreSQL-specific as it uses pgx types.

func NewTypeNameScanner added in v0.3.1

func NewTypeNameScanner[T any](types map[string]reflect.Type, typeNameKey string) *TypeNameScanner[T]

NewTypeNameScanner creates a new TypeNameScanner for the given types and type name key. The types map should map type names (lowercase) to their reflect.Type. The typeNameKey is the column name containing the type discriminator.

func (*TypeNameScanner[T]) ScanJson added in v0.3.1

func (t *TypeNameScanner[T]) ScanJson(data []byte) (T, error)

ScanJson scans JSON data into the appropriate concrete type based on the type discriminator.

func (*TypeNameScanner[T]) ScanRow added in v0.3.1

func (t *TypeNameScanner[T]) ScanRow(row pgx.CollectableRow) (T, error)

ScanRow scans a single row into the appropriate concrete type based on the type discriminator.

Jump to

Keyboard shortcuts

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