No description
Find a file
2025-06-23 16:36:29 -04:00
docker feature: adding dockerfile 2025-06-22 23:43:00 -04:00
src fix: adding missing text datatype 2025-06-23 16:36:29 -04:00
LICENSE Update LICENSE 2025-06-19 15:14:31 -04:00
plnim.nimble feat: adding pgxcrown v0.9.0 support 2025-03-25 16:57:47 -04:00
README.md Update README.md 2025-06-22 23:58:16 -04:00

plnim

Use Nim as a Procedural Language for PostgreSQL

Overview

plnim is a PostgreSQL language handler that lets you write PostgreSQL functions and procedures in the Nim programming language. Built on top of pgxcrown, plnim offers a modern, safe, and productive way to extend your database.


Features

🚀 Nim-Powered PostgreSQL Functions & Procedures

  • Write PostgreSQL functions and procedures directly in Nim.
  • Leverage Nims static typing and modern programming features for database development.

🛡️ Safety & Security by Design

  • Built on pgxcrown, plnim enforces the use of safe, pure Nim code:
    • Only allows trusted mode (cannot run in PostgreSQLs untrusted mode).
    • Functions are pure by design—no heap allocations, no global state, and no side effects.
    • Compile-time checks help prevent common bugs and vulnerabilities.

🛠️ Simple and Familiar Workflow

  • Easy installation with Nimble and clear setup instructions.
  • Automatic type mapping and glue code generation—focus on your logic.

🌐 Cross-Platform Support

  • Works on Linux, Windows, and WSL (Windows Subsystem for Linux).
  • Handles platform-specific deployment details for you.

💡 Open Source & Community-Friendly

  • MIT Licensed.
  • Welcomes issues, discussions, and contributions!

Quick Start


🚩 Try plnim instantly without installing Nim! (Perfect for curious developers)

Dont have Nim installed? No worries!

You can try plnim right away using Docker:

# Download the Dockerfile from this repository
curl -O https://raw.githubusercontent.com/luisacosta828/plnim/master/docker/Dockerfile

# Build the Docker image
docker build -t plnim-demo -f Dockerfile .

# Start PostgreSQL with plnim ready to use
docker run --rm -p 5432:5432 plnim-demo

Thats it! You can now connect to PostgreSQL and start experimenting with Nim functions without setting up anything locally.


1. Install Nim and PostgreSQL

Ensure you have Nim and PostgreSQL installed.

2. Install plnim

nimble install pgxcrown
nimble install plnim

3. Register plnim in PostgreSQL

(Setup instructions for enabling plnim as a language handler will go here—see documentation or examples.)

4. Write Nim Functions and Procedures

CREATE FUNCTION nim_add_one(a integer) RETURNS integer
AS $$
  return a + 1
$$ LANGUAGE plnim;

SELECT nim_add_one(10); -- returns 11

Security & Safety

  • Pure Functions: By enforcing Nims func (pure procedure) discipline, plnim prevents unsafe operations, memory leaks, and other vulnerabilities.
  • Strict PostgreSQL Integration: Functions are registered as STRICT for safe handling of NULLs and argument validation.

Contributing

Pull requests, issues, and feedback are welcome! Please open an issue to discuss any major changes before submitting a PR. Contributions should be well-tested.


License

MIT