All Projects → gavanitrate → faunadb-http-dart

gavanitrate / faunadb-http-dart

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

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to faunadb-http-dart

faugra
A micro "no-backend" backend framework 🤯 Quickly build powerful BaaS using only your graphql schemas
Stars: ✭ 44 (+57.14%)
Mutual labels:  faunadb
theodorusclarence.com
💠 Personal website and blog made using Next.js, TypeScript, Tailwind CSS, MDX Bundler, FaunaDB, and Preact.
Stars: ✭ 205 (+632.14%)
Mutual labels:  faunadb
netlify-faunadb-graphql-auth
Netlify functions example with faunadb, graphql, and authorization
Stars: ✭ 57 (+103.57%)
Mutual labels:  faunadb
next-fauna-auth
Implemented cookie-based user authentication in a Next.js, FaunaDB and GraphQL app
Stars: ✭ 29 (+3.57%)
Mutual labels:  faunadb
fauna-workers
A template for building fast, globally distributed applications using Cloudflare Workers and Fauna, the data API for modern applications.
Stars: ✭ 35 (+25%)
Mutual labels:  faunadb
fauna-gql-upload
A tool for managing your FaunaDB database using files. Create resources such as functions by simply creating a new file.
Stars: ✭ 45 (+60.71%)
Mutual labels:  faunadb
virtual-lolly
JAMstack demo site - prerendered with serverless API fallbacks
Stars: ✭ 110 (+292.86%)
Mutual labels:  faunadb
coderplex-org
Official Website for Coderplex Community. Built with Next.js and deployed on Vercel.
Stars: ✭ 32 (+14.29%)
Mutual labels:  faunadb
faunadb-csharp
C# driver for FaunaDB
Stars: ✭ 55 (+96.43%)
Mutual labels:  faunadb
faunadb-ruby
Ruby driver for FaunaDB
Stars: ✭ 37 (+32.14%)
Mutual labels:  faunadb
testimonial
Jamstack app using Gatsby, Netlify, and FaunaDB.
Stars: ✭ 23 (-17.86%)
Mutual labels:  faunadb
fauna-gatsby-comments
Roll your own comments with Gatsby and FaunaDB 🗞️
Stars: ✭ 29 (+3.57%)
Mutual labels:  faunadb
faunadb-importer
Importer tool to load data into FaunaDB
Stars: ✭ 33 (+17.86%)
Mutual labels:  faunadb
shopnote
shopnote is a JAMstack application that helps in creating notes with shopping items. This application is built to showcase the JAMstack concept using Fauna, Netlify Serverless Functions and GatsbyJS.
Stars: ✭ 15 (-46.43%)
Mutual labels:  faunadb
local-docker-db
A bunch o' Docker Compose files used to quickly spin up local databases.
Stars: ✭ 251 (+796.43%)
Mutual labels:  faunadb
auth-email
🔐 Lightweight authentication specifically designed for Next.js
Stars: ✭ 73 (+160.71%)
Mutual labels:  faunadb
faunadb-fql-lib
No description or website provided.
Stars: ✭ 83 (+196.43%)
Mutual labels:  faunadb
use-fauna
React hooks for interacting with Fauna databases
Stars: ✭ 44 (+57.14%)
Mutual labels:  faunadb

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].