搜尋套件、儲存庫與 APP 分類

套件詳情v0.13.4

faunadb_http

FaunaDB 客戶端的純 Dart 實現,並提供與 FQL 函數非常接近的查詢類別。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
94
喜歡數
54
Pub 分數
130

安裝套件

flutter pub add faunadb_http

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個純 Dart 客戶端,用於 FaunaDB,可使用與 FQL(Fauna 查詢語言)非常接近的查詢介面,實現與資料庫的無縫互動。專為跨平台應用設計,支援所有主要平台,包括行動、Web 和桌面。該套件提供直觀的 Dart 類別,用於建構和執行查詢,讓開發者能輕鬆將 FaunaDB 集成到 Flutter 應用中,而無需依賴平台特定程式碼。非常適合希望以輕量級、類型安全方式管理即時應用資料的開發者。

適用情境

  • 即時應用資料同步
  • 無伺服器後端整合
  • 跨平台資料庫存取
  • 使用者身分驗證系統
  • 基於文件的資料儲存
  • 基於API的應用程式邏輯

主要特色

  • 純 Dart 實現
  • FQL 類查詢語法
  • 跨平台支援
  • 類型安全的查詢構建
  • 輕量且依賴極少
  • 非同步作業

適合對象

  • 使用 FaunaDB 的 Flutter 開發人員
  • 需要即時資料更新的應用程式
  • 專案避免原生平台程式碼
  • 後端服務,伺服器需求極低
  • 偏好 FQL 熟悉度的開發者

使用建議

  • 需要 FaunaDB 帳號和 API 密鑰
  • 受限於 FaunaDB 的功能集
  • 無離線優先功能
  • 依賴網路連接
  • 可能需要額外的錯誤處理才能用於生產環境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

faunadb-http

A pure Dart implementation of a FaunaDB client. This library also provides query classes that closely mimic FQL functions.

Usage

Basic Example
import 'package:faunadb_http/faunadb_http.dart';
import 'package:faunadb_http/query.dart';

void main() async {
  final config = FaunaConfig.build(
    secret: '<your_secret_here>',
  );
  final client = FaunaClient(config);

  final query = Paginate(Match(Index('all_customers')));

  final result = await client.query(query);
  print(result);

  client.close();
}
Writing Queries

After importing the query classes from this package (as in the example above), your queries will look almost identical to FQL.

Check out the FQL Cheat Sheet to see all valid FQL functions.

Example Queries
// segment from example/crud.dart

//
// create
//

final createCollection = CreateCollection(Obj({'name': 'users'}));

final createDocument = Create(
  Collection('users'),
  Obj({
    'data': {'name': 'Gavan Singh'}
  }),
);

final createIndex = CreateIndex(Obj({
  'name': 'user-by-name',
  'source': Collection('users'),
  'terms': [
    {
      'field': ['data', 'name']
    }
  ]
}));

final createFunction = CreateFunction(Obj({
  'name': 'double',
  'body': Query(Lambda('x', Add([Var('x'), Var('x')])))
}));

//
// read
//

final callDoubleFunction = Call(Function_('double'), arguments: 2);

final paginateUsers = Paginate(
  Match(Index('user-by-name'), terms: ['Gavan Singh']),
);

final readUser = Get(Ref(Collection('users'), '281080202238362125'));

final readAllUsers = Map_(
  Paginate(Match(Index('all_Users'))),
  Lambda(
    'userRef',
    Let(
      {
        'userDoc': Get(Var('userRef')),
      },
      Obj(
        {
          'id': Select(['ref', 'id'], Var('userDoc')),
          'name': Select(['data', 'name'], Var('userDoc')),
        },
      ),
    ),
  ),
);

final paginateCollections = Paginate(Collections());

//
// update
//

final updateUser = Update(
  Ref(Collection('users'), '281080202238362125'),
  Obj({
    'data': {'isCool': true}
  }),
);

//
// delete
//

final deleteUser = Delete(Ref(Collection('users'), '281080202238362125'));

Query Differences

There are some cases where your queries will have to be written slightly differently from pure FQL. Here are examples of each type of difference.

  • Optional FQL arguments are named arguments in Dart.

    • Repeat('x', number: 10)
    • Paginate(Collections(), size: 2)
  • FQL functions with a variable number of arguments (such as Sum, GT etc.) accept a Dart List instead.

    • Add([1, Var('x')])
  • Some FQL functions and arguments are reserved keywords in Dart; simply add a trailing underscore to them.

    • Map becomes Map_
    • Function becomes Function_
    • default becomes default_

Build

The json_serializable package provides JSON serialization to the query classes.

Run pub run build_runner build to generate the boilerplate code to add JSON serialization.

pub run build_runner watch is great when trying things out.

Contributors

Can be found in CONTRIBUTORS.md

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。