Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cc493da6b | ||
|
|
08fc83709c | ||
|
|
92174dc0d2 | ||
|
|
2d72847d39 | ||
|
|
4f7dd12133 | ||
|
|
8b16a1ee33 | ||
|
|
5e9d29e07b | ||
|
|
5113187bb1 | ||
|
|
ef08af359c | ||
|
|
31c3edc183 | ||
|
|
2cfe3651b4 | ||
|
|
1c22b8d429 | ||
|
|
c6956d0ff6 | ||
|
|
4369a5617e |
@@ -3,6 +3,12 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [0.2.12.1] - 2015-11-12
|
||||
|
||||
### Fixed
|
||||
- Correct order for -> and ->> in a json path - @ruslantalpa
|
||||
- Return empty array instead of 500 when a set returning function returns an empty result set - @diogob
|
||||
|
||||
## [0.2.12.0] - 2015-10-25
|
||||
|
||||
### Added
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"POSTGREST_VER": {
|
||||
"description": "Version of PostgREST to deploy",
|
||||
"value": "0.2.12.0"
|
||||
"value": "0.2.12.1"
|
||||
},
|
||||
"DB_NAME": {
|
||||
"description": "Database name",
|
||||
|
||||
+35
-8
@@ -7,7 +7,7 @@ The [release page](https://github.com/begriffs/postgrest/releases/latest) has pr
|
||||
```sh
|
||||
# Untar the release (available at https://github.com/begriffs/postgrest/releases/latest)
|
||||
|
||||
$ tar zxf postgrest-0.2.12.0-osx.tar.xz
|
||||
$ tar zxf postgrest-0.2.12.1-osx.tar.xz
|
||||
|
||||
# Try running it
|
||||
$ ./postgrest
|
||||
@@ -22,13 +22,13 @@ $ ./postgrest
|
||||
|
||||
<ul><li>Scientific Linux 6</li><li>CentOS</li><li>RHEL 6</li></ul>
|
||||
|
||||
Also it would be good to create packages for Homebrew, and apt.</p>
|
||||
Also it would be good to create a package for apt.</p>
|
||||
</div>
|
||||
|
||||
We'll learn the meaning of the command line flags later, but here is a minimal example of running the app. It does all operations as user `postgres`, including for unauthenticated requests.
|
||||
|
||||
```sh
|
||||
$ ./postgrest -d dbname -U postgres --a postgres --v1schema public
|
||||
$ ./postgrest -d dbname -U postgres -a postgres --v1schema public
|
||||
```
|
||||
|
||||
### Building from Source
|
||||
@@ -36,27 +36,54 @@ $ ./postgrest -d dbname -U postgres --a postgres --v1schema public
|
||||
When a prebuilt binary does not exist for your system you can build the project from source. You'll also need to do this if you want to help with development. [Stack](https://github.com/commercialhaskell/stack) makes it easy. It will install any necessary Haskell dependencies on your system.
|
||||
|
||||
* [Install Stack](https://github.com/commercialhaskell/stack#how-to-install) for your platform
|
||||
* Build the project
|
||||
```bash
|
||||
#ubuntu example
|
||||
wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -
|
||||
echo 'deb http://download.fpcomplete.com/ubuntu/trusty stable main'|sudo tee /etc/apt/sources.list.d/fpco.list
|
||||
sudo apt-get update && sudo apt-get install stack -y
|
||||
```
|
||||
* Build & install in one step
|
||||
|
||||
```bash
|
||||
git clone https://github.com/begriffs/postgrest.git
|
||||
cd postgrest
|
||||
stack build
|
||||
sudo stack install --install-ghc --local-bin-path /usr/local/bin
|
||||
```
|
||||
|
||||
* Run the server
|
||||
|
||||
```bash
|
||||
stack exec postgrest -- arg1 arg2
|
||||
# ... your arguments after the double dashes
|
||||
postgrest dbconnectionstring arg1 arg2
|
||||
```
|
||||
|
||||
If you want to run the test suite, stack can do that too: `stack test`.
|
||||
|
||||
### Install via Homebrew (Mac OS X)
|
||||
|
||||
You can use the Homebrew package manager to install PostgREST on Mac
|
||||
|
||||
```bash
|
||||
# Ensure brew is up to date
|
||||
brew update
|
||||
|
||||
# Check for any problems with brew's setup
|
||||
brew doctor
|
||||
|
||||
# Install the postgrest package
|
||||
brew install postgrest
|
||||
```
|
||||
|
||||
This will automatically install PostgreSQL as a dependency (see the [Installing PostgreSQL](#installing-postgresql) section for setup instructions). The process tends to take around 15 minutes to install the package and its dependencies.
|
||||
|
||||
After installation completes, the tool is added to your $PATH and can be used from anywhere with:
|
||||
|
||||
```bash
|
||||
postgrest --help
|
||||
```
|
||||
|
||||
### Installing PostgreSQL
|
||||
|
||||
To use PostgREST you will need an underlying database. You can use something like Amazon [RDS](https://aws.amazon.com/rds/) but installing your own locally is cheaper and more convenient for development.
|
||||
|
||||
* [Instructions for OS X](http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/)
|
||||
* [Instructions for Ubuntu 14.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04)
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ name: postgrest
|
||||
description: Reads the schema of a PostgreSQL database and creates RESTful routes
|
||||
for the tables and views, supporting all HTTP verbs that security
|
||||
permits.
|
||||
version: 0.2.12.0
|
||||
version: 0.2.12.1
|
||||
synopsis: REST API for any Postgres database
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
|
||||
@@ -18,6 +18,7 @@ import Data.Tree
|
||||
import Network.Wai (Request, pathInfo, queryString)
|
||||
import PostgREST.Types
|
||||
import Text.ParserCombinators.Parsec hiding (many, (<|>))
|
||||
|
||||
parseGetRequest :: Request -> Either ParseError ApiRequest
|
||||
parseGetRequest httpRequest =
|
||||
foldr addFilter <$> (addOrder <$> apiRequest <*> ord) <*> flts
|
||||
@@ -77,7 +78,7 @@ lexeme p = ws *> p <* ws
|
||||
pTreePath :: Parser (Path,Field)
|
||||
pTreePath = do
|
||||
p <- pFieldName `sepBy1` pDelimiter
|
||||
jp <- optionMaybe ( string "->" >> pJsonPath)
|
||||
jp <- optionMaybe pJsonPath
|
||||
let pp = map cs p
|
||||
jpp = map cs <$> jp
|
||||
return (init pp, (last pp, jpp))
|
||||
@@ -98,14 +99,14 @@ pFieldName :: Parser Text
|
||||
pFieldName = cs <$> (many1 (letter <|> digit <|> oneOf "_")
|
||||
<?> "field name (* or [a..z0..9_])")
|
||||
|
||||
pJsonPathDelimiter :: Parser Text
|
||||
pJsonPathDelimiter = cs <$> (try (string "->>") <|> string "->")
|
||||
pJsonPathStep :: Parser Text
|
||||
pJsonPathStep = cs <$> try (string "->" *> pFieldName)
|
||||
|
||||
pJsonPath :: Parser [Text]
|
||||
pJsonPath = pFieldName `sepBy1` pJsonPathDelimiter
|
||||
pJsonPath = (++) <$> many pJsonPathStep <*> ( (:[]) <$> (string "->>" *> pFieldName) )
|
||||
|
||||
pField :: Parser Field
|
||||
pField = lexeme $ (,) <$> pFieldName <*> optionMaybe ( pJsonPathDelimiter *> pJsonPath)
|
||||
pField = lexeme $ (,) <$> pFieldName <*> optionMaybe pJsonPath
|
||||
|
||||
pSelect :: Parser SelectItem
|
||||
pSelect = lexeme $
|
||||
|
||||
@@ -116,7 +116,7 @@ asJsonWithCount = withCount . asJson
|
||||
asJson :: StatementT
|
||||
asJson s = s {
|
||||
B.stmtTemplate =
|
||||
"array_to_json(array_agg(row_to_json(t)))::character varying from ("
|
||||
"array_to_json(coalesce(array_agg(row_to_json(t)), '{}'))::character varying from ("
|
||||
<> B.stmtTemplate s <> ") t" }
|
||||
|
||||
withCount :: StatementT
|
||||
|
||||
@@ -296,12 +296,15 @@ spec =
|
||||
describe "jsonb" $ do
|
||||
it "can filter by properties inside json column" $ do
|
||||
get "/json?data->foo->>bar=eq.baz" `shouldRespondWith`
|
||||
[json| [{"data": {"foo": {"bar": "baz"}}}] |]
|
||||
[json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |]
|
||||
get "/json?data->foo->>bar=eq.fake" `shouldRespondWith`
|
||||
[json| [] |]
|
||||
it "can filter by properties inside json column using not" $
|
||||
get "/json?data->foo->>bar=not.eq.baz" `shouldRespondWith`
|
||||
[json| [] |]
|
||||
it "can filter by properties inside json column using ->>" $
|
||||
get "/json?data->>id=eq.1" `shouldRespondWith`
|
||||
[json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |]
|
||||
|
||||
describe "remote procedure call" $ do
|
||||
context "a proc that returns a set" . before_ (clearTable "items" >> createItems 10) .
|
||||
@@ -310,6 +313,11 @@ spec =
|
||||
post "/rpc/getitemrange" [json| { "min": 2, "max": 4 } |] `shouldRespondWith`
|
||||
[json| [ {"id": 3}, {"id":4} ] |]
|
||||
|
||||
context "a proc that returns an empty rowset" $
|
||||
it "returns empty json array" $
|
||||
post "/rpc/test_empty_rowset" [json| {} |] `shouldRespondWith`
|
||||
[json| [] |]
|
||||
|
||||
context "a proc that returns plain text" $
|
||||
it "returns proper json" $
|
||||
post "/rpc/sayhello" [json| { "name": "world" } |] `shouldRespondWith`
|
||||
|
||||
+3
-1
@@ -184,4 +184,6 @@ createJsonData = do
|
||||
[H.stmt|
|
||||
insert into "1".json (data) values (?)
|
||||
|]
|
||||
(J.object [("foo", J.object [("bar", J.String "baz")])])
|
||||
(J.object [("id", J.Number 1)
|
||||
,("foo", J.object [("bar", J.String "baz")])
|
||||
])
|
||||
|
||||
Vendored
+7
-1
@@ -297,7 +297,9 @@ CREATE FUNCTION "1".getitemrange(min bigint, max bigint) RETURNS SETOF "1".items
|
||||
SELECT * FROM "1".items WHERE id > $1 AND id <= $2;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
|
||||
CREATE FUNCTION "1".test_empty_rowset() RETURNS SETOF int AS $$
|
||||
SELECT null::int FROM (SELECT 1) a WHERE false;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION "1".sayhello(name text) RETURNS text AS $$
|
||||
SELECT 'Hello, ' || $1;
|
||||
@@ -663,6 +665,10 @@ REVOKE ALL ON FUNCTION getitemrange(bigint, bigint) FROM postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION getitemrange(bigint, bigint) TO postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION getitemrange(bigint, bigint) TO postgrest_anonymous;
|
||||
|
||||
REVOKE ALL ON FUNCTION test_empty_rowset() FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION test_empty_rowset() FROM postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION test_empty_rowset() TO postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION test_empty_rowset() TO postgrest_anonymous;
|
||||
|
||||
REVOKE ALL ON FUNCTION sayhello(text) FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION sayhello(text) FROM postgrest_test;
|
||||
|
||||
Reference in New Issue
Block a user