jaguar_mongo_data_store 1.3.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 69

jaguar_mongo_data_store

Data store implementation for MongoDb

Examples

Data store

main() async {
  // Create and open a connection to mongo
  final db = new mgo.Db(kMongoUrl);
  await db.open();

  // Create a mongo store
  MongoDataStore<Post> store =
      new MongoDataStore<Post>(mongoSerializer, "posts", db);

  // Start fresh by deleting all previous documents
  await store.removeAll();

  // Insert a post and receive the ID of the inserted document
  final String post1Id =
      await store.insert(new Post.buildNoId("title1", "message1", 5));
  print(post1Id);

  // Insert another post and receive the ID of the inserted document
  final String post2Id =
      await store.insert(new Post.buildNoId("title2", "message2", 10));
  print(post2Id);

  // Get all posts in collection
  final List<Post> posts = await (await store.getAll()).toList();
  print(posts);

  // Get a post by ID
  final post1 = await store.getById(post1Id);
  print(post1);

  // Get another post by ID
  final post2 = await store.getById(post2Id);
  print(post2);

  // Update a post
  post1.likes = 25;
  await store.updateById(post1Id, post1);

  // Get a changed a post
  final post1Changed = await store.getById(post1Id);
  print(post1Changed);

  // Update a post
  await store.updateMapById(post1Id, {'likes': 55});

  // Get a changed a post
  final post1Changed2 = await store.getById(post1Id);
  print(post1Changed2);

  // Delete a post
  await store.removeById(post2Id);

  //Posts after delete
  final List<Post> postsAfterDelete = await (await store.getAll()).toList();
  print(postsAfterDelete);

  exit(0);
}

Resource

import 'dart:io';
import 'dart:async';
import 'package:jaguar_mongo_data_store/resource.dart';
import '../common/post/post.dart';
import 'package:jaguar/jaguar.dart' hide Post;
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:jaguar_data_store/client.dart';
import 'package:http/http.dart' as http;

final String kMongoUrl = "mongodb://localhost:27017/example";

@Api(path: '/api')
class ExampleApi {
  @IncludeApi(path: '/post')
  final MongoResource s =
      new MongoResource(kMongoUrl, 'posts', serializer, mongoSerializer);
}

Future<Null> server() async {
  final server = new Jaguar();
  server.addApi(reflect(new ExampleApi()));
  await server.serve();
}

const String kAuthority = 'http://localhost:8080';

Future<Null> client() async {
  final client = new http.Client();
  final ResourceClient<String, Post> rC = new ResourceClient<String, Post>(
      client, serializer,
      authority: kAuthority, path: '/api/post');

  // Start fresh by deleting all previous documents
  print(await rC.removeAll());

  // Insert a post and receive the ID of the inserted document
  final String post1Id =
      await rC.insert(new Post.buildNoId("title1", "message1", 5));
  print(post1Id);

  // Insert another post and receive the ID of the inserted document
  final String post2Id =
      await rC.insert(new Post.buildNoId("title2", "message2", 10));
  print(post2Id);

  // Get all posts in collection
  final List<Post> posts = await rC.getAll();
  print(posts);

  // Get a post by ID
  final post1 = await rC.getById(post1Id);
  print(post1);

  // Get another post by ID
  final post2 = await rC.getById(post2Id);
  print(post2);

  // Update a post
  post1.likes = 25;
  await rC.update(post1);

  // Get a changed a post
  final post1Changed = await rC.getById(post1Id);
  print(post1Changed);

  // Update a post
  await rC.update(post1);

  // Get a changed a post
  final post1Changed2 = await rC.getById(post1Id);
  print(post1Changed2);

  // Delete a post
  await rC.removeById(post2Id);

  //Posts after delete
  final List<Post> postsAfterDelete = await rC.getAll();
  print(postsAfterDelete);
}

main() async {
  await server();
  await client();
  exit(0);
}

Changelog

1.3.2

  • Added upsertById

0.2.1

  • Added updateMapById to MongoResource

0.0.1

MongoDataStore and MongoResource

example/example.dart

library example.data_store.simple;

import 'dart:io';
import 'dart:async';
import 'package:jaguar_mongo_data_store/resource.dart';
import 'common/post/post.dart';
import 'package:jaguar/jaguar.dart' hide Post;
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:jaguar_data_store/client.dart';
import 'package:http/http.dart' as http;

final String kMongoUrl = "mongodb://localhost:27017/example";

@Api(path: '/api')
class ExampleApi {
  @IncludeApi(path: '/post')
  final MongoResource s =
  new MongoResource(kMongoUrl, 'posts', serializer, mongoSerializer);
}

Future<Null> server() async {
  final server = new Jaguar(port: 10000);
  server.addApi(reflect(new ExampleApi()));
  await server.serve();
}

const String kAuthority = 'http://localhost:10000';

Future<Null> client() async {
  final client = new http.Client();
  final ResourceClient<String, Post> rC = new ResourceClient<String, Post>(
      client, serializer,
      authority: kAuthority, path: '/api/post');

  // Start fresh by deleting all previous documents
  print(await rC.removeAll());

  // Insert a post and receive the ID of the inserted document
  final String post1Id =
  await rC.insert(new Post.buildNoId("title1", "message1", 5));
  print(post1Id);

  // Insert another post and receive the ID of the inserted document
  final String post2Id =
  await rC.insert(new Post.buildNoId("title2", "message2", 10));
  print(post2Id);

  // Get all posts in collection
  final List<Post> posts = await rC.getAll();
  print(posts);

  // Get a post by ID
  final post1 = await rC.getById(post1Id);
  print(post1);

  // Get another post by ID
  final post2 = await rC.getById(post2Id);
  print(post2);

  // Update a post
  post1.likes = 25;
  await rC.update(post1);

  // Get a changed a post
  final post1Changed = await rC.getById(post1Id);
  print(post1Changed);

  // Update a post
  await rC.update(post1);

  // Get a changed a post
  final post1Changed2 = await rC.getById(post1Id);
  print(post1Changed2);

  // Delete a post
  await rC.removeById(post2Id);

  //Posts after delete
  final List<Post> postsAfterDelete = await rC.getAll();
  print(postsAfterDelete);
}

main() async {
  await server();
  await client();
  exit(0);
}

1. Depend on it

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


dependencies:
  jaguar_mongo_data_store: "^1.3.2"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_mongo_data_store/jaguar_mongo_data_store.dart';
        
Version Uploaded Documentation Archive
1.3.2 Feb 2, 2018 Go to the documentation of jaguar_mongo_data_store 1.3.2 Download jaguar_mongo_data_store 1.3.2 archive
1.3.1 Feb 2, 2018 Go to the documentation of jaguar_mongo_data_store 1.3.1 Download jaguar_mongo_data_store 1.3.1 archive
1.2.7 Jan 13, 2018 Go to the documentation of jaguar_mongo_data_store 1.2.7 Download jaguar_mongo_data_store 1.2.7 archive
1.2.6 Jan 13, 2018 Go to the documentation of jaguar_mongo_data_store 1.2.6 Download jaguar_mongo_data_store 1.2.6 archive
1.1.5 Jan 11, 2018 Go to the documentation of jaguar_mongo_data_store 1.1.5 Download jaguar_mongo_data_store 1.1.5 archive
0.2.4 Jul 12, 2017 Go to the documentation of jaguar_mongo_data_store 0.2.4 Download jaguar_mongo_data_store 0.2.4 archive
0.2.3 Jul 9, 2017 Go to the documentation of jaguar_mongo_data_store 0.2.3 Download jaguar_mongo_data_store 0.2.3 archive
0.2.2 Jun 17, 2017 Go to the documentation of jaguar_mongo_data_store 0.2.2 Download jaguar_mongo_data_store 0.2.2 archive
0.2.1 Jun 17, 2017 Go to the documentation of jaguar_mongo_data_store 0.2.1 Download jaguar_mongo_data_store 0.2.1 archive
0.2.0 Jun 7, 2017 Go to the documentation of jaguar_mongo_data_store 0.2.0 Download jaguar_mongo_data_store 0.2.0 archive

All 16 versions...

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
38 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
69

Platforms

Detected platforms: Flutter, other

Primary library: package:jaguar_mongo_data_store/jaguar_mongo_data_store.dart with components: io.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
jaguar ^1.3.4 1.3.4
jaguar_data_store ^0.5.1 0.5.2
jaguar_mongo ^1.3.1 1.3.1
jaguar_serializer ^0.5.1 0.5.1 1.0.0-dev1
mongo_dart ^0.3.0 0.3.1
Transitive dependencies
args 1.2.0 1.3.0
async 2.0.3
auth_header 0.0.3
bson 0.3.0
charcode 1.1.1
client_cookie 0.1.0
collection 1.14.5
connection_pool 0.1.2
convert 2.0.1
crypto 2.0.2+1
fixnum 0.10.6
http_parser 3.1.1
http_server 0.9.7
intl 0.15.2
jaguar_client 0.2.1
jaguar_common 0.2.2
logging 0.11.3+1
matcher 0.12.1+4
meta 1.1.2
mime 0.9.6
mongo_dart_query 0.3.0
more 1.8.1
path 1.5.1
pool 1.3.4
quiver_hashcode 1.0.0
quiver_iterables 1.0.1
source_span 1.4.0
stack_trace 1.9.1
string_scanner 1.0.2
typed_data 1.1.5
uuid 0.5.3
yaml 2.1.13
yamlicious 0.0.5
Dev dependencies
http 0.11.3+16
jaguar_reflect ^1.3.2
jaguar_serializer_mongo ^0.2.0
test