Documentation
¶
Overview ¶
Package avatica is a database/sql driver for Apache Calcite Avatica, which carries the calls of JDBC over HTTP to a server that runs them on a database behind it. It serves the standalone server of Avatica and the Apache Phoenix Query Server, over JSON (D153). It registers the one name "avatica", and takes a DSN of the form avatica://user:pass@host:8765 (D156).
db, err := sql.Open("avatica", "avatica://SA@localhost:8765")
One connection of database/sql is one connection of Avatica, with autoCommit on (D157). A query reads its rows in frames, one token at a time, and fetches each next frame (D157). The server binds each argument as a typed value (D158). A value has the Go type that fits the name of its type of JDBC (D155). Transactions are those of the database behind the server, and the server has no way to stop a statement (D159). docs/AVATICA.md holds what the driver knows about the server.
Index ¶
Constants ¶
const ( // AuthNone sends the user and the password in the info of // openConnection only. It is the default. AuthNone = "none" // AuthBasic also sends them by HTTP basic authentication, for a server // that checks them itself. AuthBasic = dbimp.AuthBasic )
The values of the key auth, which say whether the driver also sends the user and the password by HTTP basic authentication (D156).
const Name = "avatica"
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, 8765 by default.
Port int
// TLS is true to speak HTTPS.
TLS bool
// User and Password are the credentials, which go in the info of
// openConnection, to the database behind the server.
User string
Password string
// Auth is AuthNone or AuthBasic (D156).
Auth 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 server. 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 Avatica.
type Error ¶
type Error struct {
// HTTPStatus is the status code of the response.
HTTPStatus int
// Message is the message of the server: errorMessage, or the first line
// of the first exception when the server sent none.
Message string
// Code is errorCode, such as 1 for an unknown connection.
Code int
// SQLState is sqlState, which HSQLDB leaves as 00000.
SQLState string
// Exception is the first line of the first exception, such as
// java.sql.SQLSyntaxErrorException: unexpected token: SELEC.
Exception string
// contains filtered or unexported fields
}
Error is an error that the server of Avatica reported. It arrives with HTTP 500, as {"response": "error", "exceptions": [...], "errorMessage": ..., "errorCode": ..., "sqlState": ..., "severity": ...} (measured).
type Option ¶
Option sets an option of one statement (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.
func WithDatabase ¶
WithDatabase would choose the schema of one statement. The schema is a property of the connection of Avatica, which one statement cannot change, so a statement with it fails with dbimp.ErrNotSupported. The SQL can name the schema of each table.
func WithFrameSize ¶
WithFrameSize sets the count of rows of each frame that the driver asks for, 1000 by default (D157).
func WithParameter ¶
WithParameter sets any key of the request that runs the statement by its name, such as "maxRowCount". The value is encoded with json/v2. A key named here replaces one that the driver sets itself.
func WithReadonly ¶
WithReadonly would make the server refuse a write of one statement. readOnly is a property of the connection of Avatica, which one statement cannot change, so WithReadonly(true) fails with dbimp.ErrNotSupported. BeginTx with ReadOnly makes a transaction read-only (D159).
func WithTimeout ¶
WithTimeout would bound the time of the statement on the server. Avatica has none, and the server runs a query to its end when its client leaves (measured), so a timeout above zero fails with dbimp.ErrNotSupported. The context of the statement still stops its request and its read (D159).