From 739f056b0a45965eaffa064332d1aa6a546e0908 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Thu, 17 Aug 2023 13:06:31 -0500 Subject: [PATCH] nix: add postgrest-repl command --- nix/README.md | 19 ++++++++++++++++++- nix/tools/cabalTools.nix | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/nix/README.md b/nix/README.md index f234cc703..b96984454 100644 --- a/nix/README.md +++ b/nix/README.md @@ -242,7 +242,7 @@ the check resulted in any uncommited changes. It's mostly useful for CI. ## General development tools -Tools like `postgrest-build`, `postgrest-run` etc. are simple wrappers around +Tools like `postgrest-build`, `postgrest-run`, `postgrest-repl` etc. are simple wrappers around `cabal` and should do what you expect. `postgrest-check` runs most checks that will also run in CI, with the exception of the IO and Memory checks that need to be run separately. @@ -256,6 +256,23 @@ run against the latest PostgreSQL version by default. file is changed. For example, `postgrest-watch postgrest-with-all postgrest-test-spec` will re-run the full spec test suite against all PostgreSQL versions on every change. +## REPL + +You can use `postgrest-repl` to manually inspect the PostgREST modules. + +```bash +$ postgrest-repl + +ghci> import PostgREST. +PostgREST.Admin PostgREST.Config.Database PostgREST.Plan.MutatePlan PostgREST.Response.OpenAPI +PostgREST.ApiRequest PostgREST.Config.JSPath PostgREST.Plan.ReadPlan PostgREST.SchemaCache +... + +ghci> import PostgREST.MediaType +ghci> decodeMediaType "application/json" +MTApplicationJSON +``` + ## Tour The following is not required for working on PostgREST with Nix, but it will diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix index 3caee1db3..eb6198058 100644 --- a/nix/tools/cabalTools.nix +++ b/nix/tools/cabalTools.nix @@ -57,6 +57,18 @@ let postgrest "''${_arg_leftovers[@]}" ''; + repl = + checkedShellScript + { + name = "postgrest-repl"; + docs = "Interact with PostgREST modules using the cabal repl"; + args = [ "ARG_LEFTOVERS([cabal v2-repl arguments])" ]; + inRootDir = true; + withEnv = postgrest.env; + } + '' + exec ${cabal-install}/bin/cabal v2-repl "''${_arg_leftovers[@]}" + ''; in buildToolbox { @@ -65,5 +77,6 @@ buildToolbox build clean run + repl ]; }