Clear ORM
  • Welcome to Clear
  • Introduction
    • Setup
  • Model
    • Defining your model
      • Describing your columns
      • Primary Keys
      • Converters
    • Associations
      • belongs_to
      • has_many
      • has_many through
      • has_one
    • Lifecycle
      • Persistence
      • Validations
      • Triggers
    • Batchs operations
      • Bulk update
      • Bulk insert & delete
    • Transactions & Save Points
      • Transaction & Savepoints
      • Connection pool
    • Locks
  • Querying
    • The collection object
      • Filter the query
        • Filter the query – The Expression Engine
        • Find, First, Last, Offset, Limit
        • Aggregation
        • Ordering & Group by
      • Fetching the query
        • Each and Fetch
        • Cursored fetching
        • Model extra attributes
      • Joins
      • Eager Loading
      • Window and CTE
      • Scopes
    • Writing low-level SQL
      • Select Clause
      • Insert Clause
      • Delete Clause
  • Migrations
    • Manage migrations
    • Call migration script
    • Migration CLI
  • Additional and advanced features
    • JSONB
    • Symbol vs String
    • Enums
    • BCrypt
    • Full Text Search
    • Handling multi-connection
  • Other resources
    • API Documentation
    • Inline documentation
    • Github repository
    • Credits
    • Benchmark
Powered by GitBook
On this page

Welcome to Clear

NextSetup

Last updated 5 years ago

Welcome to Clear, the ORM specifically developed for PostgreSQL and Crystal Language.

After reading this guide, you will know:

  • How to install and configure Clear for your project

  • How to use Clear to manipulate the data stored in your database

  • How to take advantage of the advanced features of PostgreSQL combined seamlessly with the powerful Crystal Language features

  • How to maintain the coherence of your database through migration and validations.

What is Clear ?

Clear is an ORM (Object Relation Mapping) built for Crystal language.

It offers the Model layer of your applications.

Clear is built especially for PostgreSQL, meaning it's not compatible with MariaDB or SQLite for example. Therefore, it achieves to delivers a tremendous amount of PostgreSQL advanced features out of the box.

Clear is largely based on Active Record pattern, and freely inspired by and . Thus, it follow some philosophical concepts, as:

  • Convention over configuration: While it's possible to name your models and key the way you want, linking achieved without any directives in the code by using the default naming convention:

Crystal

PostgreSQL

class ModelName

TABLE model_names

belongs_to foreign_object

COLUMN foreign_object_id : bigint

If you already works with Ruby on Rails, you will notice that the naming convention follow ActiveRecord pattern.

  • Multiple way of doing things: Philosophically, Clear try to reduce the gap between the mind of the developer and the code itself. The code is meant to be read as close to written English as possible. Therefore, there's often multiple way to do things, based on the feeling of the developer writing the code.

  • Less boilerplate = more happiness: The "magic" under Clear allows to write as minimum as possible boilerplate code, like type-checking, validations or even SQL fragment writing.

Rails Active Record
Sequel