Documentation ¶
Overview ¶
Package arangolite provides a lightweight ArangoDB driver.
Index ¶
- type CollectionInfo
- type CollectionInfoList
- type CreateCollection
- type CreateDatabase
- type CreateGraph
- type CreateHashIndex
- type DB
- func (db *DB) Connect(url, database, username, password string) *DB
- func (db *DB) LoggerOptions(enabled, printQuery, printResult bool) *DB
- func (db *DB) Run(q Runnable) ([]byte, error)
- func (db *DB) RunAsync(q Runnable) (*Result, error)
- func (db *DB) Send(description, method, path string, req interface{}) ([]byte, error)
- func (db *DB) SwitchDatabase(database string) *DB
- func (db *DB) SwitchUser(username, password string) *DB
- type Document
- type DropCollection
- type DropDatabase
- type DropGraph
- type Edge
- type EdgeDefinition
- type ErrDuplicate
- type ErrNotFound
- type ErrUnique
- type GetCacheProperties
- type GetCollectionInfo
- type GetGraph
- type Graph
- type GraphData
- type GraphList
- type ImportCollection
- type ListCollections
- type ListGraphs
- type Query
- type Result
- type Runnable
- type SetCacheProperties
- type Transaction
- func (t *Transaction) AddQuery(resultVar, aql string, params ...interface{}) *Transaction
- func (t *Transaction) Bind(name string, value interface{}) *Transaction
- func (t *Transaction) Description() string
- func (t *Transaction) Generate() []byte
- func (t *Transaction) Method() string
- func (t *Transaction) Path() string
- func (t *Transaction) Return(resultVar string) *Transaction
- type TruncateCollection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CollectionInfo ¶
type CollectionInfoList ¶
type CollectionInfoList struct { Collections []CollectionInfo `json:"collections"` Error bool `json:"error"` Code int `json:"code"` }
type CreateCollection ¶
type CreateCollection struct { JournalSize int `json:"journalSize,omitempty"` KeyOptions map[string]interface{} `json:"keyOptions,omitempty"` Name string `json:"name"` WaitForSync *bool `json:"waitForSync,omitempty"` DoCompact *bool `json:"doCompact,omitempty"` IsVolatile *bool `json:"isVolatile,omitempty"` ShardKeys []string `json:"shardKeys,omitempty"` NumberOfShards int `json:"numberOfShards,omitempty"` IsSystem *bool `json:"isSystem,omitempty"` Type int `json:"type,omitempty"` IndexBuckets int `json:"indexBuckets,omitempty"` }
CreateCollection creates a collection in database.
func (*CreateCollection) Description ¶
func (r *CreateCollection) Description() string
func (*CreateCollection) Generate ¶
func (r *CreateCollection) Generate() []byte
func (*CreateCollection) Method ¶
func (r *CreateCollection) Method() string
func (*CreateCollection) Path ¶
func (r *CreateCollection) Path() string
type CreateDatabase ¶
type CreateDatabase struct { Username string `json:"username,omitempty"` Name string `json:"name"` Extra json.RawMessage `json:"extra,omitempty"` Passwd string `json:"passwd,omitempty"` Active *bool `json:"active,omitempty"` Users []map[string]interface{} `json:"users,omitempty"` }
CreateDatabase creates a new database.
func (*CreateDatabase) Description ¶
func (r *CreateDatabase) Description() string
func (*CreateDatabase) Generate ¶
func (r *CreateDatabase) Generate() []byte
func (*CreateDatabase) Method ¶
func (r *CreateDatabase) Method() string
func (*CreateDatabase) Path ¶
func (r *CreateDatabase) Path() string
type CreateGraph ¶
type CreateGraph struct { Name string `json:"name"` EdgeDefinitions []EdgeDefinition `json:"edgeDefinitions,omitempty"` OrphanCollections []string `json:"orphanCollections,omitempty"` }
CreateGraph creates a collection in database.
func (*CreateGraph) Description ¶
func (c *CreateGraph) Description() string
func (*CreateGraph) Generate ¶
func (c *CreateGraph) Generate() []byte
func (*CreateGraph) Method ¶
func (c *CreateGraph) Method() string
func (*CreateGraph) Path ¶
func (c *CreateGraph) Path() string
type CreateHashIndex ¶
type CreateHashIndex struct { CollectionName string `json:"-"` Fields []string `json:"fields,omitempty"` Unique *bool `json:"unique,omitempty"` Type string `json:"type,omitempty"` Sparse *bool `json:"sparse,omitempty"` }
CreateHashIndex creates a hash index in database.
func (*CreateHashIndex) Description ¶
func (r *CreateHashIndex) Description() string
func (*CreateHashIndex) Generate ¶
func (r *CreateHashIndex) Generate() []byte
func (*CreateHashIndex) Method ¶
func (r *CreateHashIndex) Method() string
func (*CreateHashIndex) Path ¶
func (r *CreateHashIndex) Path() string
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents an access to an ArangoDB database.
func (*DB) LoggerOptions ¶
LoggerOptions sets the Arangolite logger options.
func (*DB) Run ¶
Run runs the Runnable synchronously and returns the JSON array of all elements of every batch returned by the database.
func (*DB) Send ¶
Send runs a low level request in the database. The description param is shown in the logger. The req param is serialized in the body. The purpose of this method is to be a fallback in case the user wants to do something which is not implemented in the requests.go file.
func (*DB) SwitchDatabase ¶
SwitchDatabase change the current database.
func (*DB) SwitchUser ¶
SwitchUser change the current user.
type Document ¶
type Document struct { // The document handle. Format: ':collection/:key' ID *string `json:"_id,omitempty"` // The document's revision token. Changes at each update. Rev *string `json:"_rev,omitempty"` // The document's unique key. Key *string `json:"_key,omitempty"` }
Document represents a basic ArangoDB document Fields are pointers to allow null values in ArangoDB
type DropCollection ¶
type DropCollection struct {
Name string
}
DropCollection deletes a collection in database.
func (*DropCollection) Description ¶
func (r *DropCollection) Description() string
func (*DropCollection) Generate ¶
func (r *DropCollection) Generate() []byte
func (*DropCollection) Method ¶
func (r *DropCollection) Method() string
func (*DropCollection) Path ¶
func (r *DropCollection) Path() string
type DropDatabase ¶
type DropDatabase struct {
Name string
}
DropDatabase deletes a database.
func (*DropDatabase) Description ¶
func (r *DropDatabase) Description() string
func (*DropDatabase) Generate ¶
func (r *DropDatabase) Generate() []byte
func (*DropDatabase) Method ¶
func (r *DropDatabase) Method() string
func (*DropDatabase) Path ¶
func (r *DropDatabase) Path() string
type Edge ¶
type Edge struct { Document // Reference to another document. Format: ':collection/:key' // Required: true From *string `json:"_from,omitempty"` // Reference to another document. Format: ':collection/:key' // Required: true To *string `json:"_to,omitempty"` }
Edge represents a basic ArangoDB edge Fields are pointers to allow null values in ArangoDB
type EdgeDefinition ¶
type EdgeDefinition struct { Collection string `json:"collection"` From []string `json:"from"` To []string `json:"to"` }
EdgeDefinition is a definition of the graph edges
type ErrDuplicate ¶
type ErrDuplicate struct {
// contains filtered or unexported fields
}
ErrDuplicate throwned when error message contains "duplicate name" string.
func (*ErrDuplicate) Error ¶
func (e *ErrDuplicate) Error() string
type ErrNotFound ¶
type ErrNotFound struct {
// contains filtered or unexported fields
}
ErrNotFound throwned when error message contains "not found" or "unknown collection" string.
func (*ErrNotFound) Error ¶
func (e *ErrNotFound) Error() string
type ErrUnique ¶
type ErrUnique struct {
// contains filtered or unexported fields
}
ErrUnique throwned when error message contains "unique constraint violated" string.
type GetCacheProperties ¶
type GetCacheProperties struct{}
GetCacheProperties retrieves the current query cache properties.
func (*GetCacheProperties) Description ¶
func (r *GetCacheProperties) Description() string
func (*GetCacheProperties) Generate ¶
func (r *GetCacheProperties) Generate() []byte
func (*GetCacheProperties) Method ¶
func (r *GetCacheProperties) Method() string
func (*GetCacheProperties) Path ¶
func (r *GetCacheProperties) Path() string
type GetCollectionInfo ¶
CollectionInfo gets information about the collection
func (*GetCollectionInfo) Description ¶
func (c *GetCollectionInfo) Description() string
func (*GetCollectionInfo) Generate ¶
func (c *GetCollectionInfo) Generate() []byte
func (*GetCollectionInfo) Method ¶
func (c *GetCollectionInfo) Method() string
func (*GetCollectionInfo) Path ¶
func (c *GetCollectionInfo) Path() string
type GetGraph ¶
type GetGraph struct {
Name string
}
GetGraph gets a graph from the graph module.
func (*GetGraph) Description ¶
type Graph ¶
type Graph struct { Name string `json:"name"` //An array of definitions for the edges EdgeDefinitions []EdgeDefinition `json:"edgeDefinitions,omitempty"` //An array of additional vertex collections. OrphanCollections []string `json:"orphanCollections,omitempty"` ID string `json:"_id,omitempty"` Rev string `json:"_rev,omitempty"` }
Graph represents a graph definition.
type GraphData ¶
type GraphData struct {
Graph Graph `json:"graph"`
}
GraphData is a container for data returned by a GET GRAPH request
type GraphList ¶
type GraphList struct {
Graphs []Graph `json:"graphs"`
}
GraphList is a container for data returned by a LIST GRAPHS request
type ImportCollection ¶
ImportCollection imports data to a collection
func (*ImportCollection) Description ¶
func (c *ImportCollection) Description() string
func (*ImportCollection) Generate ¶
func (c *ImportCollection) Generate() []byte
func (*ImportCollection) Method ¶
func (c *ImportCollection) Method() string
func (*ImportCollection) Path ¶
func (c *ImportCollection) Path() string
type ListCollections ¶
type ListCollections struct {
// contains filtered or unexported fields
}
ListCollections lists all collections from the current DB
func (*ListCollections) Description ¶
func (c *ListCollections) Description() string
func (*ListCollections) Generate ¶
func (c *ListCollections) Generate() []byte
func (*ListCollections) Method ¶
func (c *ListCollections) Method() string
func (*ListCollections) Path ¶
func (c *ListCollections) Path() string
type ListGraphs ¶
type ListGraphs struct{}
ListGraph lists all graphs known by the graph module.
func (*ListGraphs) Description ¶
func (l *ListGraphs) Description() string
func (*ListGraphs) Generate ¶
func (l *ListGraphs) Generate() []byte
func (*ListGraphs) Method ¶
func (l *ListGraphs) Method() string
func (*ListGraphs) Path ¶
func (l *ListGraphs) Path() string
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents an AQL query.
func (*Query) Bind ¶
Bind sets the name and value of a bind parameter Binding parameters prevents AQL injection
func (*Query) Cache ¶
Cache enables/disables the caching of the query. Unavailable prior to ArangoDB 2.7
func (*Query) Description ¶
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result defines a query result, allowing the user to retrieve asynchronously every batch returned by the database.
type Runnable ¶
type Runnable interface { Description() string // Description shown in the logger Generate() []byte // The body of the request Path() string // The path where to send the request Method() string // The HTTP method to use }
Runnable defines requests runnable by the Run and RunAsync methods. Queries, transactions and everything in the requests.go file are Runnable.
type SetCacheProperties ¶
type SetCacheProperties struct { Mode string `json:"mode,omitempty"` MaxResults int `json:"maxResults,omitempty"` }
SetCacheProperties sets the query cache properties.
func (*SetCacheProperties) Description ¶
func (r *SetCacheProperties) Description() string
func (*SetCacheProperties) Generate ¶
func (r *SetCacheProperties) Generate() []byte
func (*SetCacheProperties) Method ¶
func (r *SetCacheProperties) Method() string
func (*SetCacheProperties) Path ¶
func (r *SetCacheProperties) Path() string
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction represents an ArangoDB transaction.
func NewTransaction ¶
func NewTransaction(readCol, writeCol []string) *Transaction
NewTransaction returns a new Transaction object.
func (*Transaction) AddQuery ¶
func (t *Transaction) AddQuery(resultVar, aql string, params ...interface{}) *Transaction
AddQuery adds a new AQL query to the transaction. The result will be set in a temp variable named after the value of "resultVar". To use it from elsewhere in the transaction, use the Go templating convention.
e.g. NewTransaction([]string{}, []string{}).
AddQuery("var1", "FOR d IN documents RETURN d"). AddQuery("var2", "FOR d IN {{.var1}} RETURN d._id").Run(db)
func (*Transaction) Bind ¶
func (t *Transaction) Bind(name string, value interface{}) *Transaction
Bind sets the name and value of a bind parameter Binding parameters prevents AQL injection Example: transaction := arangolite.NewTransaction([]string{}, []string{}).
AddQuery("var1", "FOR d IN nodes FILTER d._key == @key RETURN d._id"). AddQuery("var2", "FOR n IN nodes FILTER n._id == {{.var1}}[0] RETURN n._key").Return("var2")
transaction.Bind("key", 123)
func (*Transaction) Description ¶
func (t *Transaction) Description() string
func (*Transaction) Generate ¶
func (t *Transaction) Generate() []byte
func (*Transaction) Method ¶
func (t *Transaction) Method() string
func (*Transaction) Path ¶
func (t *Transaction) Path() string
func (*Transaction) Return ¶
func (t *Transaction) Return(resultVar string) *Transaction
Return sets the final "resultVar" that is returned at the end of the transaction.
type TruncateCollection ¶
type TruncateCollection struct {
Name string
}
TruncateCollection deletes a collection in database.
func (*TruncateCollection) Description ¶
func (r *TruncateCollection) Description() string
func (*TruncateCollection) Generate ¶
func (r *TruncateCollection) Generate() []byte
func (*TruncateCollection) Method ¶
func (r *TruncateCollection) Method() string
func (*TruncateCollection) Path ¶
func (r *TruncateCollection) Path() string