No description
Find a file
2025-11-30 22:44:25 -04:00
.github/workflows Update build.yml 2024-12-04 17:23:45 -04:00
.lsp Added basic datatypes definitions 2021-01-12 20:56:50 -04:00
src removing query builder 2025-11-30 22:44:25 -04:00
.gitignore update 2024-11-12 13:51:26 -03:00
.sql adding build_extension binary 2021-04-27 19:50:27 -04:00
banner.jpg update 2024-12-03 15:18:51 -03:00
pgxcrown.nimble feat: upgrading pgxcrown to v0.9.5 2025-04-30 22:22:11 -04:00
README.md update 2024-12-03 15:18:56 -03:00

Pgxcrown

Build Postgres Extensions in Nim.

Requisites

  • Postgres with CLI tools installed and running locally
  • Nim

Usage

Install

nimble install

Create a pgxcrown project

  • This command will create your project structure:
pgxtool create-project test

Write your code into main.nim

proc add_one*(a: int): int =
  a + 1

Build a dynamic library

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.

Call your library function from Postgresql

-- 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

Contributing

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.

License

MIT