sql

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildQuery

func BuildQuery(dialect QueryBuilderDialect, resolveInfo db.ResolveDBInfo, fields map[string]any,
	returnFieldNames map[string]debefix.ResolveValue) (string, []any, error)

BuildQuery builds a query string and arguments.

func QueryInterfaceCheck

func QueryInterfaceCheck(ctx context.Context, query string, returnFieldNames []string, args ...any) (map[string]any, error)

QueryInterfaceCheck generates a simulated response for QueryInterface.Query

func ResolveDBFunc

func ResolveDBFunc(qi QueryInterface, queryBuilder QueryBuilder) db.ResolveDBCallback

ResolveDBFunc is a db.ResolveDBCallback helper to generate SQL database records.

func ResolveFunc

func ResolveFunc(qi QueryInterface, queryBuilder QueryBuilder) debefix.ResolveCallback

ResolveFunc is a debefix.ResolveCallback helper to generate SQL database records.

Types

type DB

type DB interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

DB is an abstraction over sql.DB or similar..

type DefaultQueryBuilderDialect

type DefaultQueryBuilderDialect struct {
}

DefaultQueryBuilderDialect returns placeholders using ? and unquoted table and field names.

func (DefaultQueryBuilderDialect) NewPlaceholderProvider

func (DefaultQueryBuilderDialect) QuoteField

func (d DefaultQueryBuilderDialect) QuoteField(fieldName string) string

func (DefaultQueryBuilderDialect) QuoteTable

func (d DefaultQueryBuilderDialect) QuoteTable(tableName string) string

type QueryBuilder

type QueryBuilder interface {
	BuildSQL(ctx context.Context, resolveInfo db.ResolveDBInfo, fields map[string]any, returnFieldNames map[string]debefix.ResolveValue) (string, []any, error)
}

QueryBuilder is an abstraction for building SQL queries.

func NewQueryBuilder

func NewQueryBuilder(dialect QueryBuilderDialect) QueryBuilder

NewQueryBuilder returns a QueryBuilder which uses the passed database dialect.

type QueryBuilderDialect

type QueryBuilderDialect interface {
	QuoteTable(tableName string) string
	QuoteField(fieldName string) string
	NewPlaceholderProvider() QueryBuilderPlaceholderProvider
}

QueryBuilderDialect represents a database dialect used to build queries.

type QueryBuilderPlaceholderProvider

type QueryBuilderPlaceholderProvider interface {
	Next() (placeholder string, argName string)
}

QueryBuilderPlaceholderProvider is a helper for generating database placeholders.

type QueryInterface

type QueryInterface interface {
	Query(ctx context.Context, tableID debefix.TableID, query string, returnFieldNames []string, args ...any) (map[string]any, error)
}

QueryInterface abstracts executing a query in a database.

func NewDebugQueryInterface

func NewDebugQueryInterface(out io.Writer) QueryInterface

NewDebugQueryInterface returns a QueryInterface that outputs the generated queries. If out is nil, os.Stdout will be used.

func NewSQLQueryInterface

func NewSQLQueryInterface(db DB) QueryInterface

NewSQLQueryInterface returns a QueryInterface for the passed database.

type QueryInterfaceFunc

type QueryInterfaceFunc func(ctx context.Context, tableID debefix.TableID, query string, returnFieldNames []string, args ...any) (map[string]any, error)

QueryInterfaceFunc is a func adapter for QueryInterface

func (QueryInterfaceFunc) Query

func (f QueryInterfaceFunc) Query(ctx context.Context, tableID debefix.TableID, query string, returnFieldNames []string, args ...any) (map[string]any, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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