News for hackers. Stuff that matters.
Re:PostgREST by hudo on Sunday November 03, 2019 @02:53PM (#21436141)
"Object-relational mapping is a leaky abstraction leading to slow imperative code"

So they added REST on top of ORM, few more layers of data transformation and even leakier abstraction, so poor dev doesn't have to worry about "low level" SQL.

I lost count of how many different libs/frameworks i saw that exposed CRUD through HTTP, all failed miserably, because it is actually very dumb idea.

Re:PostgREST by ruslan_talpa on Sunday November 03, 2019 @02:59PM (#21436172)
postgrest is not (and does not use) a ORM

Postgrest is more like a compiler, it takes one language as input (REST) and outputs another language (SQL) as output.

It has 0 relation to the ORM concept

Re:PostgREST by arithma on Sunday November 03, 2019 @03:05PM (#21436218)
"ORM" is more like a compiler, it takes one language/(api can be seen as a language) as input and outputs another language (SQL) as output.
Re:PostgREST by blondin on Sunday November 03, 2019 @10:07PM (#21438689)
totally in agreement with you here. an ORM could also be viewed as a compiler. the original comment didn't deserve the backlash.
Re:PostgREST by emrhzc on Sunday November 03, 2019 @03:07PM (#21436229)
"PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API." How did you manage to understand the completely opposite from the very first definition?
Re:PostgREST by ruslan_talpa on Sunday November 03, 2019 @03:15PM (#21436278)
Becasue i know the codebase maybe :)? How does the tag line say "postgrest is a ORM" and how am i interpreting it in the exact oposite way?
Re:PostgREST by fiatjaf on Sunday November 03, 2019 @03:38PM (#21436420)
This is nothing like what you're describing.

Postgrest is not an ORM, it just takes rows from your database and sends them to the client.

It encourages you to write SQL. Write a decent SQL schema. Write SQL views on top of that schema to provide the rows to your API. Even write SQL functions to modify the data in reaction to client calls!

If you hate ORMs and love SQL (specially Postgres, because it's amazing) this is the tool you should be using.

Re:PostgREST by hudo on Sunday November 03, 2019 @03:58PM (#21436543)
Postgrest is RRM actually- rest relational mapper.

My point is - exposing db over HTTP (REST, GraphQL, ...) is bad architectural design and idea.

Re:PostgREST by ruslan_talpa on Sunday November 03, 2019 @04:07PM (#21436595)
between postgrest/postgraphile/hasura there are 30k stars, have all those ppl fallend for this "dumb" idea :)?

You say "expose db" and imply that one would directly give access to the core tables and in this way coupling the api to the data model (one should expose only views and stored procedures) and making the api inflexible.

Or are you saying this is insecure, and if so, can you describe how one would "break" this?

Re:PostgREST by shantly on Sunday November 03, 2019 @04:49PM (#21436897)
> My point is - exposing db over HTTP (REST, GraphQL, ...) is bad architectural design and idea.

I'm with you that exposing a fairly free-form query language over HTTP seems like something that's gonna bite several someones in the ass pretty hard at some point (GraphQL) but what's that got to do with PostgREST?

Re:PostgREST by ruslan_talpa on Sunday November 03, 2019 @05:20PM (#21437125)
actually .... :) Postgrest has the same "capabilities" as GraphQL so if one is not carefull and jsut (naively) exposes tables with millions of rows with just postgrest (and no propper indexes) it can get bad fast since the client could create queries that join and return a lot of data.

That's why one does not deploy postgrest alone but use it in a setting like this https://github.com/subzerocloud/postgrest-starter-kit

where you at the proxy level can say things like "return 400 if the client did not provide at least 2 filters for the table" or "allow filtering on column a and b because they have indexes but not on c"

But again, those are things to consider when you have datasets exceding hundreds of K or millions, you don't need to care about this when you have tables with 10s of Ks

Re:PostgREST by shantly on Sunday November 03, 2019 @08:14PM (#21438117)
Well sure they have the same capabilities from a certain perspective, in that both ultimately send data from a database to a client, but GraphQL does this entirely through a fairly free-form query language with either auto-generated or custom mapping code to turn that into DB queries (though in all cases it has to handle a fairly flexible query set or "shape", or else what's the point of using GraphQL), while PostgREST requires views and stored procedures to handle all but the most trivial cases. I think the latter's way less likely than the former to cause unexpected problems or force tons of defensive coding and cause anxious, sleepless nights—PostgREST seems to me closer to what's normal for any more traditional DB-to-HTTP-client CRUD glueware (Rails, Django—like 99% of the dynamic web, really) when it comes to inherent risk factor.

Exposing a poorly-indexed table can happen in any ol' Rails API app with the usual lazy 3-line controller methods bouncing about its codebase—that's the same level of risk in any system using a database, more or less. I don't see PostgREST as being more likely to cause that to happen. GraphQL's trickier, especially from a performance perspective, because the scope of a query is so hard to determine or account for up-front, and it's hard to confidently answer the question "what's the largest possible scope of a request to this endpoint?".

Re:PostgREST by ruslan_talpa on Monday November 04, 2019 @12:04AM (#21439167)
Have you looked into postgrest's "select" parameter? Your comment about the "scope" of the query applies here too.

Also GraphQL is a protocol and you can't really say it will have poor performance, it all depends on the specific implementation of a particular schema. You can have a GraphQL schema where each query gets translated into a single sql query [1] jsut like with postgrest. One thing that is true is that the reference implementation for graphql servers (but only because it has to be general) pushes one in a direction where a single graphql request might generate a storm of sql queries but it's on developer to understand and write proper resolvers.

[1] https://github.com/subzerocloud/subzero-starter-kit

Re:PostgREST by cerberusss on Sunday November 03, 2019 @04:06PM (#21436591)
So what is the alternative that you propose?
Re:PostgREST by michelpp on Sunday November 03, 2019 @05:09PM (#21437057)
> I lost count of how many different libs/frameworks i saw that exposed CRUD through HTTP, all failed miserably, because it is actually very dumb idea.

The whole point of HTTP is CRUD (Create Read Update Delete). PostgREST maps the HTTP Methods POST/GET/PATCH/DELETE to SQL's INSERT/SELECT/UPDATE/DELETE.

Re:PostgREST by steve-chavez on Sunday November 03, 2019 @11:46PM (#21439113)
PostgREST actually pushes you to know your PostgreSQL. It aims to be a transparent, yet safe/sandboxed, layer over PostgreSQL.

The generated SQL statements over HTTP requests are there to help reduce SQL boilerplate but you're expected to write custom views, functions, triggers, constraints, etc and understand "low level" pg.

Re:PostgREST by cargoshipit on Monday November 04, 2019 @12:03PM (#21443664)
This is a direct mapping of the schema into a REST format to be consumed by frontend applications. It doesn't get much "SQL"ier as far as the frontend is concerned. What alternative would you present?