Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luisacosta828/pgxcrown
Build Postgres extensions in Nim
https://github.com/luisacosta828/pgxcrown
nim postgres-extensions
Last synced: 4 days ago
JSON representation
Build Postgres extensions in Nim
- Host: GitHub
- URL: https://github.com/luisacosta828/pgxcrown
- Owner: luisacosta828
- Created: 2021-01-10T18:05:34.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-15T15:15:08.000Z (15 days ago)
- Last Synced: 2025-01-15T17:03:51.688Z (15 days ago)
- Topics: nim, postgres-extensions
- Language: Nim
- Homepage:
- Size: 756 KB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pgxcrown
Build Postgres Extensions in Nim.
![](banner.jpg)
# Requisites
- Postgres with CLI tools installed and running locally
- Nim## Usage
### Install
```bash
nimble install
```### Create a pgxcrown project
- This command will create your project structure:
```bash
pgxtool create-project test
```### Write your code into main.nim
```nim
proc add_one*(a: int): int =
a + 1
```### Build a dynamic library
```bash
pgxtool build-extension test
```Linux:
```bash
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.](https://github.com/luisacosta828/pgxcrown/blob/master/.github/workflows/build.yml#L22)### Call your library function from Postgresql
```sql
-- 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](https://choosealicense.com/licenses/mit/)