⚡️ CRUDify Supabase Tables

Overview

⚡️ CRUDify Supabase Tables ⚡️

This is a wrapper around @supabase/supabase-js that generates CRUD actions (like Prisma) to manage tables' data.

Quickstart

  1. Install libraries
yarn add @supabase/supabase-js supabase-js-crud
  1. Create supabase client
import {createClient} from '@supabase/supabase-js';

const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key');
  1. CRUDify your tables
import {DBTable} from 'supabase-js-crud';

const db = {
  shop: new DBTable(supabase, 'shop'),
  product: new DBTable(supabase, 'product'),
};

const shops = await db.shop.find();
const oneProduct = await db.product.findOne({where: {id: '123456789'}});

CRUD methods

  • create: (params: CreateParams<T>, options?: DBTableMethodOptions) => Promise<T[] | null>;
  • createOne: (params: CreateOneParams<T>, options?: DBTableMethodOptions) => Promise<T | null>;
  • find: (params?: FindParams<T>, options?: DBTableMethodOptions) => Promise<T[]>;
  • findOne: (params?: FindOneParams<T>, options?: DBTableMethodOptions) => Promise<T | null>;
  • update: (params: UpdateParams<T>, options?: DBTableMethodOptions) => Promise<T[] | null>;
  • updateOne: (params: UpdateOneParams<T>, options?: DBTableMethodOptions) => Promise<T | null>;
  • delete: (params: DeleteParams<T>, options?: DBTableMethodOptions) => Promise<T[] | null>;
  • count: (params?: CountParams<T>, options?: DBTableMethodOptions) => Promise<number>;

TODO: add more detailed description for params and options types. For now, you can check them in types and they are mostly intuitive.

Global methods

  • registerActions(...) lets you register handlers for global actions such as onError that might be useful if you develop separate API server.
import {registerActions} from 'supabase-js-crud/dist/help';

registerActions({
  onError: error => {
    throw new InternalServerErrorException(error);
  },
});
  • registerConstants(...) lets you register global constants which are used in CRUD actions such as default value for take. By default, it's 25.
import {registerConstants} from 'supabase-js-crud/dist/help';

registerConstants({
  take: 50,
});

Models

You can also provide a model class to DBTable so IDEs will help with autocompletion.

type Shop = {
  id: string;
  created_at: Date;
  updated_at: Date;
  name?: string;
};

const shopTable = new DBTable<Shop>(supabase, 'shop');
const oneShop = await shopTable.findOne({where: {name: {like: '%Supa%'}}});

For types generation, check out Supabase docs.

Examples

  • Create a new shop with name SupaShop:
await db.shop.createOne({data: {name: 'SupaShop'}});
  • Get active products and a related shop:
await db.product.find({
  where: {status: 'ACTIVE'},
  include: ['*', 'shop:shop_id (id, name, status)'],
});
  • Get 20 active products with category name Bags ordered by created_at (descending):
await db.product.find({
  where: {status: 'ACTIVE'},
  include: ['*', 'shop:shop_id (id, name, status)', 'category:category_id!inner (name)'],
  innerWhere: {
    'category.name': 'Bags',
  },
  order: {by: 'created_at', ascending: false},
  take: 20,
});

Enhancements

  • Better docs and more examples
  • Article with the library usage?

Feel free to open an issue for suggestions as the library is in the beginning stages.

Troubleshooting

If you face any issues with the library, please, open an issue with the detailed explanation.

Credits

Credits go to the amazing team behind the awesome Supabase project!

License

This project is MIT licensed

You might also like...

Example project implementing authentication, authorization, and routing with Next.js and Supabase

Example project implementing authentication, authorization, and routing with Next.js and Supabase

Magic Link Authentication and Route Controls with Supabase and Next.js To run this project, To get started with this project, first create a new proje

Dec 11, 2022

The Remix Stack for deploying to Fly with Supabase, authentication, testing, linting, formatting, etc.

The Remix Stack for deploying to Fly with Supabase, authentication, testing, linting, formatting, etc.

Remix Supa Fly Stack Learn more about Remix Stacks. npx create-remix --template rphlmr/supa-fly-stack What's in the stack Fly app deployment with Doc

Jan 7, 2023

⚡ A blazing fast, lightweight, and open source comment system for your static website, blogs powered by Supabase

⚡ A blazing fast, lightweight, and open source comment system for your static website, blogs powered by Supabase

SupaComments ⚡ A blazing fast, lightweight, and open source comment system for your static website, blogs 🚀 Demo You can visit the Below demo blog po

Dec 27, 2022

ChatMore: A web chatapp like Whatsapp - Made in Typescript, React and Supabase

ChatMore: A web chatapp like Whatsapp - Made in Typescript, React and Supabase

ChatMore This project is a chatapp made in React. On the main page we can authenticate, and then add todos to the our list. The ultimate goal of this

Jan 3, 2023

This is a project to make the supabase REST API available from PrismaClient.

This is a project to make the supabase REST API available from PrismaClient.

sb-prisma 🔧 This project is experimental and not yet stable, so please use with caution. We look forward to your contributions. ⚠️ For non-node runti

Jul 6, 2022

tooldb is a (soon) massive collection of frameworks and tools. It's build on Flowbite, Next.js, Tailwind CSS and uses Supabase.

tooldb is a (soon) massive collection of frameworks and tools. It's build on Flowbite, Next.js, Tailwind CSS and uses Supabase.

tooldb is a (soon) massive collection of frameworks and tools. It's build on Flowbite, Next.js, Tailwind CSS and uses Supabase.

Jul 14, 2022

API dot Open Sauced is NestJS and SupaBase powered OAS3 backend designed to remove client complexity and provide a structured graph of all @open-sauced integrations

API dot Open Sauced is NestJS and SupaBase powered OAS3 backend designed to remove client complexity and provide a structured graph of all @open-sauced integrations

🍕 Open Sauced Nest Supabase API 🍕 The path to your next Open Source contribution 📖 Prerequisites In order to run the project we need the following

Dec 18, 2022

A modern uptime monitoring tool & status page based on Supabase.

A modern uptime monitoring tool & status page based on Supabase.

StatusBase (Supabase) Uptime monitoring tool & beautiful status pages Powered by Supabase! Free • Open Source • Notification View Demo · Report Bug ·

Dec 3, 2022

The Remix Stack with Clerk authentication, Supabase database, Chakra UI, testing, linting, and more.

The Remix Stack with Clerk authentication, Supabase database, Chakra UI, testing, linting, and more.

Remix Bossa Nova Stack Learn more about Remix Stacks. What's in the stack User management with Clerk Database with Supabase Styling with Chakra UI Dep

Jan 2, 2023
Releases(0.0.1)
  • 0.0.1(Jun 16, 2022)

    • scripts changed (8e3851c)
    • 0.0.1-rc.2 (dd68285)
    • comment removed (a9a9119)
    • Global methods section added (b2625a5)
    • full readme (cef87ee)
    • license renamed (638c48a)
    • 0.0.1-rc.1 (47466a7)
    • correct way of holding pointer (b94fd72)
    • version & desc changed (91944bd)
    • DBTable :: default generic type is any (d46a99c)
    • target & module changed (3453fde)
    • Update package.json (687f37a)
    • first source code added (00a9b7d)
    • description changed (27b2f2b)
    • @supabase/supabase-js added (75b8dcb)
    • initial commit (3f062c3)
    Source code(tar.gz)
    Source code(zip)
Owner
Batyr
Problems solver. Open Source Staff. MS in CS. Maintainer @starters-dev
Batyr
Render readable & responsive tables in the terminal

terminal-columns Readable tables for the terminal. Tables can be automatically responsive! Features Content wrapped to fit column width Column widths

hiroki osame 28 Oct 28, 2022
Obsidian-dataview-table-filter-menu - Dynamically created filter menu for dataview tables in obsidian

Dataview table Filter Menu for Obsidian Dynamically created filter menu for data

shiro 17 Sep 24, 2022
An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone.

An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone

Andy 44 Dec 30, 2022
View maps, graphs, and tables of your save and compete in a casual, evergreen leaderboard of EU4 achievement speed runs. Upload and share your save with the world.

PDX Tools PDX Tools is a modern EU4 save file analyzer that allow users to view maps, graphs, and data tables of their save all within the browser. If

PDX Tools 24 Dec 27, 2022
An Obsidian Plugin that allows to export tables from a pane in reading mode to CSV files.

Obsidian Plugin "Table to CSV Exporter" This is my very first attempt in writing a plugin for Obsidian. I didn't even know TypeScript before (but Java

Stefan Wolfrum 26 Dec 27, 2022
Javascript library to make HMTL tables editable, using Bootstrap

Donate to the project Bootstable Javascript library to make HMTL tables editable. "Bootstable" is a javascript library (plug-in), that lets convert a

Tito Hinostroza 59 Oct 30, 2022
Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.

Jspreadsheet CE v4: The JavaScript spreadsheet Jexcel CE has been renamed to Jspreadsheet CE News Important: Please import jspreadsheet.css (jexcel.cs

null 6.2k Dec 19, 2022
A jQuery plugin for making html tables searchable and sortable with pagination

jQuery.fancyTable A jQuery plugin for making html tables searchable and sortable with pagination. Live demo See a live demo on CodePen Installation Us

null 45 Dec 19, 2022
Graphs/networks turned into tables

(IMP NOTE FOR CONTRIBUTORS: PLEASE DON'T FORMAT THE CODE, IT'S DIFFICULT FOR ME TO FIND THE CHANGES. THANK YOU!) Graph to Table You must have seen gra

null 12 Oct 20, 2022