Generators

Understand how SchemaLang generators transform your schema into working code.

Overview

SchemaLang generators convert schema definitions into target-specific code. Generators can work independently or integrate through the drop-in system.

C++ Generator

Generates complete C++ classes with getters, setters, and constructors.

./SchemaLangTranspiler -schema=./schemas -outputDirectory=./output -cpp

Generated Output

  • Header files (.hpp) with class declarations
  • Source files (.cpp) with method implementations
  • Private member variables with public accessors
  • Drop-in method injection support

JSON Generator

Creates JSON schemas and adds serialization methods via drop-in.

./SchemaLangTranspiler -schema=./schemas -outputDirectory=./output -json -cpp

Generated Methods (Drop-In)

  • json toJSON() - Serialize object to JSON
  • void fromJSON(json j) - Deserialize from JSON
  • json getSchema() - Get JSON Schema definition

SQLite Generator

Generates SQLite database operations with automatic migration support.

./SchemaLangTranspiler -schema=./schemas -outputDirectory=./output -sqlite -cpp

Generated Methods (Drop-In)

  • bool SQLiteInsert(sqlite3* db) - Insert record
  • void SQLiteSelectBy[Field](sqlite3* db, type value) - Select by each field
  • static bool SQLiteCreateTable(sqlite3* db) - Create table
  • Automatic migration functions

MySQL Generator

Generates MySQL X DevAPI operations with migration support.

./SchemaLangTranspiler -schema=./schemas -outputDirectory=./output -mysql -cpp

Generated Methods (Drop-In)

  • bool MySQLInsert(mysqlx::Session& session) - Insert record
  • static vector<T*> MySQLSelectBy[Field](...) - Select operations
  • static bool MySQLCreateTable(mysqlx::Session& session) - Create table
  • Embedded migration SQL

Drop-In System

The drop-in system allows specialized generators to inject methods into OOP language classes seamlessly.

How It Works

  1. Enable multiple generators (e.g., -cpp -json -sqlite)
  2. Specialized generators register methods to inject
  3. C++ generator includes injected methods in generated classes
  4. Result: Unified classes with database ops, serialization, etc.

Custom Generators

Create custom generators as .dll/.so plugins:

./SchemaLangTranspiler -additionalGenerators=./plugins -schema=./schemas -outputDirectory=./output

See the documentation for creating dynamic generators.