Skip to content

Commit 33528c8

Browse files
lexborisovhackorum
authored andcommitted
Add url data type to contrib.
1 parent 086f6f1 commit 33528c8

49 files changed

Lines changed: 13818 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contrib/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ else
9191
ALWAYS_SUBDIRS += hstore_plpython jsonb_plpython ltree_plpython
9292
endif
9393

94+
ifeq ($(with_icu),yes)
95+
SUBDIRS += url
96+
else
97+
ALWAYS_SUBDIRS += url
98+
endif
99+
94100
# Missing:
95101
# start-scripts \ (does not have a makefile)
96102

contrib/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ subdir('test_decoding')
7070
subdir('tsm_system_rows')
7171
subdir('tsm_system_time')
7272
subdir('unaccent')
73+
subdir('url')
7374
subdir('uuid-ossp')
7475
subdir('vacuumlo')
7576
subdir('xml2')

contrib/url/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# contrib/url/Makefile
2+
3+
EXTENSION = url
4+
MODULE_big = url
5+
DATA = url--1.0.sql
6+
REGRESS = url
7+
PGFILEDESC = "url - Uniform Resource Locator data type"
8+
9+
url_objs = lexbor/core/array.o \
10+
lexbor/core/array_obj.o \
11+
lexbor/core/bst.o \
12+
lexbor/core/conv.o \
13+
lexbor/core/diyfp.o \
14+
lexbor/core/dobject.o \
15+
lexbor/core/dtoa.o \
16+
lexbor/core/mem.o \
17+
lexbor/core/memory.o \
18+
lexbor/core/mraw.o \
19+
lexbor/core/plog.o \
20+
lexbor/core/str.o \
21+
lexbor/core/strtod.o \
22+
lexbor/url/url.o
23+
24+
OBJS = url.o $(url_objs)
25+
26+
SHLIB_LINK_INTERNAL = $(ICU_LIBS)
27+
28+
ifdef USE_PGXS
29+
PG_CONFIG = pg_config
30+
PGXS := $(shell $(PG_CONFIG) --pgxs)
31+
include $(PGXS)
32+
else
33+
subdir = contrib/url
34+
top_builddir = ../..
35+
include $(top_builddir)/src/Makefile.global
36+
include $(top_srcdir)/contrib/contrib-global.mk
37+
endif

contrib/url/README

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
URL type for PostgreSQL
2+
---------------------------
3+
4+
To register the new SQL type:
5+
6+
CREATE EXTENSION url;
7+
8+
URL Functions
9+
10+
Function: to_url()
11+
Return Type: url
12+
Description: Returns the value as url.
13+
Example: to_url('https://example.com/'::text)
14+
Result: "https://example.com/"
15+
16+
Function: url_base()
17+
Return Type: url
18+
Description: Returns url on the basis of absolute and relative url.
19+
Example: url_base('https://example.com/a/b/c/d/e/f'::url, '../../x/y/z'::text)
20+
Result: "https://example.com/a/b/c/x/y/z"
21+
22+
Getters
23+
24+
Function: scheme()
25+
Return Type: text
26+
Description: Returns scheme from the url if exists, otherwise NULL.
27+
Example: ('https://example.com/'::url).scheme
28+
Result: "https"
29+
30+
Function: username()
31+
Return Type: text
32+
Description: Returns username from the url if exists, otherwise NULL.
33+
Example: ('https://root:qwerty@example.com/'::url).username
34+
Result: "root"
35+
36+
Function: password()
37+
Return Type: text
38+
Description: Returns password from the url if exists, otherwise NULL.
39+
Example: ('https://root:qwerty@example.com/'::url).password
40+
Result: "qwerty"
41+
42+
Function: host()
43+
Return Type: text
44+
Description: Returns host from the url if exists, otherwise NULL.
45+
Example: ('https://事例.com/'::url).host
46+
Result: "xn--3kq3x.com"
47+
48+
Function: host_unicode()
49+
Return Type: text
50+
Description: Returns host as unicode from the url if exists, otherwise NULL.
51+
Example: ('https://事例.com/'::url).host_unicode
52+
Result: "事例.com"
53+
54+
Function: port()
55+
Return Type: integer
56+
Description: Returns port from the url if exists, otherwise NULL.
57+
Example: ('https://example.com:8080/'::url).port
58+
Result: 8080
59+
60+
Function: path()
61+
Return Type: text
62+
Description: Returns path from the url.
63+
Example: ('https://example.com/path/to/home'::url).path
64+
Result: "/path/to/home"
65+
66+
Function: query()
67+
Return Type: text
68+
Description: Returns query from the url if exists, otherwise NULL.
69+
Example: ('https://example.com?abc=xyz&1=2'::url).query
70+
Result: "abc=xyz&1=2"
71+
72+
Function: fragment()
73+
Return Type: text
74+
Description: Returns fragment from the url if exists, otherwise NULL.
75+
Example: ('https://example.com#comments'::url).fragment
76+
Result: "comments"
77+
78+
79+
Setters
80+
81+
Function: url_scheme_set(url, text)
82+
Return Type: url
83+
Description: Sets a new scheme for the url.
84+
Example: url_scheme_set('https://example.com'::url, 'wss')
85+
Result: "wss://example.com/"
86+
87+
Function: url_username_set(url, text)
88+
Return Type: url
89+
Description: Sets a new username for the url. If the username is NULL or an empty value, it deletes it.
90+
Example: url_username_set('https://root:qwerty@example.com'::url, 'guest')
91+
Result: "https://guest:qwerty@example.com/"
92+
93+
Function: url_password_set(url, text)
94+
Return Type: url
95+
Description: Sets a new password for the url. If the password is NULL or an empty value, it deletes it.
96+
Example: url_password_set('https://root:qwerty@example.com'::url, '12345')
97+
Result: "https://root:12345@example.com/"
98+
99+
Function: url_host_set(url, text)
100+
Return Type: url
101+
Description: Sets a new host for the url.
102+
Example: url_host_set('https://example.com'::url, 'postgresql.org')
103+
Result: "https://postgresql.org/"
104+
105+
Function: url_hostname_set(url, text)
106+
Return Type: url
107+
Description: Sets a new host for the url.
108+
Example: url_hostname_set('https://example.com'::url, 'postgresql.org')
109+
Result: "https://postgresql.org/"
110+
111+
Function: url_port_set(url, text or integer)
112+
Return Type: url
113+
Description: Sets a new port for the url. If the port is NULL or an empty value, it deletes it.
114+
Example: url_port_set('https://example.com:8080'::url, '80')
115+
Result: "https://example.com:80/"
116+
117+
Function: url_path_set(url, text)
118+
Return Type: url
119+
Description: Sets a new path for the url. If the path is NULL or an empty value, it deletes it.
120+
Example: url_path_set('https://example.com/path/to/home'::url, '/a/b/c')
121+
Result: "https://example.com/a/b/c"
122+
123+
Function: url_query_set(url, text)
124+
Return Type: url
125+
Description: Sets a new query for the url. If the query is NULL or an empty value, it deletes it.
126+
Example: url_query_set('https://example.com?abc=xyz'::url, '123=abc')
127+
Result: "https://example.com/?123=abc"
128+
129+
Function: url_fragment_set(url, text)
130+
Return Type: url
131+
Description: Sets a new fragment for the url. If the fragment is NULL or an empty value, it deletes it.
132+
Example: url_fragment_set('https://example.com#comment'::url, 'position')
133+
Result: "https://example.com/#position"
134+
135+
NOTE:
136+
If you pass NULL as url, NULL will be returned.
137+

0 commit comments

Comments
 (0)