Search packages, repositories and app categories

Package detailsv0.13.4

faunadb_http

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

AndroidiOSWebmacOSWindowsLinux
30-day downloads
94
Likes
54
Pub points
130

Install package

flutter pub add faunadb_http

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A pure Dart client for FaunaDB that enables seamless interaction with the database using a query interface closely mirroring FQL (Fauna Query Language). Designed for cross-platform applications, it supports all major platforms including mobile, web, and desktop. The package provides intuitive Dart classes to construct and execute queries, making it easy to integrate FaunaDB into Flutter apps without relying on platform-specific code. It is ideal for developers seeking a lightweight, type-safe way to manage data in real-time applications.

Use cases

  • Real-time app data synchronization
  • Serverless backend integration
  • Cross-platform database access
  • User authentication systems
  • Document-based data storage
  • API-driven application logic

Key features

  • Pure Dart implementation
  • FQL-like query syntax
  • Cross-platform support
  • Type-safe query construction
  • Lightweight and minimal dependencies
  • Asynchronous operations

Suitable for

  • Flutter developers using FaunaDB
  • Apps requiring real-time data updates
  • Projects avoiding native platform code
  • Backend services with minimal server requirements
  • Developers preferring FQL familiarity

Considerations

  • Requires FaunaDB account and API key
  • Limited to FaunaDB's feature set
  • No offline-first capabilities
  • Depends on network connectivity
  • May require additional error handling for production use

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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

Categories

Dependencies

Dependency list 2 items

Source repository

Projects using this package

No data available yet.