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

supakit-eloquent

v0.1.8

Published

![npm](https://img.shields.io/npm/v/supakit-eloquent) ![npm](https://img.shields.io/npm/dy/:packageName)

Downloads

5

Readme

npm npm

⚠️ This project is still in development and is not ready for production use. ⚠️

Project Name

A niche ORM for Supabase inspired by Laravel Eloquent.

Table of Contents

Installation

npm install supakit-eloquent

Usage

Initialization

  1. SvelteKit
// src/hooks.ts
import { Model } from 'supakit-eloquent';

export const handle: Handle = async ({ event, resolve }) => {
    event.locals.supabase = createSupabaseServerClient({
        supabaseUrl: supabaseURL,
        supabaseKey: supabaseAnonKey,
        event,
    })
    Model.setConnection({client: event.locals.supabase});
    // or
    Model.setConnection({
        supabaseUrl: supabaseURL,
        supabaseKey: supabaseAnonKey,
    });
}
  1. Other frameworks / vanilla JS

Yet to be tested. Use Model.setConnection() to set the connection to supabase wherever you need to make sure it runs on startup / on every request.

import { Model } from 'supakit-eloquent';

Model.setConnection({client: event.locals.supabase});
// or
Model.setConnection({
    supabaseUrl: supabaseURL,
    supabaseKey: supabaseAnonKey,
});

Alternatively, you can set the client in the extended model classes.

import { Model } from 'supakit-eloquent';
import { createClient } from '@supabase/supabase-js';

export class User extends Model {
    protected static _connector = createClient({
        supabaseUrl: supabaseURL,
        supabaseKey: supabaseAnonKey,
    });
}

// or with the supabase client instance, anyway you usually get it

const client = useSupabaseClient();

export class User extends Model {
    protected static _connector = client;
}

Extending the Model Class

The Model class is a core component of this project. It provides an abstraction for interacting with supabase. To use the Model class, follow these steps:

  1. Create a class that extends the Model class. The User class will inherit all the methods of the Model class. The table name will be automatically inferred from the class name if the class name is in PascalCase.
import { Model } from 'supakit-eloquent';

export class User extends Model {
    // the table name will be inferred as "users"
}

export class UserProfile extends Model {
    // the table name will be inferred as "user_profiles"
}

export class BusinessPerson extends Model {
    // the table name will be inferred as "business_people"
}
  1. Customize the primary key column and the table name.

The table's id column will be inferred as id if not specified. If the table name and/or the primary key are different from the inferred values, you can specify them in the class definition.

import { Model } from 'supakit-eloquent';

// Simple primary key & custom table name
export class User extends Model {
    protected static _table = 'app_users';
    protected static _idColumn = 'user_id';
}

// Composite primary key & custom table name
export class BookmarkedPost extends Model {
    protected static _table = 'liked_posts';
    protected static _idColumn = ['user_id', 'post_id'];
}
  1. Instance Methods
import { User } from './lib/models/User'; // example

const user = new User({name: 'John Smith', email: '[email protected]'});

// Save the user as it currently is in the database
await user.save();

// Delete the user from the database
await user.delete();

// Update the user in the database. The user instance will be updated with the new data.
await user.update({name: 'Amy Pond'}); 

// Refresh the user's data from the database (in case it might have been updated by another process/source)
await user.refresh();

// Duplicate the user in the database
const duplicateUser = await user.duplicate();
  1. Static Methods

// Create a new user in the database
const user = await User.create({name: 'River Song', email: '[email protected]'});

// Find a user by id
const user = await User.find(1);

// Delete a user by id (or any other primary key column)


## Contributing

Contributions are always welcome! I am yet to define guidelines for contributing to this project. In the meantime, feel free to open an issue or a pull request.

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).

## Contact

Through my [website] (https://one-in-emilien.com) or on GitHub.