Getting Started with SchemaLang

Learn how to install SchemaLang and create your first data model in minutes.

Installation

From Source (Recommended)

Clone the repository and build using CMake:

# Clone the repository
git clone https://github.com/ReapersSoul/SchemaLang.git
cd SchemaLang

# Create build directory
mkdir build && cd build

# Configure and build
cmake ..
cmake --build . --config Release

# The transpiler will be in build/Release/SchemaLangTranspiler

Prerequisites

SchemaLang requires the following dependencies:

  • C++17 or later - Modern C++ compiler (GCC 7+, Clang 5+, MSVC 2017+)
  • CMake 3.10+ - Build system generator
  • Boost libraries - For DLL loading and filesystem operations
πŸ’‘ Tip: On Ubuntu/Debian, install dependencies with: sudo apt install build-essential cmake libboost-all-dev

Quick Start

1. Create Your First Schema

Create a file named user.schema:

struct User {
    int64: id: primary_key: required: auto_increment: 
        description("Unique user identifier");
    string: username: required: unique: 
        description("Username for login");
    string: email: required: 
        description("User email address");
    string: passwordHash: required: 
        description("Hashed password");
}

2. Generate Code

Run the transpiler to generate C++ and SQLite code:

./SchemaLangTranspiler \
    -schema=./user.schema \
    -outputDirectory=./output \
    -cpp \
    -sqlite

3. Check the Output

SchemaLang generates organized output:

output/
└── Schemas/
    β”œβ”€β”€ UserSchema.hpp
    β”œβ”€β”€ UserSchema.cpp
    β”œβ”€β”€ SQLiteDB.hpp
    β”œβ”€β”€ SQLiteDB.cpp
    └── SQLiteQueryBuilder.hpp

The generated code includes:

  • UserSchema - Your data model class with getters/setters
  • SQLiteDB - Database manager with query builders for all structs
  • SQLiteQueryBuilder - Type-safe query building

4. Use the Generated Code

Include and use your generated classes:

#include "SQLiteDB.hpp"
#include "Schemas/UserSchema.hpp"

int main() {
    // Create database manager
    SQLiteDB db("users.db");
    db.connect(); // Creates tables automatically
    
    // Create and insert a user
    auto user = std::make_shared<UserSchema>();
    user->setUsername("alice");
    user->setEmail("alice@example.com");
    user->setPasswordHash("hashed_password");
    user->SQLiteInsert(db.getDB());
    
    // Query using generated query builder
    auto retrieved = db.SelectUser()
        .WhereEquals("username", "alice")
        .First<UserSchema>();
    
    if (retrieved) {
        std::cout << "User ID: " << retrieved->getId() 
                  << std::endl;
    }
    
    return 0;
}

Basic Usage

Command Structure

SchemaLangTranspiler -schema=<path> -outputDirectory=<path> [generators] [options]

Common Generators

Generator Flag Description
C++ -cpp Generate C++ classes with getters/setters
Java -java Generate Java classes (beta)
JSON Schema -json Generate JSON schemas and serialization
SQLite -sqlite Generate SQLite database operations
MySQL -mysql Generate MySQL database operations

Common Options

Option Description
-R Recursively process subdirectories
-migrationsPath=<path> Enable automatic migration generation
-cppIncludePrefix=<prefix> Add prefix to C++ includes
-additionalGenerators=<path> Load custom generator plugins

Multi-Generator Example

Generate code for multiple targets at once:

./SchemaLangTranspiler \
    -schema=./schemas \
    -outputDirectory=./output \
    -cpp \
    -json \
    -sqlite \
    -mysql \
    -R

This generates C++ classes with JSON serialization, SQLite operations, and MySQL operationsβ€”all from the same schema definition.

Next Steps

Need Help?

If you run into issues: