Documentation
¶
Overview ¶
Package arangodb is a database/sql driver for ArangoDB, which runs AQL over the cursor API of HTTP. It registers the one name "arangodb", and takes a DSN of the form arangodb://user:pass@host:8529/database?key=value (D93).
db, err := sql.Open("arangodb", "arangodb://root:pass@localhost:8529/mydb")
The server binds each argument: sql.Named("k", v) fills @k, and a positional argument n fills @n, such as @1. A named argument that the query uses as @@k names a collection. Each query streams, one batch at a time, and with cancel=tag the driver stops it on the server when its context ends (D90). A stored document or edge is one column, and the keys of any other object are the columns (D89). A transaction names every collection of the database that is not a system collection (D91). The driver also takes CREATE and DROP of collections and indexes, which AQL does not have (D92). docs/ARANGODB.md holds what the driver knows about the server.
Index ¶
Constants ¶
const ( // CancelTag adds a line comment that names the connection and the query, // at the end of each query, or at the start of a long one (D99). It kills the query through /_api/query when // its context ends before the first batch, or when Close comes in the // first batch with more than 1 MiB of it left. It is the default. CancelTag = "tag" // CancelNone sends no comment, and a query in its first request 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 (D90).
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 = "arangodb"
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, 8529 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
// Database is the database, _system by default.
Database string
// Cancel is CancelTag or CancelNone (D90).
Cancel string
// Batch is the batchSize of each cursor, 1000 by default.
Batch int
// Auth is AuthBasic or AuthBearer (D94).
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 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 ArangoDB.
type Error ¶
type Error struct {
// HTTPStatus is the status code of the response.
HTTPStatus int
// Num is the errorNum of the server, or 0 when the body held none.
Num int
// Message is the errorMessage of the server.
Message string
// contains filtered or unexported fields
}
Error is an error that ArangoDB reported, with its HTTP status and its errorNum, such as 1501 for a statement that does not parse (measured). Compare Num, and not the message, as the vendor says.
func (*Error) AuthenticationRefused ¶ added in v0.24.0
AuthenticationRefused reports whether the server refused the credential. It returns what Is reports for dbimp.ErrAuthentication, and a caller that does not import this module reads it through an interface of its own (D227).
type Option ¶ added in v0.6.0
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 WithBatch ¶ added in v0.6.0
WithBatch sets the batchSize of the cursor, as the key batch of the DSN does.
func WithCancel ¶ added in v0.6.0
WithCancel sets how the driver stops the query on the server when its context ends, CancelTag or CancelNone, as the key cancel of the DSN does (D90).
func WithDatabase ¶ added in v0.6.0
WithDatabase sets the database of the statement or the transaction, which the path of the request names. A statement of a transaction runs in the database of the transaction, so another database there fails with dbimp.ErrNotSupported.
func WithParameter ¶ added in v0.6.0
WithParameter sets any key of the body of POST /_api/cursor by its name, such as "ttl" or "memoryLimit". The value is encoded with json/v2. A key named here replaces one that the driver sets itself, as in Couchbase.
func WithReadonly ¶ added in v0.6.0
WithReadonly makes the transaction of BeginTx read-only, as the ReadOnly of sql.TxOptions does: it names no collection for write (D91). The server has no read-only mode for one query, so a statement with WithReadonly fails with dbimp.ErrNotSupported, unless it runs in a read-only transaction.
func WithTimeout ¶ added in v0.6.0
WithTimeout sets the time that the server gives the query, as options.maxRuntime, in seconds with a fraction. The server kills a query that runs longer, with HTTP 410 and the error 1500 (measured by hand on 3.12.12).