ozark

A magical ORM for Nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.2.0
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-09-04 07:26

Tags

Authors

  • George Lemon

Installation

nimble install ozark
choosenim install ozark
git clone https://github.com/openpeeps/ozark

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
ozark - - - - - - -

Dependencies

Package Version Optional
nim >= 2.0.0 No
db_connector >= 0.1.0 No
threading >= 0.2.1 No
openparser >= 0.1.2 No
voodoo >= 0.1.9 No

Source

Repository https://github.com/openpeeps/ozark
Homepage https://github.com/openpeeps/ozark
Registry Source nimble_official

README

Ozark ORM
A magical ORM for the Nim language 👑

nimble install ozark

API reference
Github Actions Github Actions

😍 Key Features

  • [x] Macro-based query builder with a fluent API
  • [x] Compile-time SQL validation & type safety
  • [x] Support for PostgreSQL and SQLite
  • [x] Transactions (withTransaction) with automatic commit/rollback
  • [x] Upserts, batch inserts, aggregates, pagination, raw SQL with bound params
  • [ ] Async query execution (coming soon)
  • [ ] Migration system (coming soon)

[!NOTE] Ozark is still in active development. Expect bugs and breaking changes. Contributions are welcome!

Examples

Connecting to the database

Initialize the database connection with the given parameters

import ozark/database

initOzarkDatabase("localhost", "mydb", "myuser", "mypassword", 5432.Port)

withDB or withDBPool

Use withDB to execute queries then automatically close the connection after the block is executed. Use withDBPool to execute queries using a connection pool for better performance in concurrent scenarios.

withDB do:
  # execute queries here

withDBPool do:
  # execute queries here

withTransaction

Run a block inside a database transaction on a dedicated pooled connection. Commits on success, rolls back when the block raises, and always returns the connection to the pool.

withTransaction do:
  Models.table(Users).insert({...}).exec()
  Models.table(Audit).insert({...}).exec()

Define a Model

Define a model by creating a new type that inherits from Model and specifying the fields with their types. See Ozark's Types documentation for supported field types and options.

import ozark/model

newModel Users:
  id: Serial
  username: Varchar(50)
  name: Varchar(100)
  email: Varchar(100)

newModel Subscription:
  id: Serial
  user_id: Users.id
  plan: Varchar(50)
  status: Varchar(20)
  created_at: TimestampTz
  updated_at: TimestampTz

Create the tables

TO create a database table you can use the prepareTable macro.

withDB do:
  Models.table(Users).prepareTable().exec()

Drop a table

withDB do:
  Models.table(Users).dropTable(cascade = true).exec()

Querying the database

For simple queries, you can use the macro-based query builder. The query builder provides a fluent API for constructing SQL queries in a type-safe way. The generated SQL is validated at compile time to catch errors early.

Insert data

import ozark/query

withDBPool do:
  let id = Models.table(Users).insert({
    name: "John Doe",
    username: "johndoe",
    email: "johndoe@example.com",
  }).execGet() # returns the id of the inserted row

Select Query

withDBPool do:
  let res = Models.table(Users)
                  .select(["name", "email"])
                  .where("name", "John")
                  .get()

Querying with raw SQL

When things are getting too complex for the query builder, you can use rawSQL to write raw SQL queries while still benefiting from compile-time validation & type safety. The rawSQL macro allows you to write raw SQL queries with parameter binding to prevent SQL injection attacks.

Models.table(Users)
      .rawSQL("SELECT * FROM users WHERE name = ?", "Alice")
      .get(Users)

❤ Contributions & Support

OpenCode Switch to Open-Source LLMs via OpenCode GO, choosing from a variety of powerful models such as DeepSeek, Qwen, Kimi, GLM-5, MiniMax, MiMo. 🍕 Use our referral link to get started!

🎩 License

MIT license. Made by Humans from OpenPeeps.
Copyright OpenPeeps & Contributors — All rights reserved.