jaguar_data_store 2.2.0

jaguar_data_store #

A data store is a DB agnostic abstraction of CURD for a specific model/document/table.

This library defines the abstract interfaces that must be implemented by the DB specific adapters.

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 client #

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 #

2.1.1 #

  • Jaguar 2.1.x

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_data_store: ^2.2.0

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:jaguar_data_store/jaguar_data_store.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
10
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
73
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:jaguar_data_store/jaguar_data_store.dart.

Health suggestions

Fix lib/src/client.dart. (-0.50 points)

Analysis of lib/src/client.dart reported 1 hint:

line 26 col 38: Use ; instead of {} for empty constructor bodies.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and jaguar_data_store.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Package is getting outdated. (-1.64 points)

The package was last published 53 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http ^0.11.3 0.11.3+17 0.12.0+2
jaguar_client ^2.2.1 2.4.2
jaguar_common ^2.1.1 2.1.4
jaguar_serializer ^2.2.0 2.2.12
Transitive dependencies
async 2.3.0
auth_header 2.1.4
charcode 1.1.2
client_cookie 2.1.5 2.2.1
collection 1.14.12
http_parser 3.1.3
jaguar_resty 2.8.9 2.10.14
meta 1.1.7
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6