Coder Social home page Coder Social logo

supabase / dbdev Goto Github PK

View Code? Open in Web Editor NEW
331.0 23.0 18.0 4.06 MB

Database Package Registry for Postgres

Home Page: https://database.dev/

License: Apache License 2.0

PLpgSQL 46.69% JavaScript 0.64% TypeScript 40.34% CSS 0.40% Rust 11.93%
extensions postgres postgresql

dbdev's Introduction

dbdev

dbdev

dbdev is a package manager for Postgres trusted language extensions (TLE).

Usage

Users primarily interact with the registry using the dbdev SQL client. Once present, packages can be installed as follows:

-- Load the package from the package index
select dbdev.install('olirice-index_advisor');

Where olirice is the handle of the publisher and index_advisor is the name of the package.

Once installed, packages are visible in PostgreSQL as extensions. At that point they can be enabled with standard Postgres commands i.e. the create extension

To improve reproducibility, we recommend always specifying the package version in your create extension statements.

For example:

-- Enable the extension
create extension "olirice-index_advisor"
    version '0.1.0';

Which creates all tables/indexes/functions/etc specified by the extension.

Install the Client in Postgres

The in-database SQL client for the package registry is named dbdev. You can bootstrap the client with:

/*---------------------
---- install dbdev ----
----------------------
Requires:
  - pg_tle: https://github.com/aws/pg_tle
  - pgsql-http: https://github.com/pramsey/pgsql-http
*/
create extension if not exists http with schema extensions;
create extension if not exists pg_tle;
-- drop dbdev with older naming scheme if present
drop extension if exists "supabase-dbdev";
select pgtle.uninstall_extension_if_exists('supabase-dbdev');
drop extension if exists "supabase@dbdev";
select pgtle.uninstall_extension_if_exists('supabase@dbdev');
select
    pgtle.install_extension(
        'supabase@dbdev',
        resp.contents ->> 'version',
        'PostgreSQL package manager',
        resp.contents ->> 'sql'
    )
from http(
    (
        'GET',
        'https://api.database.dev/rest/v1/'
        || 'package_versions?select=sql,version'
        || '&package_alias=eq.supabase@dbdev'
        || '&order=version.desc'
        || '&limit=1',
        array[
            ('apiKey', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s')::http_header
        ],
        null,
        null
    )
) x,
lateral (
    select
        ((row_to_json(x) -> 'content') #>> '{}')::json -> 0
) resp(contents);
create extension "supabase@dbdev";
select dbdev.install('supabase@dbdev');
drop extension if exists "supabase@dbdev";
create extension "supabase@dbdev";

With the client ready, search for packages on database.dev and install them

select dbdev.install('handle@package_name');
create extension "handle@package_name"
    schema 'public'
    version '1.2.3';

Developers

The supabase/dbdev repository hosts the source code for both the database.dev package registry and its accompanying website. It also hosts the work-in-progress CLI for authors manage their packages.

Package Registry

The package registry supabase/, is a Supabase project where accounts, organizations, and packages are normalized into database tables. For more info of the registry, see the architecture section

Requires:

supabase start

which returns a set of endpoints for each service

supabase local development setup is running.

         API URL: http://localhost:54321
     GraphQL URL: http://localhost:54321/graphql/v1
          DB URL: postgresql://postgres:postgres@localhost:54322/postgres
      Studio URL: http://localhost:54323
    Inbucket URL: http://localhost:54324
      JWT secret: SECRET
        anon key: KEY
service_role key: KEY

The API URL and anon key values will be used in the next section to setup environment variables.

Website (database.dev)

The website/ directory contains a Next.js project, which serves as the visual interface for users to interact with the registry.

Requires:

Copy .env.example file to .env.local:

cp .env.example .env.local

Edit the .env.local file with your favourite text editor to set the environment variables NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY:

NEXT_PUBLIC_SUPABASE_URL="<Value of API URL>"
NEXT_PUBLIC_SUPABASE_ANON_KEY="<Value of anon key>"

Start the development environment:

cd website
npm install
npm run dev

Navigate to http://localhost:3000

CLI

Coming soon in the cli/ directory

Architecture

  • The core tables are located in the app schema.
  • The public API is located in the public schema.

ERD

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.