-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix postgrest #10064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cptwunderlich
wants to merge
9
commits into
TechEmpower:master
Choose a base branch
from
cptwunderlich:fix-postgrest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix postgrest #10064
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
42db162
Fix response media type for plaintext.
6b9e185
raw-media-types option was removed.
29ad9e4
Rename json route, as json is a reserved keyword.
fa129f0
Use stricter stability modifiers.
7c953c8
Rename update path according to wiki
6f10c2d
Minor improvement to docker-compose file.
3ad10a3
Minor changes.
d197ee3
Fix fortunes benchmark.
2da83a7
Add clarifying comment for content-type.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
CREATE TYPE fortune_t AS (id int, message text); | ||
create domain "text/html" as text; | ||
|
||
create or replace function fortune_template(f fortune_t) returns text as $$ | ||
SELECT format('<tr><td>%s</td><td>%s</td></tr>', $1.id, regexp_replace($1.message, '<', '<','g')); | ||
$$ language sql volatile; | ||
create or replace function sanitize_html(text) returns text as $$ | ||
select replace(replace(replace(replace(replace($1, '&', '&'), '"', '"'),'>', '>'),'<', '<'), '''', ''') | ||
$$ language sql immutable; | ||
|
||
create or replace function fortunes_template(fortunes fortune_t[]) returns text as $$ | ||
WITH header AS ( | ||
SELECT 0 as id,'<!DOCTYPE html> | ||
<html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>' as html | ||
), footer AS ( | ||
SELECT 2,'</table></body></html>' as html | ||
), fortunes AS ( | ||
SELECT unnest as fortune from unnest($1) | ||
), additional AS ( | ||
SELECT (-1, 'Additional fortune added at request time.')::fortune_t as f | ||
), all_fortunes AS ( | ||
SELECT * from (SELECT * FROM fortunes UNION ALL SELECT * from additional) p ORDER BY (fortune).message | ||
), fortunes_html AS ( | ||
SELECT 1,string_agg(fortune_template(fortune), '') from all_fortunes | ||
), html AS ( | ||
SELECT * FROM header UNION SELECT * FROM fortunes_html UNION SELECT * from footer ORDER BY id | ||
) | ||
SELECT string_agg(html,'') from html; | ||
$$ language sql volatile; | ||
create or replace function fortune_template("Fortune") returns text as $$ | ||
SELECT format('<tr><td>%s</td><td>%s</td></tr>', $1.id, sanitize_html($1.message)); | ||
$$ language sql immutable; | ||
|
||
create or replace function "fortunes.html"() returns bytea as $$ | ||
DECLARE | ||
fortunes fortune_t[]; | ||
BEGIN | ||
SET LOCAL "response.headers" = '[{"Content-Type": "text/html"}]'; | ||
SELECT array_agg(CAST((id,message) AS fortune_t)) FROM "Fortunes" INTO fortunes; | ||
RETURN convert_to(fortunes_template(fortunes), 'UTF8'); | ||
END | ||
$$ language plpgsql volatile; | ||
create or replace function fortunes() returns "text/html" as $$ | ||
-- This is only necessary bc. of the benchmark: The domain gives us content-type: text/html, | ||
-- but the benchmark explicitly tests for the charset in the content-type. | ||
select set_config('response.headers', '[{"Content-Type": "text/html; charset=utf-8"}]', true); | ||
|
||
select '<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>' | ||
|| string_agg(fortune_template(f), NULL order by f.message collate unicode asc) | ||
|| '</table></body></html>' | ||
from (select * from "Fortune" union all select 0, 'Additional fortune added at request time.') f; | ||
$$ language sql volatile; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
create function json() returns json as $$ | ||
create function jsonser() returns json as $$ | ||
SELECT json_build_object('message', 'Hello, World!'); | ||
$$ language sql volatile; | ||
$$ language sql immutable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
create function plaintext() returns text as $$ | ||
create domain "text/plain" as text; | ||
|
||
create function plaintext() returns "text/plain" as $$ | ||
SELECT 'Hello, World!'; | ||
$$ language sql volatile; | ||
$$ language sql immutable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cptwunderlich,
This line shouldn't be necessary. PostgREST will automatically set the content type to the
"text/html"
domain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this adds the type "text/html", but the benchmark harness expects an explicit value of "text/html; charset=UTF-8".
If you remove it, the test fails with:
I can add a comment to clarify.
There are some oddities in this benchmark. E.g., the "updates" benchmark will never work for postgREST, bc. they use a "GET" request for that and you just get a read-only transaction for that in postgrest....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks for clarifying.
Yeah, that is weird on how they landed on GET for this. There are no escape hatches on PostgREST for doing a write in a GET.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the
update
benchmark should just be omittedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, it's not in the config.