npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cursecode/fastify-supabase

v1.0.0

Published

Supabase client initialization and encapsulation in fastify framework

Downloads

3

Readme

fastify-supabase

NPM version GitHub CI Coverage Status js-standard-style

Supabase client initialization and encapsulation in fastify framework.

Install

Install the package with:

npm i fastify-supabase --save

Usage

The package needs to be added to your project with register and you must at least configure your Supabase API key and your Supabase URL wich are available in your Supabase project settings then call the Supabase API and you are done.

const fastify = require('fastify')({ logger: true })

fastify.register(require('fastify-supabase'), {
  supabaseKey: 'public-anon-key',
  supabaseUrl: 'https://xyzcompany.supabase.co'
})

fastify.get('/read', async (request, reply) => {
  const { supabase } = fastify

  const { data, error } = await supabase.from('cities').select()

  return { data, error }
})

fastify.listen(3000, (err) => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
})

Options

  • supabaseKey [ required ] <string>: The unique Supabase Key which is supplied when you create a new project in your project dashboard.

  • supabaseUrl [ required ] <string>: The unique Supabase URL which is supplied when you create a new project in your project dashboard.

  • namespace [ optional ] <string>: Through this option fastify-supabase lets you define multiple Supabase singular instances (with different options parameters if you wish) that you can later use in your application.

const fastify = require('fastify')({ logger: true })

fastify.register(require('fastify-supabase'), {
  namespace: 'one',
  supabaseKey: 'public-anon-key-one',
  supabaseUrl: 'https://xyzcompanyprojectone.supabase.co'
})

fastify.register(require('fastify-supabase'), {
  namespace: 'two',
  supabaseKey: 'public-anon-key-two',
  supabaseUrl: 'https://xyzcompanyprojecttwo.supabase.co'
})

fastify.get('/fetch-from-one', async (request, reply) => {
  const { supabase } = fastify

  const { data, error } = await supabase.one.from('project_one_table').select()

  return { data, error }
})

fastify.get('/fetch-from-two', async (request, reply) => {
  const { supabase } = fastify

  const { data, error } = await supabase.two.from('project_two_table').select()

  return { data, error }
})

fastify.listen(3000, (err) => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
})
  • schema [ optional ] <string>: The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.

  • headers [ optional ] <{ [key: string]: string }>: Optional headers for initializing the client.

  • autoRefreshToken [ optional ] <boolean>: Automatically refreshes the token for logged in users.

  • persistSession [ optional ] <boolean>: Whether to persist a logged in session to storage.

  • detectSessionInUrl [ optional ] <boolean>: Detect a session from the URL. Used for OAuth login callbacks.

  • localStorage [ optional ] <SupabaseAuthClientOptions['localStorage']>: A storage provider. Used to store the logged in session.

  • realtime [ optional ] <RealtimeClientOptions>: Options passed to the realtime-js instance.

Note for TypeScript users: If you are a TypeScript user, take a look at Supabase Generating Types documentation.

Documentation

See the Supabase reference documentation.

Testing

  • Create a test table in your Supabase project database with:
CREATE TABLE "public"."fastify_supabase_test" (
  "id" uuid DEFAULT GEN_RANDOM_UUID() NOT NULL,
  "job" uuid NOT NULL,
  "name" character varying NOT NULL,
  "created_at" timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
  CONSTRAINT "fastify_supabase_test_id__pkey" PRIMARY KEY ("id")
) WITH (oids = false);
  • Create a file named .env (at the root of this project) providing your supabaseKey and supabaseUrl:
SUPABASE_API_KEY=public-anon-key-of-your-project
SUPABASE_PROJECT_URL=https://xyzcompany.supabase.co
  • Finally run tests with:
npm run test

Acknowledgements

  • Ruan Martinelli for kindly transferring the ownership of the package name.
  • This project is kindly sponsored by coopflow.

License

Licensed under MIT