This page provides an overview of the ArangoDB wrapper functions available in Lua on Beans. These functions allow you to interact with ArangoDB, a multi-model database, using Lua.
For more detailed information about ArangoDB's HTTP API, which these wrapper functions are based on, please refer to the official ArangoDB HTTP API documentation.
The Aql function is used to execute ArangoDB Query Language (AQL) queries. It allows you to perform complex data retrieval and manipulation operations on your ArangoDB database.
Adb.Aql(query, [bindVars])
The function returns the result of the AQL query execution.
local result = Adb.Aql("FOR doc IN users LIMIT @limit RETURN doc", { limit = 10 })
The Auth function is used to authenticate with the ArangoDB server. It establishes a connection and sets up the necessary credentials for subsequent database operations.
Adb.Auth(db_config)
The function returns the result of the authentication process.
local db_config = {
server = "http://localhost:8529",
username = "root",
password = "password"
}
local result = Adb.Auth(db_config)
The GetDocument function is used to retrieve a document from ArangoDB using its unique identifier.
Adb.GetDocument(id)
The function returns the requested document if found, or an error if the document doesn't exist.
local document = Adb.GetDocument("users/12345")
The UpdateDocument function is used to update an existing document in ArangoDB.
Adb.UpdateDocument(handle, params)
The function returns the result of the update operation, typically including the updated document.
local handle = "users/12345"
local params = {
name = "John Doe",
age = 30
}
local result = Adb.UpdateDocument(handle, params)
The CreateDocument function is used to create a new document in ArangoDB.
Adb.CreateDocument(collection, document)
The function returns the result of the create operation, typically including the newly created document with its assigned _key and _id.
local collection = "users"
local document = {
name = "Jane Doe",
age = 28,
email = "jane.doe@example.com"
}
local result = Adb.CreateDocument(collection, document)
The DeleteDocument function is used to remove an existing document from ArangoDB.
Adb.DeleteDocument(handle)
The function returns the result of the delete operation, typically including a confirmation of the deletion.
local handle = "users/12345"
local result = Adb.DeleteDocument(handle)
The PatchDocument function is used to partially update an existing document in ArangoDB.
Adb.PatchDocument(handle, params)
The function returns the result of the patch operation, typically including the updated document.
local handle = "users/12345"
local params = {
age = 31,
email = "john.doe@newemail.com"
}
local result = Adb.PatchDocument(handle, params)
The GetCollection function is used to retrieve information about a specific collection in ArangoDB.
Adb.GetCollection(collection_name)
The function returns information about the specified collection, including its properties and statistics.
local collection_info = Adb.GetCollection("users")
The UpdateCollection function is used to modify the properties of an existing collection in ArangoDB.
Adb.UpdateCollection(collection_name, properties)
The function returns the result of the update operation, typically including the updated collection properties.
local properties = {
waitForSync = true
}
local result = Adb.UpdateCollection("users", properties)
The RenameCollection function is used to change the name of an existing collection in ArangoDB.
Adb.RenameCollection(old_name, new_name)
The function returns the result of the rename operation, typically including confirmation of the name change.
local result = Adb.RenameCollection("old_users", "new_users")
The CreateCollection function is used to create a new collection in ArangoDB.
Adb.CreateCollection(collection_name, [options])
The function returns the result of the create operation, typically including details of the newly created collection.
local options = {
type = 2, -- document collection
waitForSync = true
}
local result = Adb.CreateCollection("new_users", options)
The CreateCollectionWithTimestamps function creates a new collection in ArangoDB with automatic timestamp fields.
Adb.CreateCollectionWithTimestamps(collection_name, [options])
The function returns the result of the create operation, including details of the newly created collection with timestamp fields.
local options = {
waitForSync = true
}
local result = Adb.CreateCollectionWithTimestamps("timestamped_users", options)
The DeleteCollection function is used to remove an existing collection from ArangoDB.
Adb.DeleteCollection(collection_name)
The function returns the result of the delete operation, typically including confirmation of the collection deletion.
local result = Adb.DeleteCollection("old_users")
The PatchCollection function is used to partially update the properties of an existing collection in ArangoDB.
Adb.PatchCollection(collection_name, properties)
The function returns the result of the patch operation, typically including the updated collection properties.
local properties = {
waitForSync = false
}
local result = Adb.PatchCollection("users", properties)
The TruncateCollection function is used to remove all documents from a collection in ArangoDB while keeping the collection itself.
Adb.TruncateCollection(collection_name)
The function returns the result of the truncate operation, typically including confirmation that the collection has been emptied.
local result = Adb.TruncateCollection("users")
The GetAllIndexes function is used to retrieve information about all indexes in a specific collection in ArangoDB.
Adb.GetAllIndexes(collection_name)
The function returns a list of all indexes in the specified collection, including their properties and types.
local indexes = Adb.GetAllIndexes("users")
The CreateIndex function is used to create a new index on a collection in ArangoDB.
Adb.CreateIndex(collection_name, index_definition)
The function returns the result of the index creation, typically including details of the newly created index.
local index_definition = {
type = "hash",
fields = {"email"},
unique = true
}
local result = Adb.CreateIndex("users", index_definition)
The DeleteIndex function is used to remove an existing index from a collection in ArangoDB.
Adb.DeleteIndex(index_handle)
The function returns the result of the delete operation, typically including confirmation of the index deletion.
local index_handle = "users/12345"
local result = Adb.DeleteIndex(index_handle)
The CreateDatabase function is used to create a new database in ArangoDB.
Adb.CreateDatabase(database_name, [options])
The function returns the result of the create operation, typically including details of the newly created database.
local options = {
users = {
{username = "admin", passwd = "secret", active = true}
}
}
local result = Adb.CreateDatabase("new_database", options)
The DeleteDatabase function is used to remove an existing database from ArangoDB.
Adb.DeleteDatabase(database_name)
The function returns the result of the delete operation, typically including confirmation of the database deletion.
local result = Adb.DeleteDatabase("old_database")
The BeginTransaction function is used to start a new transaction in ArangoDB.
Adb.BeginTransaction([options])
The function returns the result of the transaction initiation, typically including a transaction ID.
local options = {
collections = {
write = {"users", "orders"}
}
}
local result = Adb.BeginTransaction(options)
The CommitTransaction function is used to commit an ongoing transaction in ArangoDB.
Adb.CommitTransaction(transaction_id)
The function returns the result of the commit operation, typically including confirmation of the transaction commit.
local result = Adb.CommitTransaction("12345")
The AbortTransaction function is used to abort an ongoing transaction in ArangoDB.
Adb.AbortTransaction(transaction_id)
The function returns the result of the abort operation, typically including confirmation of the transaction abort.
local result = Adb.AbortTransaction("12345")
The GetQueryCacheEntries function is used to retrieve information about the entries in the query cache of ArangoDB.
Adb.GetQueryCacheEntries()
This function does not take any parameters.
The function returns a list of entries in the query cache, including details about each cached query.
local cache_entries = Adb.GetQueryCacheEntries()
The GetQueryCacheConfiguration function is used to retrieve the current configuration of the query cache in ArangoDB.
Adb.GetQueryCacheConfiguration()
This function does not take any parameters.
The function returns the current configuration settings of the query cache.
local cache_config = Adb.GetQueryCacheConfiguration()
The UpdateCacheConfiguration function is used to modify the configuration of the query cache in ArangoDB.
Adb.UpdateCacheConfiguration(config)
The function returns the result of the update operation, typically including the new configuration settings.
local new_config = {
mode = "on",
maxResults = 1000
}
local result = Adb.UpdateCacheConfiguration(new_config)
The DeleteQueryCache function is used to clear the query cache in ArangoDB.
Adb.DeleteQueryCache()
This function does not take any parameters.
The function returns the result of the delete operation, typically indicating whether the cache was successfully cleared.
local result = Adb.DeleteQueryCache()
The RefreshToken function is used to refresh the authentication token for the ArangoDB connection.
Adb.RefreshToken(db_config)
This function does not return a value. It refreshes the token if necessary.
RefreshToken checks if the current token is older than 10 minutes (600 seconds). If so, it calls the Auth function to get a new token and updates the LastDBConnect time.
local db_config = {
-- database configuration details
}
Adb.RefreshToken(db_config)