搜索分类、插件与代码仓

GitHub 代码仓Skycoder42/firebase_database_rest

firebase_database_rest

基于 REST 的 Firebase 实时数据库 API 的跨平台 Dart/Flutter 包装器

firebase_database_rest 项目封面
星标
0
复刻
4
最近推送(UTC)
2021年7月22日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

firebase_database_rest

Continous Integration Pub Version

A platform independent Dart/Flutter Wrapper for the Firebase Realtime Database API based on REST

Features

  • Pure Dart-based implementation
    • works on all platforms supported by dart
  • Uses the official REST-API endpoints
  • Provides high-level classes to manage database access
  • Supports Model-Binding via Generics and converter functions
  • Full support of all Realtime database features:
    • Supports CRUD
    • Supports Queries (filtering, sorting)
    • Supports realtime server updates (streaming)
    • Supports ETags
  • Provides a Transaction class to wrap ETag-Logic into safe transactions
  • Provides timestamp class for server set timestamps
  • Proivides low-level REST classes for direct API access (import firebase_database_rest/rest.dart)
  • Fully integrated with firebase_auth_rest - including automatic auth token refreshes

Installation

Simply add firebase_database_rest to your pubspec.yaml and run pub get (or flutter pub get).

Usage

The libraries primary class is the FirebaseStore. It is a high-level class that allows access to a certain part of the realtime database using Model binding. With this store, you specify a subpatch and can then perform various operations on elements below that path (list key, create, read, write or delete them, ...). This class also provides the APIs for streaming changes and transactions. Typically, your application would use multiple stores, one for each dataclass you plan to store at a certain path.

The second important class is the FirebaseDatabase. It serves as the toplevel class, parent to all stores and manages the database connection itself, including the management of the associated FirebaseAccount (from firebase_auth_rest) and background ressources (like the REST-API interface).

The following code is a simple example, which can be found in full length, including errorhandling, at https://pub.dev/packages/firebase_database_rest/example. It loggs into firebase as anonymous user, starts streaming changes and then does some db operations.

// The data class that is stored in firebase
class ExampleModel {
  final int id;
  final String data;

  const ExampleModel(this.id, this.data);
  
  // ...
}

// obtain a firebase account, using firebase_auth_rest
final account = // ...

// create a database reference from that account
final database = FirebaseDatabase(
  account: account,
  database: 'my-firebase-realtime-database-name,
  basePath: 'application/${account.localId}/example',
);

// create typed store. In this example, a callback store is used, but you can
// also just extend FirebaseStore
final store = database.createRootStore<ExampleModel>(
  onDataFromJson: (dynamic json) => ExampleModel.fromJson(json),
  onDataToJson: (data) => data.toJson(),
  onPatchData: (data, updatedFields) => data.patch(updatedFields),
);

// add a stream listener that reports database changes in realtime
sub = (await store.streamAll()).listen((e) => print('Stream update: $e'));

// add some data to the store
await store.create(const ExampleModel(1, 'A'));

// get all data in store
print('All data: ${await store.all()}');

// cleanup: stop streaming and dispose of the database
await sub.cancel();
await database.dispose();

Documentation

The documentation is available at https://pub.dev/documentation/firebase_database_rest/latest/. A full example can be found at https://pub.dev/packages/firebase_database_rest/example.

Felix Brandtner GitHub avatar
GitHub 作者

Felix Brandtner ↗

语言DartMakefile

此仓库发布的插件

使用的依赖

依赖清单 16 项

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗