faunatils
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

Faunatils

FaunaDB Utilities

Installation

$ npm install faunatils

Usage

import {Client} from "faunadb";
import {getByIndex, createCaller, WithRef} from "faunatils";

type Item = {
  color: string;
  name: string;
  price: number;
};

const client = new Client({
  secret: process.env.FAUNA_KEY,
});

const call = createCaller(client);

async function getItemNameAndPriceByColor(color: string) {
  let [item, error] = await call<WithRef<Item>>(
    getByIndex("itemByColor", color),
  );

  if (error) {
    return null;
  }

  return `${item?.data?.name} $${item?.data?.price}`;
}

handler();

Readme

Keywords

none

Package Sidebar

Install

npm i faunatils

Weekly Downloads

0

Version

0.3.3

License

MIT

Unpacked Size

10 kB

Total Files

11

Last publish

Collaborators

  • kocisov