forked from pramsey/pgsql-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http--1.4.sql
104 lines (86 loc) · 2.8 KB
/
http--1.4.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION http" to load this file. \quit
CREATE DOMAIN http_method AS text
CHECK (
VALUE ILIKE 'get' OR
VALUE ILIKE 'post' OR
VALUE ILIKE 'put' OR
VALUE ILIKE 'delete' OR
VALUE ILIKE 'patch' OR
VALUE ILIKE 'head'
);
CREATE DOMAIN content_type AS text
CHECK (
VALUE ~ '^\S+\/\S+'
);
CREATE TYPE http_header AS (
field VARCHAR,
value VARCHAR
);
CREATE TYPE http_response AS (
status INTEGER,
content_type VARCHAR,
headers http_header[],
content VARCHAR
);
CREATE TYPE http_request AS (
method http_method,
uri VARCHAR,
headers http_header[],
content_type VARCHAR,
content VARCHAR
);
CREATE OR REPLACE FUNCTION http_set_curlopt (curlopt VARCHAR, value VARCHAR)
RETURNS boolean
AS 'MODULE_PATHNAME', 'http_set_curlopt'
LANGUAGE 'c';
CREATE OR REPLACE FUNCTION http_reset_curlopt ()
RETURNS boolean
AS 'MODULE_PATHNAME', 'http_reset_curlopt'
LANGUAGE 'c';
CREATE OR REPLACE FUNCTION http_list_curlopt ()
RETURNS TABLE(curlopt text, value text)
AS 'MODULE_PATHNAME', 'http_list_curlopt'
LANGUAGE 'c';
CREATE OR REPLACE FUNCTION http_header (field VARCHAR, value VARCHAR)
RETURNS http_header
AS $$ SELECT $1, $2 $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION http(request http_request)
RETURNS http_response
AS 'MODULE_PATHNAME', 'http_request'
LANGUAGE 'c';
CREATE OR REPLACE FUNCTION http_get(uri VARCHAR)
RETURNS http_response
AS $$ SELECT http(('GET', $1, NULL, NULL, NULL)::http_request) $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION http_post(uri VARCHAR, content VARCHAR, content_type VARCHAR)
RETURNS http_response
AS $$ SELECT http(('POST', $1, NULL, $3, $2)::http_request) $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION http_put(uri VARCHAR, content VARCHAR, content_type VARCHAR)
RETURNS http_response
AS $$ SELECT http(('PUT', $1, NULL, $3, $2)::http_request) $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION http_patch(uri VARCHAR, content VARCHAR, content_type VARCHAR)
RETURNS http_response
AS $$ SELECT http(('PATCH', $1, NULL, $3, $2)::http_request) $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION http_delete(uri VARCHAR)
RETURNS http_response
AS $$ SELECT http(('DELETE', $1, NULL, NULL, NULL)::http_request) $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION http_head(uri VARCHAR)
RETURNS http_response
AS $$ SELECT http(('HEAD', $1, NULL, NULL, NULL)::http_request) $$
LANGUAGE 'sql';
CREATE OR REPLACE FUNCTION urlencode(string VARCHAR)
RETURNS TEXT
AS 'MODULE_PATHNAME'
LANGUAGE 'c'
IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION urlencode(string BYTEA)
RETURNS TEXT
AS 'MODULE_PATHNAME'
LANGUAGE 'c'
IMMUTABLE STRICT;