Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evant/streamqflite
flutter reactive stream wrapper around sqflite inspired by sqlbrite
https://github.com/evant/streamqflite
Last synced: about 1 month ago
JSON representation
flutter reactive stream wrapper around sqflite inspired by sqlbrite
- Host: GitHub
- URL: https://github.com/evant/streamqflite
- Owner: evant
- License: mit
- Created: 2018-06-30T22:05:42.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2020-06-14T22:52:18.000Z (over 4 years ago)
- Last Synced: 2023-08-20T23:17:47.477Z (over 1 year ago)
- Language: Dart
- Homepage:
- Size: 19.5 KB
- Stars: 40
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# streamqflite
[![Pub](https://img.shields.io/pub/v/streamqflite.svg)]()
A reactive stream wrapper around [sqflite](https://github.com/tekartik/sqflite) inspired by
[sqlbrite](https://github.com/square/sqlbrite).## Getting Started
In your flutter project, add the dependency to your `pubspec.yaml`
```yaml
dependencies:
...
streamqflite: ^1.0.0
```## Usage
Import `streamqflite.dart`
```dart
import 'package:streamqflite/streamqflite.dart';
```Wrap your database in a `StreamDatabase`.
```dart
var streamDb = StreamDatabase(db);
```You can then listen to a query
```dart
// Emits a single row, doesn't emit if the row dosen't exist.
Stream 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 singleOrDefaultQuery = streamDb.createQuery("MyTable", where: 'id = ?', whereArgs: [id])
.mapToOneOrDefault((row) => MyEntry(row), MyEntry.empty());// Emits a list of rows.
Stream> 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`.