streamqflite 1.0.0 copy "streamqflite: ^1.0.0" to clipboard
streamqflite: ^1.0.0 copied to clipboard

reactive stream wrapper around sqflite inspired by sqlbrite

streamqflite #

Pub

A reactive stream wrapper around sqflite inspired by sqlbrite.

Getting Started #

In your flutter project, add the dependency to your pubspec.yaml

dependencies:
  ...
  streamqflite: 0.2.0

Usage #

Import streamqflite.dart

import 'package:streamqflite/streamqflite.dart';

Wrap your database in a StreamDatabase.

var streamDb = StreamDatabase(db);

You can then listen to a query

// Emits a single row, doesn't emit if the row dosen't exist.
Stream<MyEntry> singleQuery = streamDb.createQuery("MyTable", where: 'id = ?', whereArgs: [id])
    .mapToOne((row) => MyEntry(row));

// Emits a single row, or the given default value if the row doesn't exist.
Stream<MyEntry> singleOrDefaultQuery = streamDb.createQuery("MyTable", where: 'id = ?', whereArgs: [id])
    .mapToOneOrDefault((row) => MyEntry(row), MyEntry.empty());

// Emits a list of rows.
Stream<List<MyEntry>> listQuery = streamDb.createQuery("MyTable", where: 'name LIKE ?', whereArgs: [query])
    .mapToList((row) => MyEntry(row));

var flexibleQuery = streamDb.createQuery("MyTable", where: 'name LIKE ?', whereArgs: [query])
    .asyncMap((query) => {
        // query is lazy, this lets you not even execute it if you don't need to.
        if (condition) {
            return query();
        } else {
            return Stream.empty();
        }
    }).map((rows) {
        // Do something with all the rows.
        return ...;
    });

These queries will run once to get the current data, then again whenever the given table is modified though the StreamDatabase.

2
likes
20
pub points
25%
popularity

Publisher

unverified uploader

reactive stream wrapper around sqflite inspired by sqlbrite

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, sqflite

More

Packages that depend on streamqflite