Skip to main content

opendbs 1.0.1 copy "opendbs: ^1.0.1" to clipboard
opendbs: ^1.0.1 copied to clipboard

Official Dart and Flutter client for OpenDBS, a document and SQL database server. Documents, SQL, aggregation, transactions and cluster failover.

example/main.dart

import 'package:opendbs/opendbs.dart';

/// Run against a local server:
///   dart run example/main.dart http://localhost:4402 <API key>
Future<void> main(List<String> args) async {
  final client = OpenDBS(
    args.isNotEmpty ? args[0] : 'http://localhost:4402',
    apiKey: args.length > 1 ? args[1] : null,
  );

  try {
    await client.createDatabase('demo');
  } on OpenDBSException catch (e) {
    print('createDatabase: ${e.message}'); // e.g. it already exists
  }
  final db = client.database('demo');

  try {
    await db.createTable('books', {
      'title': {'type': 'string', 'required': true},
      'year': {'type': 'integer'},
    });
  } on OpenDBSException catch (_) {}

  final books = db.table('books');
  await books.insertMany([
    {'title': 'Dune', 'year': 1965},
    {'title': 'Neuromancer', 'year': 1984},
    {'title': 'Hyperion', 'year': 1989},
  ]);

  final page = await books.find({
    'year': {r'$gte': 1980},
  }, sort: 'year', order: 'desc');
  print('${page.total} books since 1980:');
  for (final b in page.results) {
    print('  ${b['title']} (${b['year']})');
  }

  final res =
      await db.sql('SELECT COUNT(*) AS n FROM books WHERE year < ?', [1970]);
  print('Before 1970: ${res['result'][0]['n']}');

  await client.dropDatabase('demo');
  client.close();
}
0
likes
160
points
38
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Official Dart and Flutter client for OpenDBS, a document and SQL database server. Documents, SQL, aggregation, transactions and cluster failover.

Homepage
Repository (GitHub)
View/report issues

Topics

#database #sql #nosql #client

License

MIT (license)

Dependencies

http

More

Packages that depend on opendbs