arangodb

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 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 = "basic"
	// AuthBearer sends the password as a Bearer token, such as a JWT.
	AuthBearer = "bearer"
)

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

This section is empty.

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.

Jump to

Keyboard shortcuts

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