github.com/luckyframework/avram
1.5.0 / published Apr 22, 2026 / repository
A Crystal database wrapper for reading, writing, and migrating Postgres databases.
Avram
Database ORM built for the Lucky Framework written in Crystal. Supporting PostgreSQL 12+ and based off principals of Elixir Ecto and Rails ActiveRecord.
Why Avram?
The name comes from Henriette Avram.
Henriette Davidson Avram (October 7, 1919 – April 22, 2006) was a computer programmer and systems analyst who developed the MARC format (Machine Readable Cataloging), the international data standard for bibliographic and holdings information in libraries.
Installation
Add this to your application's shard.yml:
dependencies:
avram:
github: luckyframework/avram
Usage
require "avram"
# Define your database
class AppDatabase < Avram::Database
end
AppDatabase.configure do |settings|
settings.credentials = Avram::Credentials.new(
database: "my_app_development",
username: "postgres",
hostname: "localhost",
password: "password",
port: 5432,
)
end
# Configure Avram to use your database
Avram.configure do |settings|
settings.database_to_migrate = AppDatabase
# When `true`, allow lazy loading (N+1).
# If `false` raise an error if you forget to preload associations
settings.lazy_load_enabled = true
settings.query_cache_enabled = false
end
# Create your read-only model
class Person < Avram::Model
def self.database : Avram::Database.class
AppDatabase
end
table :people do
column name : String
column age : Int32
column programmer : Bool = true
end
end
# Insert a new record
Person::SaveOperation.create!(name: "Henriette Davidson Avram", age: 86)
# Query for a record
person = Person::BaseQuery.new.name.ilike("%avram")
person.programmer? #=> true
For more details, read the guides.
Contributing
- Fork it ( https://github.com/luckyframework/avram/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Make your changes
- Run specs
crystal spec - Check formatting
crystal tool format spec/ src/ - Check ameba
./bin/ameba - Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Docker is provided for quick setup and testing. You can run
./script/setupand./script/testfor ease.
Contributors
paulcsmith Paul Smith - Original Creator of Lucky
Made with contrib.rocks.
API
- Array(T)
An
Arrayis an ordered, integer-indexed collection of objects of type T. - Avram
- BaseTask
- Bool
Bool has only two possible values:
trueandfalse. - Char
A
Charrepresents a Unicode code point. - DB
The DB module is a unified interface for database access.
- Db
- Enum
Enum is the base type of all enums.
- Fiber
https://crystal-lang.org/api/latest/Fiber.html
- Float64
- Gen
- Int16
- Int32
- Int64
- JSONConverter(T)
This is used for serialized JSON objects.
- Nil
The
Niltype has only one possible value:nil. - Object
Objectis the base type of all Crystal objects. - Slice(T)
A
Sliceis aPointerwith an associated size. - String
A
Stringrepresents an immutable sequence of UTF-8 characters. - Time
Timerepresents a date-time instant in incremental time observed in a specific time zone. - UUID
Represents a UUID (Universally Unique IDentifier).