Git Product home page Git Product logo

postgrest's Issues

handle bulk POST

If the post contains an array of objects, write them to the db all at once.

Use query params to filter

/:table?col=val&col2=val2

I was thinking that if { col1...coln } constitute a (possibly compound) primary key then the response would be a single object rather than an array.

Make a bespoke fixture sql

Right now test/fixtures/schema.sql is a postgres dump and includes commands that cause unnecessary code churn and merge conflicts as we work. We should rewrite it all with clean hand-written sql and continue to modify it that way.

handle PUT

To /items?primary_key=bla

If the primary key does not yet exist this should create the record. All columns must be specified in the payload. If they are not, the server should return a 400 with a body explaining they attempted a non-idempotent action with a PUT.

Schema return value

The response currently looks like this:

{"pkey":["id"],"columns":{"lastname":{"precision":null,"updatable":true,"schema":"1","name":"lastname","type":"character varying","maxLen":255,"nullable":true,"position":2},"firstname":{"precision":null,"updatable":true,"schema":"1","name":"firstname","type":"character varying","maxLen":255,"nullable":true,"position":1}

It would be helpful for columns to return an array since I don't know the column names in advance.

CORS middleware obliterates body for OPTIONS

@DrBoolean discovered that when his app requests OPTIONS /table with cors headers he doesn't get back the table structure JSON but instead gets a blank body. Looks like wai-cors is interfering. @adambaker is there a way to configure the middleware to pass the body through?

handle POST

POST /items should return 201 with location header pointing at the url of the created item (e.g. /items?primary_key=bar).

Query params are not permitted. To replace an existing resource use PUT. To update multiple, use PATCH. If params are provide the server should send a 400 response.

We'll handle 202 (accepted) delayed creation in a different issue.

Authentication and authorization

Authorization will use a designated schema, with a designated table to authenticate users. Eventually, we would like this table to be general enough to support most common authentication strategies. For this feature, we will support username/password authentication. This table will have:

  1. identifier
  2. encrypted password
  3. salt
  4. authorization role.

For authorization, we'll have each request authenticate, then before executing any action specified by the request, change roles to the role recovered from column 4 above, and then reset the role on the connection at the end of the request.

Insert where clause before offset and limit

Currently it selects a range from the table and then applies the where clause to that sub-range. It should apply the where clause to the whole table and then apply the range.

Output RAML for schema info

For the OPTIONS verb we should be outputting an industry standard to say the type of the response json as well as the parameters and versions accepted.

Combine populateSql call with query execution for speed

populateSql :: Connection -> QuotedSql -> IO String

is what was once called pgFormat. As you can see it returns a string of the sql ready to execute. We could make a populateAndExecSql function that executes it as an embedded query to save on db roundtrips.

Fix Location link in post to db lacking a primary key

It's possible to have such a table in postgres. I added a demo table called no_pk to the testing fixture which we can use to test this feature. Right now posts to this table work, but the Location header link replies with /no_pk? because the query params are generated from the (possibly compound) primary key. I am thinking the best solution is to include every single column as a constraint in the link. Even though it may return more than one row, it is the best we can do.

Return 404 for unknown table

Currently it gives a 400 with postgres error

execute: PGRES_FATAL_ERROR: ERROR:  relation "1.foo" does not exist
LINE 1: ...n(array_agg(row_to_json(t))) from ( select * from "1".foo  L...
                                                             ^

If we add an exception catching middleware we can detect the particular code for this error and do it there.

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.