Sqlbrite

🌼 RxDart Reactive stream sqflite(sqlite) for Flutter - Sqlbrite for flutter - A lightweight wrapper around sqflite which introduces reactive stream semantics to SQL operations. https://pub.dev/packages/sqlbrite
Alternatives To Sqlbrite
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Flutter_client_php_backend125
3 years agoapache-2.0Dart
Sample app demonstrating usage of Flutter Framework to Create Android & IOS App Using Rest API Created In PHP
Contacts116
8 months agoapache-2.0Dart
A flutter project with Implementation of a Contacts app in 4 ways (API, Custom, Preferences and Sqflite).
Devwidgets87
3 months ago4mitDart
DevWidgets is a Flutter application with several tools such as generators, formatters and converters for developers. It's directly inspired by DevToys.
Tinano61
14 years ago3March 09, 2019otherDart
A typesafe sqlite persistence library for flutter
Sqlbrite23
2 months ago10September 22, 20217mitDart
🌼 RxDart Reactive stream sqflite(sqlite) for Flutter - Sqlbrite for flutter - A lightweight wrapper around sqflite which introduces reactive stream semantics to SQL operations. https://pub.dev/packages/sqlbrite
Flutter_orm_demo23
3 years ago6Dart
demo of flutter_orm_plugin
Flutter_video_player20
11 days agoDart
一款完整的视频播放APP,仿抖音页面,横竖屏播放,切换视频,瀑布流页面,筛选功能等,更多等你去发现
Easiestdbflutter16
3 years ago11July 16, 2020n,ullmitDart
The Easiest and the Laziest approach to Flutter SQL Database.
Allsql13
2 years ago10mitDart
AllSQL is an open-source compact browser based SQL Compiler, built using Flutter.
Saloon Manager Flutter Dotnetcore4
2 years agon,ullHTML
A Saloon Manager Admin Application for SPA's, Saloons, Barber Shop ,Beauty Parlours built using Blazor,DotNetCore,SignalR,SQLServer,Flutter,Firebase,SMS,Whatsapp,Stripe
Alternatives To Sqlbrite
Select To Compare


Alternative Project Comparisons
Readme

SQL Brite alt text

Author: Petrus Nguyễn Thái Học

Tests Build example Pub Pub Build Status codecov License: MIT Style Hits

  • Reactive stream wrapper around sqflite for Flutter inspired by sqlbrite
  • Streaming sqflite
  • RxDart reactive stream sqflite for Flutter
  • A lightweight wrapper around sqflite which introduces reactive stream semantics to SQL operations.

Getting Started

  1. Depend on it: In your flutter project, add the dependency to your pubspec.yaml
dependencies:
  ...
  sqlbrite: <latest_version>
  1. Install it: You can install packages from the command line with Flutter:
$ flutter packages get
  1. Import it: Now in your Dart code, you can use:
import 'package:sqlbrite/sqlbrite.dart';

Usage

1. Wrap your database in a BriteDatabase:

final Database db = await openDb();
final briteDb = BriteDatabase(db);
final briteDb = BriteDatabase(db, logger: null); // disable logging.

2. Using

  • The BriteDatabase.createQuery method is similar to Database.query. Listen to the returned Stream<Query> which will immediately notify with a Query to run.
  • These queries will run once to get the current data, then again whenever the given table is modified though the BriteDatabase.

Create entity model

class Entity {
  factory Entity.fromJson(Map<String, dynamic> map) { ... }
  
  factory Entity.empty() { ... }

  Map<String, dynamic> toJson() { ... }
}

Use mapToOne extension method on Stream<Query>

// Emits a single row, emit error if the row doesn't exist or more than 1 row in result set.
final Stream<Entity> singleQuery$ = briteDb.createQuery(
  'table',
  where: 'id = ?',
  whereArgs: [id],
  limit: 1,
).mapToOne((row) => Entity.fromJson(row));

Use mapToOneOrDefault extension method on Stream<Query>

// Emits a single row, or the given default value if the row doesn't exist, or emit error if more than 1 row in result set
final Stream<Entity> singleOrDefaultQuery$ = briteDb.createQuery(
  'table',
  where: 'id = ?',
  whereArgs: [id],
  limit: 1,
).mapToOneOrDefault(
  (row) => Entity.fromJson(row),
  defaultValue: Entity.empty()
);

Use mapToList extension method on Stream<Query>

// Emits a list of rows.
final Stream<List<Entity>> listQuery$ = briteDb.createQuery(
  'table',
  where: 'name LIKE ?',
  whereArgs: [queryName],
).mapToList((row) => Entity.fromJson(row));

Same API like Database


// will trigger query stream again
briteDb.insert(
  'table',
  Entity(...).toJson()
);

// will trigger query stream again
briteDb.update(
  'table',
  Entity(...).toJson(),
  where: 'id = ?',
  whereArgs: [id],
);

// will trigger query stream again
briteDb.update(
  'table',
  where: 'id = ?',
  whereArgs: [id],
);

Full power of RxDart operators

  • You can use RxDart operators to control the frequency of notifications to subscribers.
  • The full power of RxDart's operators are available for combining, filtering, and triggering any number of queries and data changes.
briteDb
    .createQuery(
      'table',
      where: 'name LIKE ?',
      whereArgs: [queryName],
    )
    .debounceTime(const Duration(milliseconds: 500))
    .where(filterQuery) // query is lazy, this lets you not even execute it if you don't need to
    .mapToList((row) => Entity.fromJson(row))
    .listen(updateUI);

Philosophy

SQL Brite's only responsibility is to be a mechanism for coordinating and composing the notification of updates to tables such that you can update queries as soon as data changes.

This library is not an ORM. It is not a type-safe query mechanism. It's not going to perform database migrations for you.

License

MIT License
Copyright (c) 2019 - 2022 Petrus Nguyễn Thái Học
Popular Sql Projects
Popular Flutter Projects
Popular Data Processing Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Dart
Flutter
Sql
Stream
Reactive