Documentation ¶
Index ¶
- func BuildQuery(dialect QueryBuilderDialect, resolveInfo db.ResolveDBInfo, ...) (string, []any, error)
- func QueryInterfaceCheck(ctx context.Context, query string, returnFieldNames []string, args ...any) (map[string]any, error)
- func ResolveDBFunc(qi QueryInterface, queryBuilder QueryBuilder) db.ResolveDBCallback
- func ResolveFunc(qi QueryInterface, queryBuilder QueryBuilder) debefix.ResolveCallback
- type DB
- type DefaultQueryBuilderDialect
- type QueryBuilder
- type QueryBuilderDialect
- type QueryBuilderPlaceholderProvider
- type QueryInterface
- type QueryInterfaceFunc
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 (d DefaultQueryBuilderDialect) NewPlaceholderProvider() QueryBuilderPlaceholderProvider
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 ¶
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.