What is Jennifer?

Jennifer is an ActiveRecord pattern for Crystal with great query DSL and migration mechanism.

This section is based on Jennifer Docs. Also see Amber Jennifer Example App.

Installing Jennifer for Amber

Generate a normal amber app

amber new {project}

Update your project shard.yml

Add this to your application's

# Add the following dependencies
github: imdrasil/
github: imdrasil/

Choose one of existing adapters for your db: mysql or postgres.

Then in the console

shards update

Setup your database information

defaults : &defaults
host: localhost
adapter: postgres
user: root
password: somepassword
migration_files_path: db/migrations # this is the default location for all migrations
db: blog_development
<<: *defaults
db: blog_test
<<: *defaults

Create a under the /config directory

require "amber"
require "colorize""config/database.yml", Amber.env.to_s)
Jennifer::Config.configure do |conf|
conf.logger =
conf.logger.formatter = do |severity, datetime, progname, message, io|
io << datetime.colorize(:cyan) << ": \n" << message.colorize(:light_magenta)
conf.logger.level = Logger::DEBUG

Note that we pass the AMBER_ENV to this will allow Jennifer to use the correct database settings for the environment.

Create a in {project/src}

Jennifer uses Sam for running tasks pertinent to ORM operations. Sam is a Make-like utility which allows to specify tasks like Ruby's Rake do using plain Crystal. For how to use Sam visit the Github repository

# src/
require "jennifer"
require "jennifer/adapter/postgres"
require "../config/jennifer"
require "../db/migrations/*"
require "sam"
require "jennifer/sam"
load_dependencies "jennifer"

Edit your src/{project}.cr file

This should be done before you load your application configurations (or at least models). With Amber this is very easy.

require "jennifer"
require "jennifer/adapter/postgres"
require "amber"
require "./controllers/**"
require "./mailers/**"
require "./models/**"
require "./views/**"
require "../config/*"

You're all set with the configuration. Next using Jennifer Migrations and Models.