jaguar_query_postgresql 0.2.5

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

jaguar_query_postgresql

postgresql adapter for jaguar_orm

Usage

A simple usage example:

import 'dart:async';
import 'package:jaguar_orm_postgresql/jaguar_orm_postgresql.dart';

// The model
class Post {
  Post();

  Post.make(this.id, this.msg, this.author);

  int id;

  String msg;

  String author;

  String toString() => '$id $msg $author';
}

/// The adapter
PgAdapter _adapter =
    new PgAdapter('postgres://postgres:dart_jaguar@localhost/postgres');

/// The bean
class PostBean {
  /// Field DSL for id column
  final IntField id = new IntField('_id');

  /// Field DSL for msg column
  final StrField msg = new StrField('msg');

  /// Field DSL for author column
  final StrField author = new StrField('author');

  /// Table name for the model this bean manages
  String get tableName => 'posts';

  /// Inserts a new post into table
  Future insert(Post post) async {
    InsertStatement inserter = new InsertStatement()..into(tableName);

    inserter.set(id.set(post.id));
    inserter.set(msg.set(post.msg));
    inserter.set(author.set(post.author));

    await _adapter.insert(inserter);
  }

  /// Updates a post
  Future update(int id, String author) async {
    UpdateStatement updater = new UpdateStatement()..into(tableName);
    updater.where(this.id.eq(id));

    updater.set(this.author.set(author));

    await _adapter.update(updater);
  }

  /// Finds one post by [id]
  Future<Post> findOne(int id) async {
    FindStatement updater = new FindStatement()..from(tableName);

    updater.where(this.id.eq(id));

    Map map = await _adapter.findOne(updater);

    Post post = new Post();
    post.id = map['_id'];
    post.msg = map['msg'];
    post.author = map['author'];

    return post;
  }

  /// Finds all posts
  Future<List<Post>> findAll() async {
    FindStatement finder = new FindStatement()..from(tableName);

    List<Map> maps = await (await _adapter.find(finder)).toList();

    List<Post> posts = new List<Post>();

    for(Map map in maps) {
      Post post = new Post();

      post.id = map['_id'];
      post.msg = map['msg'];
      post.author = map['author'];

      posts.add(post);
    }

    return posts;
  }

  /// Deletes a post by [id]
  Future delete(int id) async {
    DeleteStatement deleter = new DeleteStatement()..from(tableName);

    deleter.where(this.id.eq(id));

    await _adapter.delete(deleter);
  }

  /// Deletes all posts
  Future deleteAll() async {
    DeleteStatement deleter = new DeleteStatement()..from(tableName);

    await _adapter.delete(deleter);
  }
}

main() async {
  // Connect
  await _adapter.connect();

  PostBean bean = new PostBean();

  // Delete all
  await bean.deleteAll();

  // Insert some posts
  await bean.insert(new Post.make(1, 'Whatever 1', 'mark'));
  await bean.insert(new Post.make(2, 'Whatever 2', 'bob'));

  // Find one post
  Post post = await bean.findOne(1);
  print(post);

  // Find all posts
  List<Post> posts = await bean.findAll();
  print(posts);

  // Update a post
  await bean.update(1, 'rowling');

  // Check that the post is updated
  post = await bean.findOne(1);
  print(post);

  // Delete some posts
  await bean.delete(1);
  await bean.delete(2);

  // Find a post when none exists
  try {
    post = await bean.findOne(1);
    print(post);
  } on JaguarOrmException catch(e) {
    print(e);
  }

  // Close connection
  await _adapter.close();
}

Changelog

0.2.5

  • Composite foreign keys

0.2.4

  • dropDb implementation

0.2.2

  • Where clauses can be any Expression

0.2.0

  • Upgraded to jaguar_query 0.2.x

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: "^0.2.5"

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_query_postgresql/jaguar_query_postgresql.dart';
        
Version Uploaded Documentation Archive
0.2.5 Sep 24, 2017 Go to the documentation of jaguar_query_postgresql 0.2.5 Download jaguar_query_postgresql 0.2.5 archive
0.2.4 Jul 29, 2017 Go to the documentation of jaguar_query_postgresql 0.2.4 Download jaguar_query_postgresql 0.2.4 archive
0.2.2 Jul 28, 2017 Go to the documentation of jaguar_query_postgresql 0.2.2 Download jaguar_query_postgresql 0.2.2 archive
0.2.1 Jul 12, 2017 Go to the documentation of jaguar_query_postgresql 0.2.1 Download jaguar_query_postgresql 0.2.1 archive
0.2.0 Jul 12, 2017 Go to the documentation of jaguar_query_postgresql 0.2.0 Download jaguar_query_postgresql 0.2.0 archive
0.1.4 Jul 12, 2017 Go to the documentation of jaguar_query_postgresql 0.1.4 Download jaguar_query_postgresql 0.1.4 archive
0.1.2 Jul 10, 2017 Go to the documentation of jaguar_query_postgresql 0.1.2 Download jaguar_query_postgresql 0.1.2 archive
0.1.1 Jul 10, 2017 Go to the documentation of jaguar_query_postgresql 0.1.1 Download jaguar_query_postgresql 0.1.1 archive
0.1.0 Jul 5, 2017 Go to the documentation of jaguar_query_postgresql 0.1.0 Download jaguar_query_postgresql 0.1.0 archive
0.0.4 Jun 6, 2017 Go to the documentation of jaguar_query_postgresql 0.0.4 Download jaguar_query_postgresql 0.0.4 archive

All 13 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]
0 / 100
Health:
Code health derived from static analysis. [more]
99 / 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: Flutter, other

Primary library: package:jaguar_query_postgresql/jaguar_query_postgresql.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.

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

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
jaguar_query ^0.2.4 0.2.8
logging >=0.9.2 <0.12.0 0.11.3+1
postgresql >=0.3.0+2 <0.4.0 0.3.4+1
Transitive dependencies
charcode 1.1.1
collection 1.14.5
convert 2.0.1
crypto 2.0.2+1
meta 1.1.2
typed_data 1.1.5
Dev dependencies
test >=0.12.0 <0.13.0