SchemaLang
Universal Data Model Stack Generator
Define your data model once. Generate C++, Java, Lua, MySQL, SQLite, and JSON schemas automatically.
struct User {
int64: id: primary_key: required:
auto_increment: description("User ID");
string: username: required: unique:
description("Username");
string: email: required:
description("Email address");
array<Post>: posts: optional:
description("User posts");
}
struct Post {
int64: id: primary_key: required:
auto_increment: description("Post ID");
string: title: required:
description("Post title");
string: content: required:
description("Post content");
int64: user_id: required:
reference(User.id):
description("Author ID");
}
Why SchemaLang?
Define Once, Deploy Everywhere
Write your data model in a clean, declarative syntax and generate code for multiple languages and databases automatically.
Drop-In System
Generators seamlessly integrate. Enable JSON and your C++ classes get toJSON(), fromJSON(), and getSchema() methods automatically.
Automatic Migrations
Update your schema version and SchemaLang generates migration files automatically. Migrations are embedded in binaries—no runtime dependencies.
Pluggable Architecture
Load custom generators at runtime via .dll/.so plugins. Extend SchemaLang without modifying the core transpiler.
Production-Ready Tooling
Includes linting, command-line debugger, and VS Code DAP integration for professional development workflows.
Type Safety Guaranteed
All generated code is strongly typed and consistent across all targets. Compile-time safety everywhere.
Supported Targets
Object-Oriented Languages
Complete classes with getters/setters, constructors, and drop-in support
Full class generation with JNI bindings and drop-in integration
Scripting Languages
Automatic Lua bindings for all structs and enums with serialization support
Basic Python class generation with serialization support
Database Systems
MySQL X DevAPI with full CRUD operations and embedded migrations
Complete SQLite operations with automatic migration support
Schema & Serialization
Full JSON Schema definitions with validation rules and serialization
See It In Action
Input: Schema Definition
struct Player: version(1.0.0) {
int64: id: primary_key: required:
auto_increment:
description("Player ID");
string: username: required: unique:
description("Player username");
int32: score: required:
description("Player score");
double: winRate: optional:
description("Win percentage");
}
Output: Multiple Targets
// Generated Player class with drop-in methods
class Player {
private:
int64_t id;
std::string username;
int32_t score;
std::optional<double> winRate;
public:
// Standard getters/setters
int64_t getId() const;
void setUsername(const std::string& value);
// JSON serialization (from JSON generator)
json toJSON();
void fromJSON(json j);
// SQLite operations (from SQLite generator)
bool SQLiteInsert(sqlite3* db);
};
// Generated SQLiteDB class with query builders
class SQLiteDB {
public:
// Query builder for Player table
auto SelectPlayer() -> SQLiteQueryBuilder<Player>;
// Create all tables with migrations
void connect();
};
// Real-world usage in an HTTP server:
auto players = db->SelectPlayer()
.WhereEquals("score", "1000")
.OrderBy("username")
.Exec<Player>();
for (const auto& player : players) {
json response = player->toJSON();
send_json_response(response);
}
CREATE TABLE IF NOT EXISTS Player (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
score INT NOT NULL,
winRate DOUBLE,
INDEX idx_username (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "Player ID"
},
"username": {
"type": "string",
"description": "Player username"
},
"score": {
"type": "integer",
"description": "Player score"
},
"winRate": {
"type": "number",
"description": "Win percentage"
}
},
"required": ["id", "username", "score"]
}
Real-World Example: HTTP API Server
Here's how SchemaLang-generated code is used in a production web server
Schema Definition
struct Character: version(1.0.0) {
int64: id: primary_key: required:
auto_increment;
string: first_name: required;
string: last_name: required;
int32: level: required;
int32: max_hp: required;
int32: current_hp: required;
bool: is_npc: required;
int64: owner_user_id: required:
reference(User.id);
}
HTTP Server Using Generated Code
// HTTP GET /api/characters endpoint
void HTTPSession::handle_get_characters() {
// Get user from auth token
auto user_id = validate_session_token(token);
// Use generated query builder
auto query = db_manager_->SelectCharacter()
.WhereEquals("is_npc", "0")
.WhereEquals("owner_user_id",
std::to_string(user_id));
// Execute and get results
auto characters = query.Exec<CharacterSchema>();
// Use generated JSON serialization
json response = json::array();
for (const auto& char_ptr : characters) {
if (char_ptr) {
response.push_back(char_ptr->toJSON());
}
}
send_json_response(response);
}
// HTTP POST /api/characters endpoint
void HTTPSession::handle_create_character() {
json body = json::parse(req_.body());
// Create using generated class
auto character = std::make_shared<CharacterSchema>();
character->fromJSON(body); // Generated method
character->setOwner_user_id(user_id);
// Insert using generated method
if (character->SQLiteInsert(db_manager_->getDB())) {
send_json_response(character->toJSON(),
http::status::created);
}
}
Perfect For
🎮 Game Development
Define game entities once and generate C++ classes, Lua bindings, and SQLite persistence automatically. Perfect for game engines needing scripting support.
🏢 Enterprise Systems
Maintain consistency across microservices written in different languages. Single source of truth for your domain models.
🔌 API Development
Generate backend classes, database schemas, and JSON schemas for validation—all from one definition. Keep APIs and databases in perfect sync.
🔄 Legacy Migration
Bridge old and new systems. Generate JNI bindings to connect C++ and Java, or create adapters between different database systems.
Ready to Simplify Your Data Layer?
Get started with SchemaLang in minutes