> For the complete documentation index, see [llms.txt](https://crystal-garage.gitbook.io/lustra-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://crystal-garage.gitbook.io/lustra-docs/model/column-types.md).

# Defining your model

Model definition in Lustra starts by including `Lustra::Model` in a class and declaring the columns that exist in the PostgreSQL table.

Assume this table:

```sql
CREATE TABLE articles (
  id serial PRIMARY KEY,
  name text NOT NULL,
  description text
);
```

The matching model can be written as:

{% code title="article.cr" %}

```crystal
class Article
  include Lustra::Model

  column id : Int32, primary: true, presence: false
  column name : String
  column description : String?
end
```

{% endcode %}

Step by step:

```crystal
include Lustra::Model
```

This adds Lustra's model behavior to the class.

```crystal
column name : String
```

This maps the PostgreSQL `name` column to a Crystal `String` attribute.

```crystal
column description : String?
```

This maps the nullable PostgreSQL `description` column to a nilable Crystal attribute.

```crystal
column id : Int32, primary: true, presence: false
```

This declares `id` as the primary key. Because PostgreSQL generates the `serial` value, `presence: false` tells Lustra not to require the value before insert.

You can then use the model:

```crystal
article = Article.new({name: "A superb article!"})
article.description = "This is a masterpiece."
article.save!

puts "Article saved as id=#{article.id}"
```

By default, Lustra infers the table name from the model name. `Article` maps to `articles`.

You can override the table name:

```crystal
class Model::Customer
  include Lustra::Model

  self.table = "clients"

  column id : Int64, primary: true, presence: false
  column name : String
end
```

The next page covers column options in more detail.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://crystal-garage.gitbook.io/lustra-docs/model/column-types.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
