-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 50acd7c
Showing
10 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ls | ||
pwd | ||
cargo pgx package | ||
cargo pgx package | ||
pgx | ||
cargo | ||
exit |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[target.'cfg(target_os="macos")'] | ||
# Postgres symbols won't be available until runtime | ||
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"] |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.idea/ | ||
/target | ||
/artifacts | ||
*.iml | ||
**/*.rs.bk | ||
Cargo.lock |
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[workspace] | ||
members = ["."] | ||
|
||
[package] | ||
name = "pgurl" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[features] | ||
default = ["pg13"] | ||
pg11 = ["pgx/pg11", "pgx-tests/pg11"] | ||
pg12 = ["pgx/pg12", "pgx-tests/pg12"] | ||
pg13 = ["pgx/pg13", "pgx-tests/pg13"] | ||
pg14 = ["pgx/pg14", "pgx-tests/pg14"] | ||
pg15 = ["pgx/pg15", "pgx-tests/pg15"] | ||
pg_test = [] | ||
|
||
[dependencies] | ||
pgx = { version = "=0.6.1" } | ||
url = "2.3.1" | ||
|
||
[dev-dependencies] | ||
pgx-tests = "=0.6.1" | ||
|
||
[profile.dev] | ||
panic = "unwind" | ||
lto = "thin" | ||
|
||
[profile.release] | ||
panic = "unwind" | ||
opt-level = 3 | ||
lto = "fat" | ||
codegen-units = 1 |
This file contains 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FROM ubuntu:focal | ||
|
||
ARG USER=docker | ||
ARG UID=1000 | ||
ARG GID=1000 | ||
|
||
RUN useradd -m ${USER} --uid=${UID} | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get update && apt-get install -y wget gnupg | ||
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" >> /etc/apt/sources.list.d/pgdg.list | ||
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - | ||
|
||
RUN apt-get update && apt-get install -y curl git | ||
RUN apt-get update && apt-get install -y clang-10 llvm-10 clang gcc make build-essential libz-dev zlib1g-dev strace libssl-dev pkg-config | ||
|
||
RUN apt-get update && apt-get install -y postgresql-11 postgresql-server-dev-11 | ||
RUN apt-get update && apt-get install -y postgresql-12 postgresql-server-dev-12 | ||
RUN apt-get update && apt-get install -y postgresql-13 postgresql-server-dev-13 | ||
RUN apt-get update && apt-get install -y postgresql-14 postgresql-server-dev-14 | ||
RUN apt-get update && apt-get install -y postgresql-15 postgresql-server-dev-15 | ||
RUN apt-get update && apt-get install -y ruby ruby-dev rubygems build-essential | ||
RUN gem install --no-document fpm | ||
|
||
USER ${UID}:${GID} | ||
WORKDIR /home/${USER}/pkg | ||
|
||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y | ||
ENV PATH="/home/${USER}/.cargo/bin:${PATH}" | ||
|
||
RUN cargo install cargo-pgx | ||
RUN cargo pgx init \ | ||
--pg11=/usr/lib/postgresql/11/bin/pg_config \ | ||
--pg12=/usr/lib/postgresql/12/bin/pg_config \ | ||
--pg13=/usr/lib/postgresql/13/bin/pg_config \ | ||
--pg14=/usr/lib/postgresql/14/bin/pg_config \ | ||
--pg15=/usr/lib/postgresql/15/bin/pg_config |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
comment = 'pgurl: Created by pgx' | ||
default_version = '@CARGO_VERSION@' | ||
module_pathname = '$libdir/pgurl' | ||
relocatable = false | ||
superuser = false |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -exu | ||
|
||
OS=$1 | ||
ARCH=$2 | ||
VER=$3 | ||
|
||
docker buildx build --platform="$OS/$ARCH" -f build/ubuntu-focal/Dockerfile -t "pgx-ubuntu-focal-$ARCH" . | ||
|
||
mkdir -p artifacts | ||
|
||
docker run \ | ||
-v "$PWD":/home/docker/pkg \ | ||
-v "$PWD/artifacts":/artifacts \ | ||
-e PG_VERSION="$VER" \ | ||
"pgx-ubuntu-focal-$ARCH" ./scripts/package.sh |
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -exuo | ||
|
||
OSNAME=$(cat /etc/*-release | grep -oE "(DISTRIB_ID=)(.*)" | awk -F= '{print $2}') | ||
VERSION=$(perl -ne 'print "$1\n" if /version\s*=\s*"(.*)"/' Cargo.toml | head -1) | ||
|
||
ARCH=$(uname -m) | ||
ARTIFACTDIR=/artifacts | ||
OUTDIR=/home/docker/pkg/target/release/pgurl-pg${PG_VERSION} | ||
|
||
PG_CONFIG_DIR=$(dirname $(grep ${PG_VERSION} ~/.pgx/config.toml | cut -f2 -d= | cut -f2 -d\")) | ||
export PATH=${PG_CONFIG_DIR}:${PATH} | ||
|
||
rustup update || exit 1 | ||
cargo pgx package || exit $? | ||
|
||
cd $OUTDIR && fpm \ | ||
-s dir \ | ||
-t deb \ | ||
-n pgurl-${PG_VERSION} \ | ||
-v ${VERSION} \ | ||
--deb-no-default-config-files \ | ||
-p ${ARTIFACTDIR}/pgurl_${OSNAME}_pg${PG_VERSION}-${VERSION}_$ARCH.deb \ | ||
-a $ARCH \ | ||
. || exit 1 |
This file contains 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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use pgx::prelude::*; | ||
|
||
pgx::pg_module_magic!(); | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_scheme(url: &str) -> Option<String> { | ||
url::Url::parse(url).ok().map(|u| u.scheme().to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_set_scheme(url: &str, scheme: &str) -> Option<String> { | ||
let mut url = url::Url::parse(url).ok()?; | ||
url.set_scheme(scheme).ok()?; | ||
Some(url.to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_host(url: &str) -> Option<String> { | ||
url::Url::parse(url).ok().and_then(|u| u.host_str().map(|v| v.to_string())) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_set_host(url: &str, host: &str) -> Option<String> { | ||
let mut url = url::Url::parse(url).ok()?; | ||
url.set_host(Some(host)).ok()?; | ||
Some(url.to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_path(url: &str) -> Option<String> { | ||
url::Url::parse(url).ok().map(|u| u.path().to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_set_path(url: &str, path: &str) -> Option<String> { | ||
let mut url = url::Url::parse(url).ok()?; | ||
url.set_path(path); | ||
Some(url.to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_query(url: &str) -> Option<String> { | ||
url::Url::parse(url).ok().and_then(|u| u.query().map(|v| v.to_string())) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_set_query(url: &str, query: &str) -> Option<String> { | ||
let mut url = url::Url::parse(url).ok()?; | ||
url.set_query(Some(query)); | ||
Some(url.to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_fragment(url: &str) -> Option<String> { | ||
url::Url::parse(url).ok().and_then(|u| u.fragment().map(|v| v.to_string())) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_set_fragment(url: &str, query: &str) -> Option<String> { | ||
let mut url = url::Url::parse(url).ok()?; | ||
url.set_fragment(Some(query)); | ||
Some(url.to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_query_param(url: &str, name: &str) -> Option<String> { | ||
let url = url::Url::parse(url).ok()?; | ||
url.query_pairs().find(|q| q.0 == name).map(|v| v.1.to_string()) | ||
} | ||
|
||
#[pg_extern(immutable, parallel_safe)] | ||
fn url_set_query_param(url: &str, name: &str, value: &str) -> Option<String> { | ||
let mut url = url::Url::parse(url).ok()?; | ||
let c = url.clone(); | ||
let q = c.query_pairs(); | ||
|
||
url.query_pairs_mut() | ||
.clear() | ||
.extend_pairs(q.filter(|it| it.0 != name)) | ||
.append_pair(name, value) | ||
.finish(); | ||
|
||
Some(url.to_string()) | ||
} | ||
|
||
#[cfg(any(test, feature = "pg_test"))] | ||
#[pg_schema] | ||
mod tests { | ||
use pgx::prelude::*; | ||
|
||
#[pg_test] | ||
fn test_hello_pgurl() { | ||
assert_eq!(Some("http"), crate::url_scheme("http://abc.com/a").as_deref()); | ||
assert_eq!(Some("abc.com"), crate::url_host("http://abc.com/a").as_deref()); | ||
assert_eq!(Some("/a"), crate::url_path("http://abc.com/a").as_deref()); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod pg_test { | ||
pub fn setup(_options: Vec<&str>) { | ||
// perform one-off initialization when the pg_test framework starts | ||
} | ||
|
||
pub fn postgresql_conf_options() -> Vec<&'static str> { | ||
// return any postgresql.conf settings that are required for your tests | ||
vec![] | ||
} | ||
} |