sqlcool 1.2.0

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

Sqlcool #

A database helper library for Sqflite. Forget about implementation details and focus on the business logic. Features:

  • Simple api for crud operations
  • Changefeed: a stream to monitor database changes
  • Select bloc: a ready to use bloc for select operations

Check the documentation for usage instructions


   dependencies:
     sqlcool: ^1.1.2

Simple crud #

   import 'package:sqlcool/sqlcool.dart';

   void someFunc() async {
      String dbpath = "db.sqlite"; // relative to the documents directory
      await db.init(path: dbpath, fromAsset: "assets/db.sqlite", verbose: true).catchError((e) {
          print("Error initializing the database: ${e.message}");
      });
      // insert
      Map<String, String> row = {
       slug: "my-item",
       name: "My item",
      };
      db.insert(table: "category", row: row, verbose: true).catchError((e) {
          print("Error inserting data: ${e.message}");
      });
      // select
      List<Map<String, dynamic>> rows = await db.select(
        table: "product", limit: 20, columns: "id,name",
        where: "name LIKE '%something%'",
        orderBy: "name ASC").catchError((e) {
          print("Error selecting data: ${e.message}");
      });
      //update
      Map<String, String> row = {
       slug: "my-item-new",
       name: "My item new",
      };
      int updated = await db.update(table: "category", 
          row: row, where: "id=1", verbose: true).catchError((e) {
             print("Error updating data: ${e.message}");
      });
      // delete
      db.delete(table: "category", where: "id=3").catchError((e) {
          print("Error deleting data: ${e.message}");
      });
   }

Changefeed #

A stream of database change events is available

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

   StreamSubscription _changefeed;

   _changefeed = db.changefeed.listen((change) {
      print("CHANGE IN THE DATABASE:");
      print("Change type: ${change.changeType}");
      print("Number of items impacted: ${change.value}");
      print("Query: ${change.query}");
    });

   // _changefeed.cancel();

Reactive select bloc #

The bloc will rebuild itself on any database change because of the reactive parameter set to true:

   import 'package:flutter/material.dart';
   import 'package:sqlcool/sqlcool.dart';

   class _PageSelectBlocState extends State<PageSelectBloc> {
     SelectBloc bloc;

     @override
     void initState() {
       super.initState();
       this.bloc = SelectBloc(
           table: "items", orderBy: "name", reactive: true, verbose: true);
     }

     @override
     Widget build(BuildContext context) {
       return Scaffold(
         appBar: AppBar(
           title: Text("My app"),
         ),
         body: StreamBuilder<List<Map>>(
             stream: bloc.items,
             builder: (BuildContext context, AsyncSnapshot snapshot) {
               if (snapshot.hasData) {
                 // the select query has not found anything
                 if (snapshot.data.length == 0) {
                   return Center(
                     child: Text(
                         "No data"),
                   );
                 }
                 // the select query has results
                 return ListView.builder(
                     itemCount: snapshot.data.length,
                     itemBuilder: (BuildContext context, int index) {
                       var item = snapshot.data[index];
                       return ListTile(
                         title: GestureDetector(
                           child: Text(item["name"]),
                           onTap: () => print("Action"),
                         ),
                       );
                     });
               } else {
                 // the select query is still running
                 return CircularProgressIndicator();
               }
             }),
       );
     }
   }

   class PageSelectBloc extends StatefulWidget {
     @override
     _PageSelectBlocState createState() => _PageSelectBlocState();
   }

Todo #

  • [ ] Upsert
  • [ ] Batch operations

Changelog #

1.2.0 #

  • Downgrade to path_provider 0.4.1

  • Add mutexes for write operations

  • Add the query to the changefeed info

  • Fix return values for update and delete

  • Fix bloc select verbose param

  • Fix verbosity for update and insert queries

  • Improve the example

  • Improve the doc and readme

1.1.2 #

Fix: close _changeFeedController sink

1.1.1 #

Minor fixes

1.1.0 #

Add changefeed and reactive select bloc

1.0.0 #

Initial release

example/README.md

example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  sqlcool: ^1.2.0

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:sqlcool/sqlcool.dart';
  
Version Uploaded Documentation Archive
1.2.0 Feb 16, 2019 Go to the documentation of sqlcool 1.2.0 Download sqlcool 1.2.0 archive
1.1.2 Feb 9, 2019 Go to the documentation of sqlcool 1.1.2 Download sqlcool 1.1.2 archive
1.1.1 Feb 9, 2019 Go to the documentation of sqlcool 1.1.1 Download sqlcool 1.1.1 archive
1.1.0 Feb 9, 2019 Go to the documentation of sqlcool 1.1.0 Download sqlcool 1.1.0 archive
1.0.0+1 Jan 30, 2019 Go to the documentation of sqlcool 1.0.0+1 Download sqlcool 1.0.0+1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.13+1
  • Flutter: 1.2.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
cupertino_icons ^0.1.2 0.1.2
flutter 0.0.0
path_provider ^0.4.1 0.4.1 0.5.0+1
sqflite ^1.0.0 1.1.0 1.1.0+1
synchronized ^1.5.3 1.5.3+2 2.0.2+1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
path 1.6.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test