Skip to content

Commit 6e0b3bb

Browse files
authored
Add Haskell/PostgREST Implementation (#6162)
* Add Postgrest Test * add stuff * Initial PostgREST Implementation * Initial PostgREST Implementation * Add Haskell/postgrest * Update README.md * Update README.md * remove setup files
1 parent 45bbd85 commit 6e0b3bb

File tree

13 files changed

+238
-0
lines changed

13 files changed

+238
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ env:
4747
- "TESTDIR=Haskell/spock"
4848
- "TESTDIR=Haskell/warp"
4949
- "TESTDIR=Haskell/wizzardo-inline"
50+
- "TESTDIR=Haskell/postgrest"
5051
- 'TESTDIR="Java/act Java/comsat"'
5152
- 'TESTDIR="Java/activeweb Java/armeria Java/baratine Java/bayou Java/blade Java/curacao Java/dropwizard Java/firenio Java/servicetalk Java/voovan"'
5253
- 'TESTDIR="Java/gemini Java/greenlightning Java/grizzly Java/helidon Java/httpserver Java/jetty Java/jlhttp Java/jooby Java/wicket"'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# PostgREST Benchmarking Test
2+
3+
### Test Type Implementation Source Code
4+
5+
* [JSON](src/json.sql)
6+
* [PLAINTEXT](src/plaintext.sql)
7+
* [DB](src/db.sql)
8+
* [QUERY](src/query.sql)
9+
* [CACHED QUERY] Not Implemented
10+
* [UPDATE] Not Implemented
11+
* [FORTUNES](src/fortunes.sql)
12+
13+
## Important Libraries
14+
The tests were run with:
15+
* docker-compose down && docker-compose build && docker-compose up
16+
17+
## Test URLs
18+
### JSON
19+
20+
http://localhost:3000/rpc/json
21+
22+
### PLAINTEXT
23+
24+
http://localhost:3000/rpc/plaintext
25+
26+
### DB
27+
28+
http://localhost:3000/rpc/db
29+
30+
### QUERY
31+
32+
http://localhost:3000/rpc/query?queries=
33+
34+
### CACHED QUERY Not Implemented
35+
36+
http://localhost:8080/cached_query?queries=
37+
38+
### UPDATE Not Implemented
39+
40+
http://localhost:3000/rpc/update?queries=
41+
42+
### FORTUNES
43+
44+
http://localhost:3000/rpc/fortunes.html
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"framework": "postgrest",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/rpc/json",
7+
"plaintext_url": "/rpc/plaintext",
8+
"db_url": "/rpc/db",
9+
"query_url": "/rpc/queries?queries=",
10+
"fortunes_url": "/rpc/fortunes.html",
11+
"port": 3000,
12+
"approach": "Realistic",
13+
"classification": "Micro",
14+
"database": "postgres",
15+
"framework": "PostgREST",
16+
"language": "Haskell",
17+
"flavor": "None",
18+
"orm": "Full",
19+
"platform": "None",
20+
"webserver": "None",
21+
"os": "Linux",
22+
"database_os": "Linux",
23+
"display_name": "PostgREST",
24+
"notes": "",
25+
"versus": "None"
26+
}
27+
}
28+
]
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
tfb-database:
4+
build:
5+
dockerfile: postgresql.dockerfile
6+
context: .
7+
environment:
8+
- POSTGRES_PASSWORD=benchmarkdbpass
9+
- POSTGRES_USER=benchmarkdbuser
10+
- POSTGRES_DB=hello_world
11+
web:
12+
build:
13+
dockerfile: postgrest.dockerfile
14+
context: .
15+
ports:
16+
- 3030:3000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM postgres:latest
2+
3+
RUN mkdir -p /docker-entrypoint-initdb.d
4+
COPY src/*.sql /docker-entrypoint-initdb.d/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM postgrest/postgrest:latest
2+
3+
FROM alpine
4+
RUN apk add postgresql-client bash
5+
6+
COPY --from=0 /usr/local/bin/postgrest /usr/local/bin/postgrest
7+
COPY --from=0 /etc/postgrest.conf /etc/postgrest.conf
8+
9+
ENV PGRST_DB_SCHEMA=public
10+
ENV PGRST_DB_ANON_ROLE=
11+
ENV PGRST_DB_POOL=100
12+
ENV PGRST_DB_POOL_TIMEOUT=10
13+
ENV PGRST_DB_EXTRA_SEARCH_PATH=public
14+
ENV PGRST_DB_CHANNEL=pgrst
15+
ENV PGRST_DB_CHANNEL_ENABLED=false
16+
ENV PGRST_SERVER_HOST=*4
17+
ENV PGRST_SERVER_PORT=3000
18+
ENV PGRST_OPENAPI_SERVER_PROXY_URI=
19+
ENV PGRST_JWT_SECRET=
20+
ENV PGRST_SECRET_IS_BASE64=false
21+
ENV PGRST_JWT_AUD=
22+
ENV PGRST_MAX_ROWS=
23+
ENV PGRST_PRE_REQUEST=
24+
ENV PGRST_ROLE_CLAIM_KEY=.role
25+
ENV PGRST_ROOT_SPEC=
26+
ENV PGRST_RAW_MEDIA_TYPES=
27+
28+
ENV PGRST_DB_URI=postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world
29+
ENV PGRST_DB_SCHEMA=public
30+
ENV PGRST_DB_ANON_ROLE=benchmarkdbuser
31+
ENV PGRST_RAW_MEDIA_TYPES="text/html, text/plain"
32+
ENV PGRST_DB_POOL=64
33+
RUN mkdir /app
34+
COPY src /app
35+
RUN chmod +x /app/entrypoint.sh
36+
WORKDIR /app
37+
ENTRYPOINT [ "/app/entrypoint.sh" ]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
create or replace function db() returns json as $$
3+
SELECT json_build_object('id', id, 'randomNumber', randomNumber) from (SELECT ((random()*9999)::int+1) as rnd) g JOIN "World" ON id = rnd;
4+
$$ language sql volatile;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
touch /root/.pgpass
3+
chmod 600 /root/.pgpass
4+
echo tfb-database:5432:hello_world:benchmarkdbuser:benchmarkdbpass >> /root/.pgpass
5+
cat *.sql | psql -U benchmarkdbuser -h tfb-database -d hello_world
6+
/usr/local/bin/postgrest /etc/postgrest.conf > /dev/null 2>&1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CREATE TYPE fortune_t AS (id int, message text);
2+
3+
create or replace function fortune_template(f fortune_t) returns text as $$
4+
SELECT format('<tr><td>%s</td><td>%s</td></tr>', $1.id, regexp_replace($1.message, '<', '&lt;','g'));
5+
$$ language sql volatile;
6+
7+
create or replace function fortunes_template(fortunes fortune_t[]) returns text as $$
8+
WITH header AS (
9+
SELECT 0 as id,'<!DOCTYPE html>
10+
<html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>' as html
11+
), footer AS (
12+
SELECT 2,'</table></body></html>' as html
13+
), fortunes AS (
14+
SELECT unnest as fortune from unnest($1)
15+
), additional AS (
16+
SELECT (-1, 'Additional fortune added at request time.')::fortune_t as f
17+
), all_fortunes AS (
18+
SELECT * from (SELECT * FROM fortunes UNION ALL SELECT * from additional) p ORDER BY (fortune).message
19+
), fortunes_html AS (
20+
SELECT 1,string_agg(fortune_template(fortune), '') from all_fortunes
21+
), html AS (
22+
SELECT * FROM header UNION SELECT * FROM fortunes_html UNION SELECT * from footer ORDER BY id
23+
)
24+
SELECT string_agg(html,'') from html;
25+
$$ language sql volatile;
26+
27+
create or replace function "fortunes.html"() returns bytea as $$
28+
DECLARE
29+
fortunes fortune_t[];
30+
BEGIN
31+
SET LOCAL "response.headers" = '[{"Content-Type": "text/html"}]';
32+
SELECT array_agg(CAST((id,message) AS fortune_t)) FROM "Fortunes" INTO fortunes;
33+
RETURN convert_to(fortunes_template(fortunes), 'UTF8');
34+
END
35+
$$ language plpgsql volatile;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
create function json() returns json as $$
2+
SELECT json_build_object('message', 'Hello, World!');
3+
$$ language sql volatile;

0 commit comments

Comments
 (0)