arangodb

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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).

View Source
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).

View Source
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

func WithOptions added in v0.6.0

func WithOptions(ctx context.Context, opts ...Option) context.Context

WithOptions returns a context that carries opts. Each statement and each transaction started with the context applies them after the options of the DSN.

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).

func ParseDSN

func ParseDSN(dsn string) (*Config, error)

ParseDSN parses a DSN of the form arangodb://user:pass@host:port/database?key=value (D27, D35 and D93).

func (*Config) FormatDSN

func (cfg *Config) FormatDSN() string

FormatDSN returns the DSN of cfg. ParseDSN reads it back as cfg, for a Config that ParseDSN or NewConnector filled.

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

func NewConnector(cfg Config) *Connector

NewConnector returns a Connector for cfg. The connector keeps a copy of cfg, and fills each field that is zero with its default.

func (*Connector) Close

func (c *Connector) Close() error

Close closes the idle connections of the transport.

func (*Connector) Connect

func (c *Connector) Connect(context.Context) (driver.Conn, error)

Connect satisfies driver.Connector. A connection holds no state on the server, except a transaction while one is open. Each connection has a random id, which names its queries for cancel=tag (D90).

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

Driver satisfies driver.Connector.

type Driver

type Driver struct{}

Driver is the database/sql driver for ArangoDB.

func (Driver) Open

func (Driver) Open(string) (driver.Conn, error)

Open satisfies driver.Driver. database/sql opens a connection through OpenConnector, and Open returns an error, because opening a connection needs a context.

func (Driver) OpenConnector

func (Driver) OpenConnector(dsn string) (driver.Connector, error)

OpenConnector satisfies driver.DriverContext. It parses the DSN.

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) Error

func (err *Error) Error() string

Error satisfies the error interface.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap returns the *dbimp.StatusError of the response.

type Option added in v0.6.0

type Option = dbimp.Option[options]

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

func WithBatch(n int) Option

WithBatch sets the batchSize of the cursor, as the key batch of the DSN does.

func WithCancel added in v0.6.0

func WithCancel(how string) Option

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

func WithDatabase(name string) Option

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

func WithParameter(name string, value any) Option

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

func WithReadonly(v bool) Option

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

func WithTimeout(d time.Duration) Option

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).

Jump to

Keyboard shortcuts

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