builders

package
v0.0.0-...-85622c8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnsFromResultStream

func ColumnsFromResultStream(rows core.ResultStream) ([]*core.Column, error)

ColumnsFromResultStream converts the result stream to columns. A result stream should return rows that are at least 2 columns wide and have the following structure:

1st elem: name - string
2nd elem: type - string

func NextNil

func NextNil() (func() (core.Row, error), func() bool)

NextNil creates next and hasNext functions that don't return anything (no rows)

func NextSingle

func NextSingle(value any) (func() (core.Row, error), func() bool)

NextSingle creates next and hasNext functions from a provided single value

func NextSlice

func NextSlice[T any](values []T, preprocess func(T) any) (func() (core.Row, error), func() bool)

NextSlice creates next and hasNext functions from provided values preprocessor is an optional function which parses a single value from slice before adding it to a row

func NextYield

func NextYield(fn func(yield func(...any)) error) (func() (core.Row, error), func() bool)

NextYield creates next and hasNext functions by calling yield in internal function. WARNING: the caller must call "hasNext" before each call to "next".

Types

type Client

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

default sql client used by other specific implementations

func NewClient

func NewClient(db *sql.DB, opts ...ClientOption) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) ColumnsFromQuery

func (c *Client) ColumnsFromQuery(query string, args ...any) ([]*core.Column, error)

ColumnsFromQuery executes a given query on a new connection and converts the results to columns. A query should return a result that is at least 2 columns wide and have the following structure:

1st elem: name - string
2nd elem: type - string

Query is sprintf-ed with args, so ColumnsFromQuery("select a from %s", "table_name") works.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, query string) (*ResultStream, error)

Exec executes a query and returns a stream with single row (number of affected results).

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string) (*ResultStream, error)

Query executes a query on a connection and returns a result stream.

func (*Client) QueryUntilNotEmpty

func (c *Client) QueryUntilNotEmpty(ctx context.Context, queries ...string) (*ResultStream, error)

QueryUntilNotEmpty executes given queries on a single connection and returns when one of them has a nonempty result. Useful for specifying "fallback" queries like "ROWCOUNT()" when there are no results in query.

func (*Client) Swap

func (c *Client) Swap(db *sql.DB)

Swap swaps current database connection for another one and closes the old one.

type ClientOption

type ClientOption func(*clientConfig)

func WithCustomTypeProcessor

func WithCustomTypeProcessor(typ string, fn func(any) any) ClientOption

type ResultStream

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

func (*ResultStream) AddCallback

func (r *ResultStream) AddCallback(fn func())

func (*ResultStream) Close

func (r *ResultStream) Close()

func (*ResultStream) HasNext

func (r *ResultStream) HasNext() bool

func (*ResultStream) Header

func (r *ResultStream) Header() core.Header

func (*ResultStream) Meta

func (r *ResultStream) Meta() *core.Meta

func (*ResultStream) Next

func (r *ResultStream) Next() (core.Row, error)

type ResultStreamBuilder

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

ResultStreamBuilder builds the rows

func NewResultStreamBuilder

func NewResultStreamBuilder() *ResultStreamBuilder

func (*ResultStreamBuilder) Build

func (b *ResultStreamBuilder) Build() *ResultStream

func (*ResultStreamBuilder) WithCloseFunc

func (b *ResultStreamBuilder) WithCloseFunc(fn func()) *ResultStreamBuilder

func (*ResultStreamBuilder) WithHeader

func (b *ResultStreamBuilder) WithHeader(header core.Header) *ResultStreamBuilder

func (*ResultStreamBuilder) WithMeta

func (b *ResultStreamBuilder) WithMeta(meta *core.Meta) *ResultStreamBuilder

func (*ResultStreamBuilder) WithNextFunc

func (b *ResultStreamBuilder) WithNextFunc(fn func() (core.Row, error), has func() bool) *ResultStreamBuilder

Jump to

Keyboard shortcuts

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