Documentation
¶
Overview ¶
Package databend is a database/sql driver for Databend, which runs SQL over the query API of HTTP. It registers the one name "databend", and takes a DSN of the form databend://user:pass@host:8000/database?key=value (D117).
db, err := sql.Open("databend", "databend://root:pass@localhost:8000/default")
The server binds each argument: a positional argument fills each ? in order, and sql.Named("k", v) fills :k (D120). Each result arrives one page at a time, and when the context ends, or the rows close before their end, the driver kills the query on the server (D123). Every value arrives as text, and the driver decodes it by the type of its column, an array, a map and a tuple too (D118 and D119). A transaction and the settings of SET and USE are carried in the session of the connection (D121 and D122). docs/DATABEND.md holds what the driver knows about the server.
Index ¶
Constants ¶
const ( // CancelKill sends GET on the kill URI of the query. It is the default. CancelKill = "kill" // CancelNone sends nothing, and the query runs on to its end. CancelNone = "none" )
The values of the key cancel, which say how the driver stops a query on the server when its context ends or its rows close early (D123).
const ( // AuthBasic sends the user and the password with basic authentication. // It is the default. AuthBasic = dbimp.AuthBasic // AuthBearer sends the password as a Bearer token, such as a JWT. AuthBearer = dbimp.AuthBearer )
The values of the key auth, which say how the driver sends the password (D94).
const Name = "databend"
Name is the name that the driver registers with database/sql, and the scheme of its DSN.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Host is the host of the server.
Host string
// Port is the port of the server, 8000 by default.
Port int
// TLS is true to speak HTTPS.
TLS bool
// User and Password are the credentials. The password can be a token
// (D94).
User string
Password string
// Auth is AuthBasic or AuthBearer (D94).
Auth string
// Database is the database, default by default.
Database string
// Cancel is CancelKill or CancelNone (D123).
Cancel string
// Timezone is the timezone of the session, such as UTC, or "" for the
// setting of the server.
Timezone string
}
Config is the configuration of a connector, which the DSN holds. The caller owns it (D7).
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector opens connections to one database. It owns its transport, and every connection shares it. A caller can build one from a Config and open it with sql.OpenDB.
func NewConnector ¶
NewConnector returns a Connector for cfg. The connector keeps a copy of cfg, and fills each field that is zero with its default.
type Driver ¶
type Driver struct{}
Driver is the database/sql driver for Databend.
type Error ¶
type Error struct {
// HTTPStatus is the status code of the response.
HTTPStatus int
// Code is the code of the server, or the HTTP status when the body held
// none.
Code int
// Message is the message of the server.
Message string
// contains filtered or unexported fields
}
Error is an error that Databend reported, with its HTTP status and its code, such as 1005 for a statement that does not parse (measured). A statement that fails has HTTP 200 and the error in its body.
type Option ¶
Option sets an option of one statement or one transaction (D109). An option comes from the DSN, then from the context through WithOptions, then from an argument of the statement, and a later one wins. BeginTx takes no argument, so an option of a transaction comes from the DSN or through WithOptions only.
func WithCancel ¶
WithCancel sets how the driver stops the statement on the server, CancelKill or CancelNone, as the key cancel of the DSN does (D123).
func WithDatabase ¶
WithDatabase sets the database of the statement, which the session of the request names, as the path of the DSN does. The next statement of the connection returns to the database of its session.
func WithParameter ¶
WithParameter sets any key of the body of POST /v1/query by its name, such as "pagination". The value is encoded with json/v2. A key named here replaces one that the driver sets itself, as in Couchbase.
func WithReadonly ¶
WithReadonly would make the server refuse a write. The server has no read-only mode for one statement, so a statement with it fails with dbimp.ErrNotSupported (D117).
func WithTimeout ¶
WithTimeout sets the time that the server gives the statement, as the setting max_execute_time_in_seconds, which counts whole seconds, so the driver rounds d up to the next second. The server stops a statement that runs longer with the code 1043 (measured).
func WithTimezone ¶
WithTimezone sets the timezone of the statement, as the key timezone of the DSN does.