jaguar_query_sqflite 2.2.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 83

jaguar_query_sqflite

sqflite adapter for jaguar_query and jaguar_orm.

Usage

A simple usage example:

import 'dart:io';
import 'dart:async';
import 'package:sqflite/sqflite.dart';
import 'package:jaguar_query_sqflite/jaguar_query_sqflite.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
SqfliteAdapter _adapter;

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

  Future<Null> createTable() async {
    final st = new Create()
        .named(tableName)
        .ifNotExists()
        .addNullInt('_id', primary: true)
        .addNullStr('msg')
        .addNullStr('author');

    await _adapter.createTable(st);
  }

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

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

    return await _adapter.insert(inserter);
  }

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

    updater.set(this.author, author);

    return await _adapter.update(updater);
  }

  /// Finds one post by [id]
  Future<Post> findOne(int id) async {
    Find updater = new Find()..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 {
    Find finder = new Find()..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<int> remove(int id) async {
    Remove deleter = new Remove()..from(tableName);

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

    return await _adapter.remove(deleter);
  }

  /// Deletes all posts
  Future<int> removeAll() async {
    Remove deleter = new Remove()..from(tableName);

    return await _adapter.remove(deleter);
  }
}

main() async {
  _adapter = new SqfliteAdapter(await getDatabasesPath());

  // Connect
  await _adapter.connect();

  final bean = new PostBean();

  await bean.createTable();

  // Delete all
  await bean.removeAll();

  // 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.remove(1);
  await bean.remove(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();

  exit(0);
}

For more usage don't hesitate to check this example https://github.com/jaguar-orm/sqflite

Changelog

2.2.1

  • Fixed SQL string escape

2.1.10

  • Removed NoRecordFound exception

2.1.9

  • find now returns List

2.1.8

  • Remove 'AUTOINCREMENT'

2.1.7

  • Autoincrement fix

2.1.6

  • Proper number parsing

2.1.5

  • parseValue double parsing

2.1.4

  • Added parseValue to parse values from Database

2.1.2

  • sqlite-ify create statement

2.1.1

  • Architecture

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_query_sqflite: ^2.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter 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_sqflite/jaguar_query_sqflite.dart';
  
Version Uploaded Documentation Archive
2.2.1 Sep 11, 2018 Go to the documentation of jaguar_query_sqflite 2.2.1 Download jaguar_query_sqflite 2.2.1 archive
2.2.0 Sep 5, 2018 Go to the documentation of jaguar_query_sqflite 2.2.0 Download jaguar_query_sqflite 2.2.0 archive
2.1.10 Jul 17, 2018 Go to the documentation of jaguar_query_sqflite 2.1.10 Download jaguar_query_sqflite 2.1.10 archive
2.1.9 Jul 17, 2018 Go to the documentation of jaguar_query_sqflite 2.1.9 Download jaguar_query_sqflite 2.1.9 archive
2.1.7 Jul 6, 2018 Go to the documentation of jaguar_query_sqflite 2.1.7 Download jaguar_query_sqflite 2.1.7 archive
2.1.6 Jul 5, 2018 Go to the documentation of jaguar_query_sqflite 2.1.6 Download jaguar_query_sqflite 2.1.6 archive
2.1.5 Jul 5, 2018 Go to the documentation of jaguar_query_sqflite 2.1.5 Download jaguar_query_sqflite 2.1.5 archive
2.1.4 Jul 5, 2018 Go to the documentation of jaguar_query_sqflite 2.1.4 Download jaguar_query_sqflite 2.1.4 archive
2.1.2 Jul 5, 2018 Go to the documentation of jaguar_query_sqflite 2.1.2 Download jaguar_query_sqflite 2.1.2 archive
2.1.1 Jul 5, 2018 Go to the documentation of jaguar_query_sqflite 2.1.1 Download jaguar_query_sqflite 2.1.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3
  • Flutter: 0.8.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use jaguar_query_sqflite.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.65.0 <3.0.0
flutter 0.0.0
jaguar_query ^2.2.0 2.2.2
sqflite ^0.11.2 0.11.2+4 0.12.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
synchronized 1.5.2
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test