> For the complete documentation index, see [llms.txt](https://azutopia.gitbook.io/cql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://azutopia.gitbook.io/cql/readme.md).

# CQL Documentation

A type-safe query builder and Active Record ORM for Crystal on SQLite, PostgreSQL, MySQL and CockroachDB.

Schemas, models and queries are Crystal code, so a misspelled column or a value of the wrong type fails at compile time, and every value reaches the database as a bound parameter. CQL ships its own PostgreSQL driver.

```crystal
require "cql"
require "sqlite3"

AppDB = CQL::Schema.define(:app, adapter: CQL::Adapter::SQLite, uri: "sqlite3://./app.db") do
  table :users do
    primary :id, Int64, auto_increment: true
    text :name
  end
end

class User
  include CQL::ActiveRecord::Model(Int64)
  db_context AppDB, :users
  property name : String

  def initialize(@name : String)
  end
end

AppDB.users.create!
User.create!(name: "Ada")
User.where(name: "Ada").count # => 1   SELECT COUNT(*) FROM users WHERE users.name = ?
```

## Start Here

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Installation</strong></td><td>Add the shards for your database and check the connection.</td><td><a href="/cql/installation.md">Installation</a></td></tr><tr><td><strong>Tutorials</strong></td><td>Learn CQL step by step, from a first app to a full blog.</td><td><a href="/cql/tutorials/tutorials.md">Tutorials Overview</a></td></tr><tr><td><strong>How-to Guides</strong></td><td>One task per page: models, queries, migrations, caching, PostgreSQL.</td><td><a href="/cql/how-to-guides/how-to.md">How-to Overview</a></td></tr><tr><td><strong>Reference</strong></td><td>Every setting, DSL method, callback, validator and error.</td><td><a href="/cql/reference/reference.md">Reference Overview</a></td></tr><tr><td><strong>Explanation</strong></td><td>How CQL works and why: Active Record, guardrails, performance.</td><td><a href="/cql/explanation/explanation.md">Explanation Overview</a></td></tr><tr><td><strong>Resources</strong></td><td>FAQ and how to contribute.</td><td><a href="/cql/resources/resources.md">Resources Overview</a></td></tr></tbody></table>

Source, issues and releases: [azutoolkit/cql](https://github.com/azutoolkit/cql) on GitHub. CQL is available under the MIT license.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://azutopia.gitbook.io/cql/readme.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
