jaguar_query_postgresql_data_store 0.2.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 50

jaguar_query_postgresql_data_store

Data store implementation for PostgreSQL

Examples

Data store

final String postgreUrl = 'postgres://postgres:dart_jaguar@localhost/example';

main() async {
  // Create and open a connection to mongo
  final adapter = new PgAdapter(postgreUrl);
  await adapter.connect();

  final st = new Create()
      .named('posts')
      .ifNotExists()
      .addInt('_id', primary: true, autoIncrement: true)
      .addStr('title')
      .addStr('message')
      .addInt('likes');

  await adapter.createTable(st);

  // Create a mongo store
  final store = new QueryDataStore<String, Post, pg.Connection>(
      serializer, "posts", adapter, () => new Ulid().toUuid(),
      idKey: 'id');

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

  // 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);

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

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

  exit(0);
}

Resource

final String postgreUrl = 'postgres://postgres:dart_jaguar@localhost/example';

Future<Null> createDb() async {
  PgAdapter adapter = new PgAdapter(postgreUrl);
  await adapter.connect();

  {
    final Drop st = Sql.drop('posts');
    await adapter.dropTable(st);
  }

  {
    final Create st = Sql
        .create('posts')
        .addStr('id', primary: true, length: 50)
        .addStr('title', length: 100)
        .addStr('message', length: 1000)
        .addInt('likes');
    await adapter.createTable(st);
  }
}

@Api(path: '/api')
class ExampleApi {
  @IncludeApi(path: '/post')
  final PostgreResource s = new PostgreResource<String, Post>(
      postgreUrl, 'posts', serializer, serializer, () => new Ulid().toUuid(),
      idKey: 'id');
}

Future<Null> server() async {
  //TODO await createDb();
  Jaguar server = new Jaguar();
  server.addApiReflected(new ExampleApi());
  await server.serve();
}

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

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

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

  // 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);

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

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

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

Changelog

0.1.0

0.0.1

  • Initial version, created by Stagehand

1. Depend on it

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


dependencies:
  jaguar_query_postgresql_data_store: "^0.2.1"

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:jaguar_query_postgresql_data_store/jaguar_query_postgresql_data_store.dart';
        
Version Uploaded Documentation Archive
0.2.1 Jul 12, 2017 Go to the documentation of jaguar_query_postgresql_data_store 0.2.1 Download jaguar_query_postgresql_data_store 0.2.1 archive
0.2.0 Jul 12, 2017 Go to the documentation of jaguar_query_postgresql_data_store 0.2.0 Download jaguar_query_postgresql_data_store 0.2.0 archive
0.1.0 Jul 10, 2017 Go to the documentation of jaguar_query_postgresql_data_store 0.1.0 Download jaguar_query_postgresql_data_store 0.1.0 archive

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]
0 / 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]
50

Platforms

Detected platforms: other

Primary library: package:jaguar_query_postgresql_data_store/jaguar_query_postgresql_data_store.dart with components: io, mirrors.

Suggestions

  • Fix analysis_options.yaml.

    We were unable to parse analysis_options.yaml.

  • 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.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use jaguar_query_postgresql_data_store.dart.

  • Enable strong mode analysis.

    Strong mode helps you to detect bugs and potential issues earlier.Start your analysis_options.yaml file with the following:

    analyzer:
      strong-mode: true
    

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
jaguar ^0.6.5 0.6.11 1.3.4
jaguar_data_store ^0.1.0 0.1.0 0.5.2
jaguar_json ^0.1.2 0.1.3 1.3.1
jaguar_postgresql ^0.5.2 0.5.2
jaguar_query ^0.2.1 0.2.8
jaguar_query_data_store ^0.2.0 0.2.1
jaguar_query_postgresql ^0.2.1 0.2.5
jaguar_serializer ^0.3.10 0.3.16 0.5.1
postgresql ^0.3.4+1 0.3.4+1
Transitive dependencies
analyzer 0.30.0+4 0.31.0+1
args 0.13.7 1.3.0
async 1.13.3 2.0.3
barback 0.15.2+14
build 0.9.3 0.12.0+1
build_barback 0.3.0 0.5.0+3
build_runner 0.3.4+1 0.7.9
charcode 1.1.1
cli_util 0.1.2+1
code_transformers 0.5.1+4
collection 1.14.5
connection_pool 0.1.2
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
dart_style 1.0.9+1
dice 1.7.0
front_end 0.1.0-alpha.4.1 0.1.0-alpha.8
glob 1.1.5
html 0.13.2+2
http_parser 3.1.1
http_server 0.9.7
intl 0.14.0 0.15.2
isolate 1.1.0
jaguar_generator_config 0.0.1
kernel 0.3.0-alpha.1.1 0.3.0-alpha.5
logging 0.11.3+1
meta 1.1.2
mime 0.9.6
mustache 0.2.5+1 1.0.0
package_config 1.0.3
path 1.5.1
plugin 0.2.0+2
pool 1.3.4
quiver_hashcode 1.0.0
quiver_iterables 1.0.1
shelf 0.6.8 0.7.2
shelf_static 0.2.7
source_gen 0.5.10+1 0.7.4+3
source_gen_help 0.0.4
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.1
stream_channel 1.6.3
stream_transform 0.0.10
string_scanner 1.0.2
teja_http_json 0.1.5 0.1.6-dev
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+7
yaml 2.1.13
yamlicious 0.0.5
Dev dependencies
http ^0.11.3+13 0.11.3+16
test
ulid ^1.0.0