urlpattern
WHATWG-URLPattern-API zum Abgleichen und Extrahieren von URL-Komponenten mit Mustersyntax
Maintainer: teaguesterling
Installation und Laden
INSTALL urlpattern FROM community;LOAD urlpattern;Beispiel
-- Test if a URL matches a patternSELECT urlpattern_test('https://example.com/users/:id', 'https://example.com/users/123');-- true
-- Extract a named group from a URLSELECT urlpattern_extract('https://example.com/users/:id', 'https://example.com/users/123', 'id');-- '123'
-- Get full match results with all componentsSELECT urlpattern_exec('/posts/:slug', '/posts/hello-world');-- {matched: true, pathname: '/posts/hello-world', groups: {slug: 'hello-world'}, ...}
-- Use the URLPATTERN type for validated patternsSELECT urlpattern_test(urlpattern('/api/:version/*'), '/api/v2/users/list');-- trueÜber urlpattern
Die URLPattern-Erweiterung implementiert die WHATWG-URLPattern-API für DuckDB und ermöglicht leistungsfähiges URL-Matching, Extraktion, Parsing und Konstruktion.
Funktionen
- Eigener Typ URLPATTERN mit Validierung und implizitem Casting von VARCHAR
- Musterabgleich mit benannten Gruppen (
:name), Wildcards (*) und Regex-Gruppen - URL-Parsing in Komponenten (protocol, host, path, query, hash)
- URL-Aufbau und Änderung aus Komponenten
- Extraktion von Query-Parametern als MAP oder Einzelwerte
- Muster-Caching für höhere Leistung (~320k Treffer/s)
Wichtige Funktionen
| Function | Description |
|---|---|
urlpattern_test(pattern, url) |
Test if URL matches pattern |
urlpattern_extract(pattern, url, group) |
Extract a named group |
urlpattern_exec(pattern, url) |
Get full match results as STRUCT |
url_parse(url) |
Parse URL into struct with all components |
url_build(...) |
Build URL from named components |
url_modify(url, ...) |
Modify existing URL components |
url_search_params(url) |
Get query parameters as MAP |
Mustersyntax
URLPattern verwendet eine Syntax ähnlich Express.js-Routen:
:name- benannter Parameter (passt auf jedes Segment)*- Wildcard (passt auf alles)/path/:id- reine Pfadmuster passen auf beliebiges Protokoll/Host
Die vollständige Dokumentation finden Sie unter duckdb-urlpattern.readthedocs.io.
Hinzugefügte Funktionen
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| url_build | scalar | NULL | NULL | |
| url_hash | scalar | NULL | NULL | |
| url_host | scalar | NULL | NULL | |
| url_hostname | scalar | NULL | NULL | |
| url_href | scalar | NULL | NULL | |
| url_modify | scalar | NULL | NULL | |
| url_origin | scalar | NULL | NULL | |
| url_parse | scalar | NULL | NULL | |
| url_password | scalar | NULL | NULL | |
| url_pathname | scalar | NULL | NULL | |
| url_port | scalar | NULL | NULL | |
| url_protocol | scalar | NULL | NULL | |
| url_resolve | scalar | NULL | NULL | |
| url_search | scalar | NULL | NULL | |
| url_search_param | scalar | NULL | NULL | |
| url_search_params | scalar | NULL | NULL | |
| url_username | scalar | NULL | NULL | |
| url_valid | scalar | NULL | NULL | |
| urlpattern | scalar | NULL | NULL | |
| urlpattern_exec | scalar | NULL | NULL | |
| urlpattern_extract | scalar | NULL | NULL | |
| urlpattern_hash | scalar | NULL | NULL | |
| urlpattern_hostname | scalar | NULL | NULL | |
| urlpattern_init | scalar | NULL | NULL | |
| urlpattern_pathname | scalar | NULL | NULL | |
| urlpattern_port | scalar | NULL | NULL | |
| urlpattern_protocol | scalar | NULL | NULL | |
| urlpattern_search | scalar | NULL | NULL | |
| urlpattern_test | scalar | NULL | NULL |
Überladene Funktionen
Diese Erweiterung fügt keine Funktionsüberladungen hinzu.
Hinzugefügte Typen
| type_name | type_size | logical_type | type_category | internal |
|---|---|---|---|---|
| URLPATTERN | 16 | VARCHAR | STRING | true |
Hinzugefügte Einstellungen
Diese Erweiterung fügt keine Einstellungen hinzu.