syncbase 0.0.42

  • Example
  • Installing
  • Versions
  • 0


This project exposes Syncbase as a Mojo service.

Read the architecture proposal.

Initial Mojo setup

You must have the Mojo repo in $MOJO_DIR.

This section only needs to be run once.

See the Mojo readme for more comprehensive instructions.

Install Mojo prereqs

  1. Install depot tools.

  2. Install Goma.

  3. Put the following in your .bashrc:

     # NOTE: Actual locations depend on where you installed depot_tools and
     # goma.
     export PATH=${PATH}:${HOME}/dev/depot_tools
     export GOMA_DIR=${HOME}/goma
     export MOJO_DIR=${HOME}/mojo

Download Mojo repo

$ mkdir $MOJO_DIR && cd $MOJO_DIR

# NOTE: This step takes about 10 min.
$ fetch mojo --target_os=android,linux

# NOTE: This step also takes about 10 min.  Furthermore, the script uses
# 'sudo', so you will need to enter your password.
$ cd src && ./build/

# Or, to include Android deps as well:
$ cd src && ./build/

Update Mojo and compile resources

This updates the Mojo repo to HEAD, and builds the Mojo resources needed to compile Syncbase.

Run this while you grab your morning coffee.

  1. Start by updating the repo.

     $ cd $MOJO_DIR/src
     $ git checkout master
     $ git pull
     $ gclient sync
  2. Compile for Linux. Built resources will be in $MOJO_DIR/src/out/Debug

     $ ./mojo/tools/ gn
     $ ./mojo/tools/ build # NOTE: This can take up to 10 minutes.
  3. Compile for Android. Built resources will be in $MOJO_DIR/src/out/android_Debug

     $ ./mojo/tools/ gn --android
     $ ./mojo/tools/ build --android # NOTE: This can take up to 10 minutes.

Install Dart SDK

To run Dart apps, you must install the Dart SDK.

Googlers: http://go/install-dart External:


Run the tests:

make test

This will run all tests listed in the tests file in the root directory of this repo.

The following command will run a single test file. This is useful when the full test suite hangs with no output.

$(MOJO_DIR)/src/mojo/devtools/common/mojo_run -v --enable-multiprocess --shell-path $(MOJO_DIR)/src/out/Debug/mojo_shell test/integration/<filename>


#!mojo mojo:dart_content_handler
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:math' show Random;
import 'dart:convert' show UTF8;

import 'package:syncbase/initialized_application.dart'
    show InitializedApplication;
import 'package:syncbase/src/naming/util.dart' as naming;
import 'package:syncbase/syncbase_client.dart' as sb;

main(List args, Object handleToken) async {
  // mojo_shell does not print a stack trace when the dart program crashes.
  // Hence, we must wrap everything in a try/catch if we want to see the
  // errors. :(
  try {
    InitializedApplication app = new InitializedApplication.fromHandle(handleToken);
    await app.initialized;

    const String mtAddr = '/';

    sb.SyncbaseClient c = new sb.SyncbaseClient(
        app.connectToService, '');

    sb.SyncbaseApp sbApp = await createApp(c, 'testapp');
    sb.SyncbaseDatabase sbDb = await createDb(sbApp, 'testdb');
    sb.SyncbaseTable sbTable = await createTable(sbDb, 'testtable');
    await joinOrCreateSyncgroup(sbDb, mtAddr,, 'testsg');

    startWatch(sbDb, sbTable);

    // Wait forever.
    await new Completer().future;

    // Looks like forever came and went.  Might as well clean up after
    // ourselves...
    await c.close();
    await app.close();
  } catch (e) {
    print('ERROR in main()');

startWatch(db, table) async {
  try {
    var s =, '', await db.getResumeMarker());
    await for (var change in s) {
          'GOT CHANGE: ${change.rowKey} - ${UTF8.decode(change.valueBytes)} - ${change.fromSync}');
  } catch (e) {
    print('ERROR in startWatch()');

var r = new Random();

startPuts(table) async {
  try {
    var key = r.nextInt(100000000);
    var val = r.nextInt(100000000);

    var row = table.row('k$key');
    print('PUTTING k$key');
    await row.put(UTF8.encode('$val'));
  } catch (e) {
    print('ERROR in startPuts()');

  await new Future.delayed(new Duration(seconds: 2));

String openPermsJson =
sb.Perms openPerms = sb.SyncbaseClient.perms(openPermsJson);

Future<sb.SyncbaseApp> createApp(sb.SyncbaseClient c, String name) async {
  var app =;
  var exists = await app.exists();
  if (exists) {
    print('app exists, rolling with it');
    return app;
  print('app does not exist, creating it');
  await app.create(openPerms);
  return app;

Future<sb.SyncbaseDatabase> createDb(sb.SyncbaseApp app, String name) async {
  var db = app.noSqlDatabase(name);
  var exists = await db.exists();
  if (exists) {
    print('db exists, rolling with it');
    return db;
  print('db does not exist, creating it');
  await db.create(openPerms);
  return db;

Future<sb.SyncbaseTable> createTable(
    sb.SyncbaseDatabase db, String name) async {
  var table = db.table(name);
  var exists = await table.exists();
  if (exists) {
    print('table exists, rolling with it');
    return table;
  print('table does not exist, creating it');
  await table.create(openPerms);
  return table;

Future<sb.SyncbaseSyncgroup> joinOrCreateSyncgroup(sb.SyncbaseDatabase db,
    String mtAddr, String tableName, String name) async {
  var mtName = naming.join(
      mtAddr, 'users/');
  // TODO(nlacasse): Make this %%sync thing a constant.
  var sgPrefix = naming.join(mtName, 'syncbase_mojo/%%sync');
  var sgName = naming.join(sgPrefix, 'testsg');
  var sg = db.syncgroup(sgName);

  print('SGNAME = $sgName');

  var myInfo = sb.SyncbaseClient.syncgroupMemberInfo(syncPriority: 3);

  try {
    print('trying to join syncgroup');
    await sg.join(myInfo);
    print('syncgroup join success');
  } catch (e) {
    // Syncgroup does not exist.
    print('syncgroup does not exist, creating it');

    List<sb.TableRow> prefixes = [];
    prefixes.add(sb.SyncbaseClient.syncgroupPrefix('$tableName', ''));

    var sgSpec = sb.SyncbaseClient.syncgroupSpec(prefixes,
        description: 'test syncgroup',
        perms: openPerms,
        // Sync the entire table.
        mountTables: [mtName]);

    print('SGSPEC = $sgSpec');

    try {
      await sg.create(sgSpec, myInfo);
    } catch (e) {
      print('ERROR creating syncgroup');

  return sg;

Use this package as a library

1. Depend on it

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

  syncbase: ^0.0.42

2. Install it

You can install packages from the command line:

with pub:

$ pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:syncbase/initialized_application.dart';
import 'package:syncbase/syncbase_client.dart';
Version Uploaded Documentation Archive
0.0.42 May 12, 2016 Go to the documentation of syncbase 0.0.42 Download syncbase 0.0.42 archive
0.0.41 May 10, 2016 Go to the documentation of syncbase 0.0.41 Download syncbase 0.0.41 archive
0.0.40 Apr 27, 2016 Go to the documentation of syncbase 0.0.40 Download syncbase 0.0.40 archive
0.0.39 Apr 27, 2016 Go to the documentation of syncbase 0.0.39 Download syncbase 0.0.39 archive
0.0.38 Apr 20, 2016 Go to the documentation of syncbase 0.0.38 Download syncbase 0.0.38 archive
0.0.37 Apr 6, 2016 Go to the documentation of syncbase 0.0.37 Download syncbase 0.0.37 archive
0.0.36 Apr 4, 2016 Go to the documentation of syncbase 0.0.36 Download syncbase 0.0.36 archive
0.0.35 Mar 31, 2016 Go to the documentation of syncbase 0.0.35 Download syncbase 0.0.35 archive
0.0.34 Mar 23, 2016 Go to the documentation of syncbase 0.0.34 Download syncbase 0.0.34 archive
0.0.33 Mar 21, 2016 Go to the documentation of syncbase 0.0.33 Download syncbase 0.0.33 archive

All 42 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see

Maintenance issues and suggestions

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.12.0 <2.0.0