couchdb 0.2.1 copy "couchdb: ^0.2.1" to clipboard
couchdb: ^0.2.1 copied to clipboard

outdated

Library for interacting with CouchDB from both a server and browser environment

example/README.md

Server #

import 'package:couchdb/couchdb.dart';
import 'package:couchdb/couchdb_server_client.dart';

Future<void> main() async {
  final client = CouchDbServerClient(username: 'name', password: 'password');
  final dbModel = DatabaseModel(client);
  final docModel = DocumentModel(client)

  try {
    final DbResponse commonResponse = await dbModel.allDocs('some_db');
    final DatabaseModelResponse response1 = commonResponse.databaseModelResponse();

    for (var i in response1.rows) {
      // Some code here
    }

    final DbResponse response2 = await docModel.doc('another_db', 'some_id');

    var thing = response2.json['some_attribute'];

  } on CouchDbException catch (e) {
    print('$e - error');
  }
}

Browser #

import 'dart:html';

import 'package:couchdb/couchdb.dart';
import 'package:couchdb/couchdb_web_client.dart';

Future<void> main(List<String> args) async {
  final ButtonElement btn = querySelector('#data');
  final DivElement output = querySelector('#output');

  final c = CouchDbWebClient(username: 'name', password: 'pass', cors: true);
  final dm = DocumentModel(c);

  btn.onClick.listen((event) async {
  try {
    final DbResponse commonResponse = await dbModel.doc('some_db', 'some_doc_id');
    final DocumentModelResponse response1 = commonResponse.documentModelResponse();

    final Map<String, Object> doc = response1.doc;

    // Some code here

    // There properties are extracted from [doc] in order to gets direct access
    final String id = response1.id;
    final String rev = response1.rev;
    final Object attachment = response1.attachment;

    // Another code here

  } on CouchDbException catch (e) {
      window.console.log('${e.code} - error');
    }
  });
}
20
likes
0
pub points
11%
popularity

Publisher

unverified uploader

Library for interacting with CouchDB from both a server and browser environment

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, meta

More

Packages that depend on couchdb