Skip to content

Commit cb578ba

Browse files
committed
initial commit
0 parents  commit cb578ba

File tree

9 files changed

+512
-0
lines changed

9 files changed

+512
-0
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
strategy:
16+
matrix:
17+
pg:
18+
- v17
19+
runs-on: namespace-profile-cached-amd64-lg
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: namespacelabs/nscloud-cache-action@v1
23+
with:
24+
path: |
25+
/nix
26+
- uses: cachix/install-nix-action@v31
27+
with:
28+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
29+
extra_nix_config: |
30+
accept-flake-config = true
31+
- uses: cachix/cachix-action@v16
32+
with:
33+
name: willruggiano
34+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
35+
- run: nix flake check
36+
- run: nix build .#${{ matrix.pg }}
37+
- run: nix run .#devenv -- up -D
38+
- run: nix develop -c pg_prove test.sql
39+
- run: nix run .#devenv down

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is for project-specific build artifacts.
2+
# If you have OS-specific or editor-specific files to ignore,
3+
# such as *.swp or .DS_Store, put those in your global
4+
# ~/.gitignore and put this in your ~/.gitconfig:
5+
#
6+
# [core]
7+
# excludesfile = ~/.gitignore
8+
#
9+
# Cheers!
10+
# -rugg
11+
12+
data
13+
result

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# PostgreSQL implementation of JSON Patch
2+
3+
[https://datatracker.ietf.org/doc/html/rfc6902]
4+
5+
```sql
6+
select jsonb_patch(
7+
'{"foo":{"bar":"baz","waldo":"fred"},"qux":{"corge":"grault"}}',
8+
'[{"op":"move","from":"/foo/waldo","path":"/qux/thud"}]'
9+
);
10+
jsonb_patch
11+
---------------------------------------------------------------------
12+
{"foo": {"bar": "baz"}, "qux": {"thud": "fred", "corge": "grault"}}
13+
(1 row)
14+
```
15+
16+
See [./test.sql] for more examples.
17+
I have not yet written tests for A.11-A.15 from the RFC.

flake.lock

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
inputs = {
3+
flake-parts.url = "github:hercules-ci/flake-parts";
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
rust-overlay = {
6+
url = "github:oxalica/rust-overlay";
7+
inputs.nixpkgs.follows = "nixpkgs";
8+
};
9+
process-compose.url = "github:Platonic-Systems/process-compose-flake";
10+
services.url = "github:juspay/services-flake";
11+
};
12+
13+
nixConfig = {
14+
extra-substituters = [
15+
"https://nix-community.cachix.org"
16+
"https://willruggiano.cachix.org"
17+
];
18+
extra-trusted-public-keys = [
19+
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
20+
"willruggiano.cachix.org-1:rz00ME8/uQfWe+tN3njwK5vc7P8GLWu9qbAjjJbLoSw="
21+
];
22+
};
23+
24+
outputs = inputs @ {flake-parts, ...}:
25+
flake-parts.lib.mkFlake {inherit inputs;} {
26+
imports = [
27+
inputs.process-compose.flakeModule
28+
];
29+
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
30+
perSystem = {
31+
config,
32+
self',
33+
inputs',
34+
lib,
35+
pkgs,
36+
system,
37+
...
38+
}: {
39+
devShells.default = pkgs.mkShell {
40+
name = "pg_jsonpatch";
41+
buildInputs = with pkgs; [
42+
postgresql
43+
perlPackages.TAPParserSourceHandlerpgTAP # pg_prove
44+
];
45+
PGDATA = "data/pg1";
46+
PGHOST = "localhost";
47+
PGDATABASE = "postgres";
48+
};
49+
50+
packages = {
51+
default = pkgs.callPackage ./package.nix {inherit (pkgs) postgresql;};
52+
v17 = pkgs.callPackage ./package.nix {postgresql = pkgs.postgresql_17;};
53+
v16 = pkgs.callPackage ./package.nix {postgresql = pkgs.postgresql_16;};
54+
v15 = pkgs.callPackage ./package.nix {postgresql = pkgs.postgresql_15;};
55+
v14 = pkgs.callPackage ./package.nix {postgresql = pkgs.postgresql_14;};
56+
};
57+
58+
process-compose.devenv = {
59+
imports = [
60+
inputs.services.processComposeModules.default
61+
];
62+
63+
cli.options.no-server = false;
64+
65+
services.postgres.default = {
66+
enable = true;
67+
extensions = exts:
68+
with exts; [
69+
config.packages.default
70+
pgtap
71+
];
72+
initialScript.after = ''
73+
create extension pgtap;
74+
'';
75+
package = config.packages.default.postgresql;
76+
settings = {
77+
log_statement = "all";
78+
logging_collector = false;
79+
};
80+
};
81+
};
82+
};
83+
};
84+
}

package.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
postgresql,
3+
lib,
4+
}:
5+
postgresql.stdenv.mkDerivation {
6+
pname = "pg_jsonpatch";
7+
version = "1.0.0";
8+
src = ./.;
9+
dontBuild = true;
10+
installPhase = ''
11+
mkdir -p $out/share/postgresql/extension
12+
cp pg_jsonpatch* $out/share/postgresql/extension
13+
'';
14+
meta = {
15+
description = "PostgreSQL implementation of JSON Patch";
16+
license = lib.licenses.mit;
17+
inherit (postgresql.meta) platforms;
18+
};
19+
passthru = {inherit postgresql;};
20+
}

0 commit comments

Comments
 (0)