Skip to content

CLI Tools

The Sleet CLI provides code generation and database tooling for the Sleet FiveM ORM.

Installation

bash
npm install -g sleet-orm-cli

From Source (Go 1.21+)

bash
git clone https://github.com/SleetCo/sleet-orm-cli.git
cd sleet-orm-cli
go build -o sleet .

Add the binary to your PATH, or run ./sleet directly.

Commands

The Sleet CLI provides three main commands for working with your schemas:

sleet generate

Generate LuaLS type annotations from your schema files.

Executes your schema.lua in an embedded Lua VM, intercepts all sl.table() calls, and generates a ---@meta file with full LuaLS type inference.

bash
sleet generate schema.lua
sleet generate schema.lua -o .sleet/types.lua
sleet generate schema.lua --stdout

Default output: .sleet/types.lua in the current directory.

What it generates:

  • Type definitions for table records
  • Column type definitions
  • Schema object types
  • Full LuaLS integration for autocomplete and type checking

sleet sql

Generate MySQL CREATE TABLE statements from your schema.

bash
sleet sql server/schema.lua
sleet sql server/schema.lua -o database/init.sql
sleet sql server/schema.lua --stdout

Generates CREATE TABLE IF NOT EXISTS statements that you can execute against your MySQL/MariaDB database.

sleet pull

Reverse-engineer existing MySQL/MariaDB database into a schema.lua file.

bash
sleet pull --db myserver
sleet pull --host 127.0.0.1 -u root -p s3cr3t --db myserver -o server/schema.lua
sleet pull --db myserver --stdout

Connection Options:

FlagShortDefaultDescription
--host127.0.0.1Database host
--port3306Database port
--user-urootDatabase user
--pass-pDatabase password
--db-dDatabase name (required)
--out-oschema.luaOutput file path
--stdoutPrint to stdout instead of file

Usage Examples

Basic Development Workflow

  1. Write your schema:
lua
-- server/schema.lua
local sl = require 'sleet'

return {
    players = sl.table('players', {
        id = sl.serial().primaryKey(),
        identifier = sl.varchar(64).notNull().unique(),
        name = sl.varchar(255).notNull(),
        money = sl.integer().default(5000),
        created_at = sl.timestamp().default(sl.raw('CURRENT_TIMESTAMP'))
    })
}
  1. Generate SQL for database:
bash
sleet sql server/schema.lua -o database/init.sql
  1. Generate type annotations:
bash
sleet generate server/schema.lua
  1. Apply to database:
bash
mysql -u root -p gamemode < database/init.sql

IDE Integration

After generating types with sleet generate, LuaLS will automatically detect and load the generated type annotations for autocomplete and type checking.

Optional Configuration (only needed if working in a workspace without sleet):

VS Code (.vscode/settings.json):

json
{
    "Lua.workspace.library": [".sleet"]
}

LuaLS (.luarc.json):

json
{
    "workspace": {
        "library": [".sleet"]
    }
}

Build Scripts Integration

Add Sleet commands to your npm scripts:

json
{
  "scripts": {
    "schema:types": "sleet generate server/schema.lua",
    "schema:sql": "sleet sql server/schema.lua -o database/schema.sql",
    "schema:pull": "sleet pull --db gamemode -o server/schema-backup.lua"
  }
}

Database Migration Workflow

  1. Backup current schema:
bash
sleet pull --db gamemode -o schema-backup.lua
  1. Generate new SQL:
bash
sleet sql server/schema.lua -o migration.sql
  1. Review and apply:
bash
# Review the generated SQL first
cat migration.sql
# Then apply to database
mysql -u root -p gamemode < migration.sql

Getting Help

bash
sleet --help           # General help
sleet generate --help  # Generate command help
sleet sql --help      # SQL command help
sleet pull --help     # Pull command help

Project Structure

The CLI is organized as follows:

cli/
├── cmd/           # Cobra commands (root, generate, sql, pull)
├── internal/      # Core logic, generators, database connection
├── main.go        # Entry point
├── go.mod         # Go module definition
└── sleet.exe      # Windows binary

The CLI makes it easy to maintain type-safe database schemas and get full IDE support for your FiveM Lua development!

Released under the MIT License.