搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。