Questions tagged [postgrest]

PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API. It differs from the other emerging API servers by taking an opinionated stance on the full implementation of API by being operationally sound and simple to deploy, by delivering built-in security with JSON Web Tokens plus database roles, and by fully embracing the relational model.

Introduction

PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations.

Motivation

Using PostgREST is an alternative to manual CRUD programming. Custom API servers suffer problems. Writing business logic often duplicates, ignores or hobbles database structure. Object-relational mapping is a leaky abstraction leading to slow imperative code. The PostgREST philosophy establishes a single declarative source of truth: the data itself.

Declarative Programming

It's easier to ask Postgres to join data for you and let its query planner figure out the details than to loop through rows yourself. It's easier to assign permissions to db objects than to add guards in controllers. (This is especially true for cascading permissions in data dependencies.) It's easier to set constraints than to litter code with sanity checks.

Leakproof Abstraction

There is no ORM involved. Creating new views happens in SQL with known performance implications. A database administrator can now create an API from scratch with no custom programming.

Embracing the Relational Model

In 1970 E. F. Codd criticized the then-dominant hierarchical model of databases in his article A Relational Model of Data for Large Shared Data Banks. Reading the article reveals a striking similarity between hierarchical databases and nested http routes. With PostgREST we attempt to use flexible filtering and embedding rather than nested routes.

One Thing Well

PostgREST has a focused scope. It works well with other tools like Nginx. This forces you to cleanly separate the data-centric CRUD operations from other concerns. Use a collection of sharp tools rather than building a big ball of mud.

136 questions
1
vote
3 answers

supabase flutter get multiple data (JSON object requested, multiple (or no) rows returned)

I am trying to print out multiple data from Supabase using flutter but it just isn't working getResponse(String uid) async { await client .from("privChatRoom") .select() .eq('userID', uid) .single() …
Brightcode
  • 660
  • 9
  • 27
1
vote
0 answers

How can I display data from a PostgreSQL database on a WordPress website?

I am interested in learning how I can create a connection from my PostgreSQL database to my WordPress hosted website in order to build dynamic webpage templates. I have spent a good amount of time researching this topic but I came up short. I hope…
1
vote
1 answer

Vue router - How to open in new tab in production?

I am using Vue, Vuetify and my database is in postgreSQL with an API-backend from postgREST (https://postgrest.org/en/stable/). When using the localhost and hash mode everything is fine locally. I can open the component product in a new tab when…
1
vote
1 answer

CORS Issue with postgREST api on different localhost port then local web app

For a project I am researching postgREST API and applying it to a project being worked on. I simply wanna use the postgREST api in an ajax request from a SpringBoot web app. I am however getting this issue. According to postgREST docs, it will allow…
dybka
  • 43
  • 5
1
vote
1 answer

GET method erroneously working with volatile PostgREST RPC function?

According to the PostgREST v7.0.0 docs, the GET method should only work on RPC functions which are declared with STABLE or IMMUTABLE. However I find that GETs to a function declared VOLATILE PARALLEL UNSAFE seems to work just fine. Anyone know why?
user9645
  • 6,286
  • 6
  • 29
  • 43
1
vote
2 answers

Get vuetify.js checkbox selected values

So I've been trying to get some values from a postgres db with postgREST, show them in a table with vuetify and have checkboxes next to every value so that the user can delete a row from the table. My problem is I don't know how to get the selected…
renaise21
  • 169
  • 2
  • 9
1
vote
2 answers

Function postgreSQL with JSON parameters

I have to create a function that takes an object of this type : "users":"John", "Level":"1", "list":[ {"id":"1", "price1":"100.50", "price2":"90.50"}, {"id":"2", "price1":"100.60", "price2":"80.50"}, {"id":"2",…
MyJobIsHard
  • 25
  • 1
  • 6
1
vote
1 answer

How can I implement dynamic variables into my GET API requests using postgREST and python?

I'm building an API using PostgREST... I'm confused on how-to replicate the query below, more specifically, utilizing the parameters inputted by users = %s. SELECT symbol, date, adj_close FROM api.security_price WHERE security_price.symbol IN %s…
andres
  • 1,558
  • 7
  • 24
  • 62
1
vote
0 answers

React-Admin: TimeRange filter

I'm using React-Admin + ra-data-postgrest + PostgREST + PgSQL to view very large table. Queries to this table MUST be restricted to predefined maximum time range. I was able to implement time range filter using two DateTimeInputs and PostgREST…
1
vote
2 answers

PostgREST JSON field serialisation performance

In Postgres I have a table that I run a function against which returns the top result. This function takes around 2ms to complete without cached data, which is what I need. I then drop PostgREST in the mix, since I need to have an HTTP API that will…
Werner Raath
  • 1,322
  • 3
  • 16
  • 34
1
vote
1 answer

function sign(json, unknown) does not exist

I'm following the tutorial on https://postgrest.org/en/v5.0/auth.html#jwt-from-sql I created this function: create or replace function login(email text, pass text) returns basic_auth.jwt_token language plpgsql as $$ declare _role name; …
stijn.aerts
  • 6,026
  • 5
  • 30
  • 46
1
vote
2 answers

Docker-compose swagger-ui setup which doesn't depend on a particular URL

I want to add swagger-ui to my docker-compose setup. I'm using postgres and postgrest. My setup looks roughly like: version: '3' services: postgrest: image: postgrest/postgrest ports: - 3000:3000 links: - postgres …
Alex Lenail
  • 12,992
  • 10
  • 47
  • 79
1
vote
0 answers

WARNING, running in insecure mode, JWT secret is the default value Listening on port 3000

I have run PostgREST on my machine with Postgresql database : ./postgrest postgres://postgres:DBPASS@localhost:5433/DBNAME --port 3000 --schema public --anonymous postgres --pool 200 It says: WARNING, running in insecure mode, JWT secret is the…
Iwak Teri
  • 11
  • 4
1
vote
0 answers

How to integrate postgREST with Django

I am fairly new to Django and looking for an API to access postres DB in Django. I tried to find the solution for integrating postgREST in my Django project, but couldn't find any solution. I would like to have some direction on how to integrate…
py_dev
  • 43
  • 5
1
vote
1 answer

How to insert a record with id (auto increment) PostgREST?

I have a function axios.post('http://localhost:3000/unitsmeasure', { id: 20, name: 'name' }) .then(function (response) { console.log(response); }) .catch(function (error)…
Vladimir Golub
  • 523
  • 1
  • 8
  • 22