CLI Tools
The Sleet CLI provides code generation and database tooling for the Sleet FiveM ORM.
Installation
Via npm (Windows - Recommended)
npm install -g sleet-orm-cliFrom Source (Go 1.21+)
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.
sleet generate schema.lua
sleet generate schema.lua -o .sleet/types.lua
sleet generate schema.lua --stdoutDefault 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.
sleet sql server/schema.lua
sleet sql server/schema.lua -o database/init.sql
sleet sql server/schema.lua --stdoutGenerates 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.
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 --stdoutConnection Options:
| Flag | Short | Default | Description |
|---|---|---|---|
--host | 127.0.0.1 | Database host | |
--port | 3306 | Database port | |
--user | -u | root | Database user |
--pass | -p | Database password | |
--db | -d | Database name (required) | |
--out | -o | schema.lua | Output file path |
--stdout | Print to stdout instead of file |
Usage Examples
Basic Development Workflow
- Write your schema:
-- 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'))
})
}- Generate SQL for database:
sleet sql server/schema.lua -o database/init.sql- Generate type annotations:
sleet generate server/schema.lua- Apply to database:
mysql -u root -p gamemode < database/init.sqlIDE 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):
{
"Lua.workspace.library": [".sleet"]
}LuaLS (.luarc.json):
{
"workspace": {
"library": [".sleet"]
}
}Build Scripts Integration
Add Sleet commands to your npm scripts:
{
"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
- Backup current schema:
sleet pull --db gamemode -o schema-backup.lua- Generate new SQL:
sleet sql server/schema.lua -o migration.sql- Review and apply:
# Review the generated SQL first
cat migration.sql
# Then apply to database
mysql -u root -p gamemode < migration.sqlGetting Help
sleet --help # General help
sleet generate --help # Generate command help
sleet sql --help # SQL command help
sleet pull --help # Pull command helpProject 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 binaryThe CLI makes it easy to maintain type-safe database schemas and get full IDE support for your FiveM Lua development!
