sql

package
v1.17.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConn

func GetConn(conn interface{}) (sdk.Conn, error)

GetConn gets the underlying SQL gateway from a database/sql CHConn connection

func NewConnector

func NewConnector(connContext *bytehouse.ConnectionContext, dsn string) (driver.Connector, error)

NewConnector returns new driver.Connector.

func RunConn

func RunConn(ctx context.Context, db *sql.DB, callback func(conn sdk.Conn) error) error

RunConn runs a query on the raw underlying driver connection Use this function for batch inserts or insert with reader You must return an error in the callback if there is an error with the query

Types

type CHConn

type CHConn struct {
	Gateway *sdk.Gateway
}

CHConn implements Conn interface from database/sql library

func (*CHConn) Begin

func (c *CHConn) Begin() (driver.Tx, error)

func (*CHConn) CheckNamedValue

func (c *CHConn) CheckNamedValue(nv *driver.NamedValue) error

NamedValueChecker may be optionally implemented by CHConn or Stmt. It provides the driver more control to handle Go and database types beyond the default Values types allowed.

The sql package checks for value checkers in the following order, stopping at the first found match: Stmt.NamedValueChecker, CHConn.NamedValueChecker, Stmt.ColumnConverter, DefaultParameterConverter.

If CheckNamedValue returns ErrRemoveArgument, the NamedValue will not be included in the final query arguments. This may be used to pass special options to the query itself.

If ErrSkip is returned the column converter error checking path is used for the argument. Drivers may wish to return ErrSkip after they have exhausted their own special cases.

CheckNamedValue is called before passing arguments to the driver and is called in place of any ColumnConverter. CheckNamedValue must do type validation and conversion as appropriate for the driver.

func (*CHConn) Close

func (c *CHConn) Close() error

Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.

Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.

Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).

func (*CHConn) Commit

func (c *CHConn) Commit() error

func (*CHConn) Exec

func (c *CHConn) Exec(query string, args []driver.Value) (driver.Result, error)

func (*CHConn) ExecContext

func (c *CHConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

func (*CHConn) Ping

func (c *CHConn) Ping(ctx context.Context) error

Ping implements Pinger interface If CHConn.Ping returns ErrBadConn, DB.Ping and DB.PingContext will remove the CHConn from pool.

func (*CHConn) Prepare

func (c *CHConn) Prepare(query string) (driver.Stmt, error)

func (*CHConn) PrepareContext

func (c *CHConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

func (*CHConn) Query

func (c *CHConn) Query(query string, args []driver.Value) (driver.Rows, error)

Query makes a sql query args are parameters in a prepared statement

func (*CHConn) QueryContext

func (c *CHConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext runs a query and returns it's results

func (*CHConn) ResetSession

func (c *CHConn) ResetSession(ctx context.Context) error

ResetSession is called prior to executing a query on the connection if the connection has been used before. If the driver returns ErrBadConn the connection is discarded.

func (*CHConn) Rollback

func (c *CHConn) Rollback() error

type GatewayDriver

type GatewayDriver struct{}

GatewayDriver implements the sql Driver interface See https://golang.org/pkg/database/sql/driver/#Driver

func (GatewayDriver) Open

func (d GatewayDriver) Open(dsn string) (driver.Conn, error)

Open returns a new connection to the database. The name is a string in a driver-specific format.

OpenConfig may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.

The returned connection is only used by one goroutine at a time.

func (GatewayDriver) OpenConnector

func (d GatewayDriver) OpenConnector(dsn string) (driver.Connector, error)

OpenConnector implements driver.DriverContext. sql.DB will call OpenConnector to obtain a Connector and then invoke that Connector's Connect method to obtain each needed connection, instead of invoking the Driver's OpenConfig method for each connection. The two-step sequence allows drivers to parse the name just once and also provides access to per-Conn contexts.

Jump to

Keyboard shortcuts

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