Introduction

Crystal Query Language (CQL) is a type-safe ORM for Crystal that combines compile-time safety with high performance.

What is CQL?

CQL provides:

  • Type Safety - Compile-time error detection

  • Performance - Zero-cost abstractions with macro-generated code

  • Flexibility - Active Record, Repository, and Data Mapper patterns

  • Multi-Database - PostgreSQL, MySQL, SQLite support

# Type-safe model definition
struct User
  include CQL::ActiveRecord::Model(Int64)
  db_context UserDB, :users

  property id : Int64?
  property name : String
  property email : String
  property active : Bool = true

  validate :email, presence: true, match: EMAIL_REGEX
  has_many :posts, foreign_key: :user_id
end

# Compile-time safe queries
active_users = User
  .where(active: true)
  .where { age >= 18 }
  .order(created_at: :desc)
  .limit(10)
  .all

Key Features

Type-Safe ORM

Crystal's static type system eliminates runtime database errors:

Multi-Database Support

Single codebase works across databases:

Multiple Patterns

Active Record:

Repository:

Quick Setup

Add to shard.yml:

Basic example:

Next Steps


Built for Crystal developers, by Crystal developers - CQL brings together the performance and safety of Crystal with the power and flexibility of modern ORM design.

Ready to build something amazing? Let's get started!

Last updated

Was this helpful?