Skip to content

Latest commit

 

History

History
246 lines (173 loc) · 8.33 KB

docs.md

File metadata and controls

246 lines (173 loc) · 8.33 KB

sqlite-path Documentation

A full reference to every function and module that sqlite-url offers.

As a reminder, sqlite-url follows semver and is pre v1, so breaking changes are to be expected.

API Reference

url_version()

Gets the version string of the sqlite-url library.

select url_version(); --> "v0.0.0"

url_debug()

Get debug info of the sqlite-url library.

url(url [, name1, value1], [...])

Generate a URL. The first "url" parameter is a base URL that is parsed, and can be overwritten by the other parameters. If "url" is null or the empty string, Then only the other parameters are used. "name" parameters must be one of the following:

  • "scheme"
  • "host"
  • "path"
  • "query"
  • "fragment"
  • "user"
  • "password"
  • "options"
  • "zoneid"
select url(
  'http://github.com',
  'path', 'asg017/sqlite-url',
  'fragment', 'usage'
);
-- 'http://github.com/asg017/sqlite-url#usage'


select url(
  '',
  'scheme', 'https',
  'host', 'github.com',
  'path', 'asg017/sqlite-url'
);
-- 'https://github.com/asg017/sqlite-url'

url_valid(url, [strict])

Returns 1 if url is a well-formed URL according to libcurl, 0 otherwise.

select url_valid('https://google.com'); -- 1
select url_valid('invalid'); -- 0

url_host(url)

Returns the host portion of the given URL.

select url_host('https://github.com'); -- 'github.com'

url_scheme(url)

Returns the scheme portion of the given URL.

select url_scheme('https://github.com'); -- 'https'
select url_scheme('http://github.com'); -- 'http'

url_path(url)

Returns the path portion of the given URL.

select url_path('https://github.com/asg017/sqlite-url'); -- '/asg017/sqlite-url'

url_query(url)

Returns the query portion of the given URL.

Use with url_query_each to iterate through all escaped items in the resulting query string.

select url_query('https://google.com/books?sort=asc'); -- 'sort=asc'

url_fragment(url)

Returns the fragment portion of the given URL.

select url_fragment('https://google.com#a'); -- 'a'

url_user(url)

Returns the user portion of the given URL.

select url_user('https://admin:password@google.com'); -- 'admin'

url_password(url)

Returns the password portion of the given URL.

select url_password('https://admin:password@google.com'); -- 'password'

url_options(url)

Returns the options portion of the given URL.

Note that despite the name, "options" is a very rare URL part and you probably have very little reason to use this.

select url_options('imap://user:pass;word@host/file'); -- 'word'

url_port(url)

Returns the port portion of the given URL.

select url_port('https://google.com:8080'); -- '8080'

url_zoneid(url)

Returns the zoneid portion of the given URL.

Note that it only seems useful with a small susbset of IPv6 URLs.

select url_zoneid('http://[ffaa::aa%21]/'); -- '21'

url_escape(url)

Escape the given text.

select url_escape('alex garcia, &='); -- 'alex%20garcia%2C%20%26%3D'

url_unescape(contents)

Unescape the given text.

select url_unescape('alex%20garcia%2C%20%26%3D'); -- 'alex garcia, &='

url_querystring(name1, value1, [...])

Generate a query string with the given names and values, based on the urlencoded serializing algorithm. Individual part are automatically escaped.

Use with url()'s query option to generate URLs with query strings.

select url_querystring(
  'q', 'memes',
  'tag', 'Bug Fix'
);
-- 'q=memes&tag=Bug%20Fix'

select url_querystring(
  'q', 'memes',
  'filters', '[{"type":"videos"}]',
  'after', '2022-08-22T16:14:29.077Z'
);
-- 'q=memes&filters=%5B%7B%22type%22%3A%22videos%22%7D%5D&after=2022-08-22T16%3A14%3A29.077Z'

select url(
  'https://github.com/asg017/sqlite-url/issues',
  'query', url_querystring('q', 'foo bar')
);
-- 'https://github.com/asg017/sqlite-url/issues?q=foo%20bar'

select * from url_query_each(query)

Table function that returns each sequence in the given query string. Every sequence in the query string returns its own row, and every name and value are pre-escaped. Based on the urlencoded parsing algorithm.

select *
from url_query_each('q=memes&filters=%5B%7B%22type%22%3A%22videos%22%7D%5D&after=2022-08-22T16%3A14%3A29.077Z');
/*
┌─────────┬──────────────────────────┐
│  name   │          value           │
├─────────┼──────────────────────────┤
│ q       │ memes                    │
│ filters │ [{"type":"videos"}]      │
│ after   │ 2022-08-22T16:14:29.077Z │
└─────────┴──────────────────────────┘
*/

Use url_query() on a full URL before passing along to url_query_each().

select *
from url_query_each(
  url_query('https://www.google.com/search?q=memes&rlz=1C5CHFA_enUS915US915&oq=memes&aqs=chrome..69i57j0i433i512j0i131i433i512j0i512j46i433i512j0i433i512j0i512l2j0i131i433i512j0i512.817j0j7&sourceid=chrome&ie=UTF-8')
);

/*
┌──────────┬──────────────────────────────────────────────────────────────┐
│   name   │                            value                             │
├──────────┼──────────────────────────────────────────────────────────────┤
│ q        │ memes                                                        │
├──────────┼──────────────────────────────────────────────────────────────┤
│ rlz      │ 1C5CHFA_enUS915US915                                         │
├──────────┼──────────────────────────────────────────────────────────────┤
│ oq       │ memes                                                        │
├──────────┼──────────────────────────────────────────────────────────────┤
│ aqs      │ chrome..69i57j0i433i512j0i131i433i512j0i512j46i433i512j0i433 │
│          │ i512j0i512l2j0i131i433i512j0i512.817j0j7                     │
├──────────┼──────────────────────────────────────────────────────────────┤
│ sourceid │ chrome                                                       │
├──────────┼──────────────────────────────────────────────────────────────┤
│ ie       │ UTF-8                                                        │
└──────────┴──────────────────────────────────────────────────────────────┘
*/