Documentation ¶
Index ¶
- func QueryInterfaceCheck(ctx context.Context, query string, returnFieldNames []string, args ...any) (map[string]any, error)
- func ResolverDBCallback(ctx context.Context, db QueryInterface, sqlBuilder QueryBuilder) db.ResolverDBCallback
- type DefaultSQLBuilder
- type PlaceholderProvider
- type QueryBuilder
- type QueryInterface
- type QueryInterfaceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QueryInterfaceCheck ¶
func QueryInterfaceCheck(ctx context.Context, query string, returnFieldNames []string, args ...any) (map[string]any, error)
QueryInterfaceCheck generates a smulated response for QueryInterface.Query
func ResolverDBCallback ¶
func ResolverDBCallback(ctx context.Context, db QueryInterface, sqlBuilder QueryBuilder) db.ResolverDBCallback
ResolverDBCallback is a db.ResolverDBCallback to generate SQL-based database records. The parameter "fields" and "returnFieldNames" are always sorted to be deterministic.
Types ¶
type DefaultSQLBuilder ¶
type DefaultSQLBuilder struct { PlaceholderProviderFactory func() PlaceholderProvider // uses defaultSQLPlaceholderProvider if not set QuoteTable func(t string) string // don't quote if not set QuoteField func(f string) string // don't quote if not set }
DefaultSQLBuilder is the default customizable INSERT SQL builder, using placeholders for values. It uses "RETURNING" to get the returnFieldNames.
func (DefaultSQLBuilder) BuildInsertSQL ¶
func (DefaultSQLBuilder) CreatePlaceholderProvider ¶
func (d DefaultSQLBuilder) CreatePlaceholderProvider() PlaceholderProvider
type PlaceholderProvider ¶
PlaceholderProvider generates database-specific placeholders, like ? for MySQL, $1 for postgres, or :param1 for MSSQL. If the database uses named parameters, its name should be returned in argName, otherwise this should be blank.
type QueryBuilder ¶
type QueryBuilder interface { CreatePlaceholderProvider() PlaceholderProvider BuildInsertSQL(tableName string, fieldNames []string, fieldPlaceholders []string, returnFieldNames []string) string }
QueryBuilder is an abstraction for building INSERT queries.
type QueryInterface ¶
type QueryInterface interface {
Query(ctx context.Context, query string, returnFieldNames []string, args ...any) (map[string]any, error)
}
QueryInterface abstracts executing a query on a database. The return map should contain values for all fields specified in returnFieldNames.
func NewDebugQueryInterface ¶ added in v0.13.0
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 NewDebugResultQueryInterface ¶ added in v0.13.0
func NewDebugResultQueryInterface(qi QueryInterface, out io.Writer) QueryInterface
NewDebugResultQueryInterface returns a QueryInterface calls an inner QueryInterface and outputs the generated queries and the returned fields. If out is nil, os.Stdout will be used.
func NewMultiQueryInterface ¶ added in v0.13.0
func NewMultiQueryInterface(itfs []QueryInterface) QueryInterface
NewMultiQueryInterface returns a QueryInterface that calls multiple QueryInterface, returning the result of the last one.
func NewSQLQueryInterface ¶
func NewSQLQueryInterface(db *sql.DB) QueryInterface
NewSQLQueryInterface wraps a *sql.DB on the QueryInterface interface.