Build Postgres Extensions in Nim.
- Postgres with CLI tools installed and running locally
- Nim
nimble install
- This command will create your project structure:
pgxtool create-project test
proc add_one*(a: int): int =
a + 1
pgxtool build-extension test
Linux:
cp *.so $(pg_config --pkglibdir)
Windows:
- Windows may not add all Postgres CLI tools to PATH by default(?)
- Locate
pg_config.exe
in the folders"C:\Program Files\PostgreSQL\"
. - Run it in a terminal like so
pg_config.exe --pkglibdir
to get the pkglibdir path. - See
pgconfigFinder()
function source code as hint. - Check if you have development header files ("postgres.h", "spi.h", "analyze.h", "elog.h").
- See Windows CI builds for more.
-- Enter into psql and create a function to wrap your library function
-- omit library extension.
create function function_name(params) return data_type as
'{libname}', '{function}'
language c strict;
-- Example
create function nim_add_one(integer) return integer as
'libadd_one', 'pgx_add_one'
language c strict;
select nim_add_one(10); # -> 11
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.