• Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust client for PostgREST

postgrest-rs

Build Crate API License: Apache-2.0 OR MIT

PostgREST client-side library πŸ¦€. This library provides an ORM interface to PostgREST.

Usage

Add this to your Cargo.toml:

[dependencies]
postgrest = "1.0"

Simple example:

use postgrest::Postgrest;

let client = Postgrest::new("https://your.postgrest.endpoint");
let resp = client
    .from("your_table")
    .select("*")
    .execute()
    .await?;
let body = resp
    .text()
    .await?;

Simple example with JWT auth

use postgrest::Postgrest;

let client = Postgrest::new("https://your.postgrest.endpoint");
let resp = client
    .from("your_table")
    .auth("VerySensitiveJWTValueAsStringOrStr")
    .select("*")
    .execute()
    .await?;
let body = resp
    .text()
    .await?;

Simplified example using a custom header (e.g. for API gateway authentication with Supabase).

use postgrest::Postgrest;

let client = Postgrest::new("https://your.supabase.endpoint/rest/v1/")
    .insert_header("apikey", "ExampleAPIKeyValue"); // EXAMPLE ONLY!
// Don't actually hard code this value, that's really bad. Use environment
// variables like with the dotenv(https://crates.io/crates/dotenv) crate to inject
let resp = client
    .from("your_table")
    .select("*")
    .execute()
    .await?;
let body = resp
    .text()
    .await?;

Secure example with authenticated API gateway using the dotenv crate to correctly retrieve sensitive values.

use postgrest::Postgrest;
use dotenv;

dotenv::dotenv().ok(); 

let client = Postgrest::new("https://your.supabase.endpoint/rest/v1/")
    .insert_header(
        "apikey",
        dotenv::var("SUPABASE_PUBLIC_API_KEY").unwrap())
let resp = client
    .from("your_table")
    .select("*")
    .execute()
    .await?;
let body = resp
    .text()
    .await?;

Building Queries

These examples assume you've already initialized the client. The methods .from() and .rpc() initalizes the query builder inside the client.

Using filters:

let resp = client
    .from("your_table")
    .eq("country", "Germany")
    .gte("id", "20")
    .select("*")
    .execute()
    .await?;

Updating a table:

let resp = client
    .from("your_table")
    .eq("username", "soedirgo")
    .update("{\"organization\": \"supabase\"}")
    .execute()
    .await?;

Executing stored procedures:

let resp = client
    .rpc("add", "{\"a\": 1, \"b\": 2}")
    .execute()
    .await?;

Not enough filters:

let resp = client
    .from("countries")
    .eq("name", "New Zealand")                        // You can filter for equality...
    .gt("id", "20")
    .lt("id", "20")
    .gte("id", "20")
    .lte("id", "20")
    .like("name", "%United%")                         // ...do pattern matching...
    .ilike("name", "%United%")
    .is("name", "null")
    .in_("name", vec!["China", "France"])
    .neq("name", "China")
    .fts("phrase", "The Fat Cats", Some("english"))   // ...do full text search...
    .plfts("phrase", "The Fat Cats", None)
    .phfts("phrase", "The Fat Cats", Some("english"))
    .wfts("phrase", "The Fat Cats", None)
    .cs("countries", "(10,20)")
    .cd("countries", "(10,20)")
    .ov("population_range", "(100,500)")
    .sl("population_range", (100, 500))               // ...and range operations!
    .sr("population_range", (100, 500))               // Find out more about the filters at:
    .nxl("population_range", (100, 500))              // https://postgrest.org/en/stable/api.html#operators
    .nxr("population_range", (100, 500))
    .adj("population_range", (100, 500))
    .select("*")
    .execute()
    .await?;

Check out the API docs for more info!

Contributing

Contributions are welcome! There might be some features you want in, or some unclear documentation, or a bugβ€”either way, feel free to create an issue, and we'll work it out!

Boring stuff below.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

License

Licensed under either of

at your option.


More Repositories

1

postgres_lsp

A Language Server for Postgres
Rust
3,188
star
2

postgres-new

In-browser Postgres sandbox with AI assistance
TypeScript
2,212
star
3

nextjs-openai-doc-search

Template for building your own custom ChatGPT style doc search powered by Next.js, OpenAI, and Supabase.
TypeScript
1,249
star
4

copycat

Generate deterministic fake values: The same input will always generate the same fake-output.
TypeScript
755
star
5

supabase-csharp

A C# Client library for Supabase
C#
491
star
6

supabase-on-aws

Self-hosted Supabase on AWS
TypeScript
382
star
7

supabase-kt

A Kotlin Multiplatform Client for Supabase.
Kotlin
364
star
8

sql-examples

Curated list of SQL to help you find useful script easily πŸš€
Vue
358
star
9

chatgpt-your-files

Production-ready MVP for securely chatting with your documents using pgvector
TypeScript
330
star
10

supabase-custom-claims

How to implement custom claims with Supabase
JavaScript
254
star
11

supabase-graphql-example

A HackerNews-like clone built with Supabase and pg_graphql
PLpgSQL
214
star
12

snapshot

Capture a snapshot (or subset) of your Postgres database whilst transforming the data.
TypeScript
211
star
13

supabase-kubernetes

Helm 3 charts to deploy a Supabase on Kubernetes
Smarty
206
star
14

svelte-kanban

PLpgSQL
203
star
15

godot-engine.supabase

A lightweight addon which integrates Supabase APIs for Godot Engine out of the box.
GDScript
172
star
16

nuxt-supabase

A supa simple wrapper around Supabase.js to enable usage within Nuxt.
TypeScript
167
star
17

postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
Go
125
star
18

supabase-ui-svelte

Supabase authentication UI for Svelte
Svelte
120
star
19

postgrest-csharp

A C# Client library for Postgrest
C#
117
star
20

firebase-to-supabase

Firebase to Supabase Migration Guide
JavaScript
100
star
21

vue-supabase

A supa simple wrapper around Supabase.js to enable usage within Vue.
TypeScript
87
star
22

expo-stripe-payments-with-supabase-functions

Bring the Func(πŸ•Ί)
TypeScript
86
star
23

realtime-csharp

A C# client library for supabase/realtime.
C#
71
star
24

svelte-supabase

JavaScript
71
star
25

partner-gallery-example

Supabase Partner Gallery Example
TypeScript
67
star
26

supabase-sveltekit-example

Svelte
65
star
27

supabase-flutter-quickstart

Flutter implementation of the Quickstart Supabase User Management app.
C++
61
star
28

deno-fresh-openai-doc-search

Template for building your own custom ChatGPT style doc search powered by Fresh, Deno, OpenAI, and Supabase.
TypeScript
60
star
29

supabase-traefik

Python
57
star
30

flutter-stripe-payments-with-supabase-functions

Dart
55
star
31

supabase-terraform

HCL
53
star
32

postgrest-kt

Postgrest Kotlin Client
Kotlin
52
star
33

supabase-vscode-extension

Supabase Extension for VS Code and GitHub Copilot.
TypeScript
50
star
34

flutter-auth-ui

Supabase Auth UI library for Flutter
Dart
49
star
35

supabase-rb

An isomorphic Ruby client for Supabase.
Ruby
46
star
36

realtime-swift

A Swift client for Supabase Realtime server.
Swift
45
star
37

supabase-by-example

TypeScript
44
star
38

flutter-chat

Simple chat application built with Flutter and Supabase.
Dart
44
star
39

postgrest-swift

Swift client for PostgREST
Swift
43
star
40

gotrue-csharp

C# implementation of Supabase's GoTrue
C#
39
star
41

postgrest-rb

Isomorphic Ruby client for PostgREST.
Ruby
32
star
42

gotrue-swift

A Swift client library for GoTrue.
Swift
32
star
43

storage-go

Storage util client for Supabase in Go
Go
31
star
44

vec2pg

Migrate vector workloads to Postgres
Python
29
star
45

chatgpt-plugin-template-deno

Template for building ChatGPT Plugins in TypeScript that run on Supabase's custom Deno Edge Runtime.
TypeScript
27
star
46

storage-swift

Swift client library to interact with Supabase Storage
Swift
25
star
47

base64url-js

Pure TypeScript implementation of Base64-URL encoding for JavaScript strings.
TypeScript
22
star
48

gotrue-kt

Kotlin Client for GoTrue API
Kotlin
21
star
49

storage-csharp

A C# implementation of Supabase's Object Storage API
C#
19
star
50

sql-to-rest

SQL to PostgREST translator
TypeScript
19
star
51

postgrest-ex

Elixir Client library for PostgREST
Elixir
18
star
52

gotrue-ex

An Elixir client for the GoTrue authentication service
Elixir
16
star
53

heroku-to-supabase

Heroku to Supabase Migration Guide
16
star
54

sveltekit-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with SvelteKit.
TypeScript
13
star
55

nuxt3-quickstarter

CSS
13
star
56

gotrue-go

Typed Golang cilent for the Supabase fork of GoTrue
Go
12
star
57

supabase-php

PHP
11
star
58

pg_headerkit

A set of functions for adding special features to your application that uses PostgREST API calls to your PostgreSQL database.
PLpgSQL
11
star
59

functions-csharp

C# client for interacting with Supabase Functions
C#
11
star
60

auth-go

Go
10
star
61

gotrue-java

A Java client library for the GoTrue API.
Java
10
star
62

onesignal

Next.js app showcasing how you can implement push notification using OneSignal and Supabase
TypeScript
10
star
63

postgres-wasm-fdw

A WebAssembly foreign data wrapper example project
Rust
9
star
64

functions-swift

Swift Client library to interact with Supabase Functions.
Swift
8
star
65

supabase-adminpack

A Trusted Language Extension containing a variety of useful databse admin queries.
8
star
66

functions-go

Golang client library to interact with Supabase Functions.
Go
7
star
67

unboring.sg

A website and browser extensions to discover things to eat, do, and learn.
TypeScript
7
star
68

supabase-community-bot

TypeScript
5
star
69

ai-writer

An AI writing assistant powered by OpenAI, Supabase, and Next.js
TypeScript
5
star
70

storage-java

A Java client library for the Supabase Storage API
Java
4
star
71

supabase-management-js

Convenience wrapper for the Supabase Management API: https://supabase.com/docs/reference/api/introduction
TypeScript
4
star
72

supabase-go

Go
4
star
73

deno-supabase-js

Using supabase-js in Deno.
4
star
74

launchweek.dev

Tracking launch weeks across the industry, for product discovery and inspiration.
JavaScript
3
star
75

.github

Supabase Community
3
star
76

core-swift

Shared interfaces and helpers for Swift libraries
Swift
2
star
77

supa-jam

TypeScript
2
star
78

nftree-garden

Mint an NFT, plant a Tree!
JavaScript
1
star
79

realtime-go

1
star
80

functions-rs

Rust
1
star
81

squad

1
star
82

gotrue-php

PHP
1
star
83

storage-php

PHP
1
star
84

postgrest-php

PHP
1
star
85

deno-storage-js

Repo to overwrite https://deno.land/x/storagee listing.
1
star
86

supabase-fastify-api

TypeScript
1
star
87

gotrue-fsharp

F# client for interacting with Supabase GoTrue
F#
1
star
88

realtime-php

1
star
89

core-py

Shared interfaces and helpers for the supabase-py libs
Python
1
star
90

hacktoberfest-hackathon-template

Template for the Supabase Hacktoberfest Hackathon that follows https://hacktoberfest.digitalocean.com/resources/maintainers
1
star
91

postgrest-java

1
star