arango_driver 0.3.0-nullsafety.0 arango_driver: ^0.3.0-nullsafety.0 copied to clipboard
ArangoDB driver, working on top of ArangoDB HTTP API. This package is a fork of the dart_arango_min package.
ArangoDB driver for Dart with null safety #
See EXAMPLE tab for example of code and see tests in repository for much more examples.
Getting Started #
First, you need to create a client that represents connections to
var client = ArangoDBClient(
scheme: 'http',
host: 'host.where.runned.arangodb.com',
port: 8529, // <- use your real ArangoDB port
db: 'blog', // <- the name of database for connect
// User below must have access for you database:
user: 'user1', // <- use real username for this database
pass: 'user1password', // <- use real password for this user
);
Data manipulation and query operations assume the database and the collection already exist. Both can be created from this API. Here's an example of how to create a collection in case it doesn't exist:
if (!(await cli.allCollections()).result.any((e) => e.name == 'posts')) {
await cli.createCollection(name: 'posts');
}
Then, documents to be inserted can be represented as Map<String, dynamic>:
var createResult = await client.createDocument('posts', // the collection
// the content of the new document
{
'title': 'My new post',
'public': false, // do not publish it, we want to edit it later
'content': [
// let 'content' field is array with a different keys
{
// let one of key is 'markdown' with text as it's value:
'mardown': '__My markdown text__',
},
],
});
Querying is also easy:
// Let collection 'posts' exists in database 'blog'.
// Read all titles for public posts.
var titles = await client
.newQuery()
// this part of query will be added anyway:
.addLine('FOR post IN posts')
// part of query will be added only if readOnlyPublic is true:
.addLineIfThen(readOnlyPublic, 'FILTER post.public')
// this line will be added if postKey!=null:
// Look to @key in this line: this is placeholder for binded value
// (it will appear later):
.addLineIfThen(true, 'FILTER post._key=@key')
.addLine('RETURN post.title')
// binded variable named as 'key' (accessed in query as '@key')
// will be inserted to query only if postKey!=null:
.addBindVarIfThen(true, 'key', postKey)
// Run query now.
// Remember that we used 'await' keyword in above of this chain.
.runAndReturnFutureList(); // <-- result type is Future<List>
// See also .runAndReturnStream() method.