Model Generator

The model generator creates CQL ORM models for your Azu application. Models represent database tables and provide an object-oriented interface for database operations.

Overview

azu generate model <name> [field:type] [options]

Basic Usage

# Generate a basic model
azu generate model user

# Generate with fields
azu generate model user name:string email:string age:int32

# Generate with relationships
azu generate model post title:string content:text user_id:references

Command Options

Option
Description
Default

--timestamps

Add created_at/updated_at fields

true

--uuid

Use UUID as primary key

false

--skip-migration

Don't generate migration file

false

--force

Overwrite existing files

false

Field Types

Type
Crystal Type
Database Type
Description

string

String

VARCHAR/TEXT

Short text field

text

String

TEXT

Long text field

int32

Int32

INTEGER

32-bit integer

int64

Int64

BIGINT

64-bit integer

float64

Float64

DECIMAL

Floating point number

bool

Bool

BOOLEAN

True/false value

date

Date

DATE

Date only

time

Time

TIMESTAMP

Date and time

json

JSON::Any

JSON/JSONB

JSON data

uuid

UUID

UUID

UUID field

references

Int64

BIGINT

Foreign key reference

Generated Files

Model File

Migration File

Examples

User Model

Generated Model:

Post Model with Relationships

Generated Model:

Category Model with UUID

Generated Model:

Relationships

belongs_to

has_many

has_one

many_to_many

Validations

Scopes

Query Examples


Next Steps:

Last updated