dart_arango_min 0.2.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

Minimalistic ArangoDB driver for Dart.

See EXAMPLE tab for example of code and see tests in repository for much more examples.

0.0.1-dev.0.1 #

  • Initial version, created by Stagehand

0.0.1-dev.0.2 #

  • MVP realised

0.0.1-dev.0.3 #

  • FIX return type

0.0.1-dev.0.4 #

  • queryToListOfMap() method was added.

0.0.1-dev.0.5 #

  • queryToListOfMap() -> queryToList() and query() -> queryToStream()

0.0.1-dev.0.6 #

  • type of elements of queryToList() and queryToStream() is dynamic

0.0.1-dev.0.7 #

  • try to count bytes

0.0.1-dev.0.8 #

  • throws error if query iresult has error

0.0.2 #

  • Query() constructor

0.0.3 #

  • delete FromList() constructor

0.0.4 #

  • fix toMap() return type

0.0.5 #

  • addLine* - methods to Query
  • addBind* - methods to Query

0.0.6 #

QueryWithOwner class

0.0.7 #

QueryWithClient instead of QueryWithOwner class RunAndReturnFutureList RunAndReturnStream

0.0.8 #

newQuery creates QueryWithClient

0.0.9 #

fix bug

0.0.10 #

remove return types for some methods

0.0.12 #

move methods to QueryWithClient class with return value type

0.0.13 #

fix bug

0.0.14 #

camel case

0.1.1 #

Breaking! Code style

0.1.2 #

replaceDocument() method was added

0.1.3 #

removeDocument() was added

0.1.4 #

replaceDocuments() method was added

0.1.5 #

removeDocuments() method was added

0.1.6 #

check ArangoDBClient() arguments for not null

0.1.7 #

Query example added.

0.1.8 #

More examples

0.1.9 #

fix project description

0.2.0 #

fix README

0.2.1 #

remove commented tests

0.2.2 #

Change description.

0.2.3 #

Fix example

example/example.dart

// Import dart_arango_min package:
import 'dart:io';

import 'package:dart_arango_min/dart_arango_min.dart';

main() async {
// First, create client for database:
  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
  );

  // Lets, we have some condition which blog documents to read:
  bool readOnlyPublic = true;
  String postKey = '1234567';

  // 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(postKey != null, '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(postKey != null, '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.

  for (var title in titles) {
    print(title);
  }

  // Let's create a new post:
  var createResult = await client.createDocument('posts', {
    '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__',
      },
    ],
  });

  // See ArangoDB answer documentation for answer structure:
  // https://www.arangodb.com/docs/3.5/http/document-working-with-documents.html#create-document
  if (createResult['error'] == true) {
    print('Somewhat wrong: $createResult');
    exit(2);
  }

  var newPostKey = createResult['_key'] as String;

  // Let's update post:
  var updatedPost =
      await client.updateDocument('posts', newPostKey, {'public': true},
          // use 'returnNew' query paramener if you want to have copy of new post:
          // (see ArangoDB documentation for known more about query parameters)
          // https://www.arangodb.com/docs/3.5/http/document-working-with-documents.html#update-document
          queryParams: {"returnNew": "true"});

  // delete post:
  await client.removeDocument('posts', newPostKey);

  
  // Another, less convenient way to create query.
  // Here is an example of hardcoded query.
  // Any variants should be composed by hand.
  var titles_another_way = await client.queryToList({
    // See alse client.queryToStream().
    'query':'''
    FOR post IN posts
    FILTER post.public
    FILTER post._key=@key
    RETURN post.title
    ''',
    'bindVars':{
      'key': postKey,
    }
  });

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_arango_min: ^0.2.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_arango_min/dart_arango_min.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Apr 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/dart_arango_min.dart.

Run dartfmt to format lib/dart_arango_min.dart.

Format lib/src/dart_arango_min_base.dart.

Run dartfmt to format lib/src/dart_arango_min_base.dart.

Format lib/src/dart_arango_min_query.dart.

Run dartfmt to format lib/src/dart_arango_min_query.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0