# NAME

odb - object-relational mapping (ORM) compiler for C++

# SYNOPSIS

`odb [options] file [file...]`

# DESCRIPTION

Given a set of C++ classes in a header file, `odb` generates C++ code that allows you to persist, query, and update objects of these classes in a relational database (RDBMS). The relational database that the generated code should target is specified with the required `--database` option (see below).

For an input file in the form `name.hxx` (other file extensions can be used instead of `.hxx`), the following C++ files are generated: `name-odb.hxx` (header file), `name-odb.ixx` (inline file, generated unless the `--suppress-inline` option is specified), and `name-odb.cxx` (source file). Additionally, if the `--generate-schema` option is specified and the `sql` schema format is requested, the `name.sql` database schema file is generated.

# OPTIONS

`--help`
  Print usage information and exit.
`--version`
  Print version and exit.
`-I` dir
  Add dir to the beginning of the list of directories to be searched for included header files.
`-D` name[=def]
  Define macro name with definition def. If definition is omitted, define name to be 1.
`-U` name
  Cancel any previous definitions of macro name, either built-in or provided with the `-D` option.
`--database`|`-d` db
  Generate code for the db database. Valid values are `mysql`, `sqlite`, and `tracer`.
`--generate-query`|`-q`
  Generate query support code. Without this support you can only load objects via their ids.
`--generate-schema`|`-s`
  Generate the database schema. The database schema contains SQL statements that create database tables necessary to store persistent classes defined in the file being compiled. Note that by applying this schema, all the existing information stored in such tables will be lost.

  Depending on the database being used (`--database` option), the schema is generated either as a standalone SQL file or embedded into the generated C++ code. By default the SQL file is generated for the MySQL database and the schema is embedded into the C++ code for the SQLite database. Use the `--schema-format` option to alter the default schema format.

`--schema-format` format
  Generate the database schema in the specified format. Pass `sql` as format to generate the database schema as a standalone SQL file or pass `embedded` to embed the schema into the generated C++ code. Repeat this option to generate the same database schema in multiple formats.
`--default-schema` name
  Use name as the default database schema name. Schema names are primarily used for distinguishing between multiple embedded schemas in the schema catalog. If this option is not specified, the empty name, which corresponds to the default schema, is used.
`--default-pointer` ptr
  Use ptr as the default pointer for persistent objects. Objects that do not have a pointer assigned with the `db pointer` pragma will use this pointer by default. The value of this option can be `*` which denotes the raw pointer and is the default, or a qualified name of a smart pointer class template, for example, `std::auto_ptr`. In the latter case, the ODB compiler constructs the object pointer by adding a single template argument of the object type to the qualified name, for example `std::auto_ptr<object>`. The object pointer is used by the ODB runtime to return, pass, and cache dynamically allocated instances of the object type.

  Except for the raw pointer and the standard smart pointers defined in the `<memory>` header file, you are expected to include the definition of the default pointer at the beginning of the generated header file. There are two common ways to achieve this: you can either include the necessary header in the file being compiled or you can use the `--hxx-prologue` option to add the necessary `#include` directive to the generated code.

`--profile`|`-p` name
  Specify a profile that should be used during compilation. A profile is an options file. The ODB compiler first looks for a database-specific version with the name constructed by appending the `-``database``.options` suffix to name, where `database` is the database name as specified with the `--database` option. If this file is not found, then the ODB compiler looks for a database-independant version with the name constructed by appending just the `.options` suffix.

  The profile options files are searched for in the same set of directories as C++ headers included with the `#include <...>` directive (built-in paths plus those specified with the `-I` options). The options file is first searched for in the directory itself and then in its `odb/` subdirectory.

  For the format of the options file refer to the `--options-file` option below. You can repeat this option to specify more than one profile.

`--output-dir`|`-o` dir
  Write the generated files to dir instead of the current directory.
`--odb-file-suffix` suffix
  Use suffix instead of the default `-odb` to construct the names of the generated C++ files.
`--hxx-suffix` suffix
  Use suffix instead of the default `.hxx` to construct the name of the generated C++ header file.
`--ixx-suffix` suffix
  Use suffix instead of the default `.ixx` to construct the name of the generated C++ inline file.
`--cxx-suffix` suffix
  Use suffix instead of the default `.cxx` to construct the name of the generated C++ source file.
`--sql-suffix` suffix
  Use suffix instead of the default `.sql` to construct the name of the generated database schema file.
`--hxx-prologue` text
  Insert text at the beginning of the generated C++ header file.
`--ixx-prologue` text
  Insert text at the beginning of the generated C++ inline file.
`--cxx-prologue` text
  Insert text at the beginning of the generated C++ source file.
`--sql-prologue` text
  Insert text at the beginning of the generated database schema file.
`--hxx-epilogue` text
  Insert text at the end of the generated C++ header file.
`--ixx-epilogue` text
  Insert text at the end of the generated C++ inline file.
`--cxx-epilogue` text
  Insert text at the end of the generated C++ source file.
`--sql-epilogue` text
  Insert text at the end of the generated database schema file.
`--hxx-prologue-file` file
  Insert the content of file at the beginning of the generated C++ header file.
`--ixx-prologue-file` file
  Insert the content of file at the beginning of the generated C++ inline file.
`--cxx-prologue-file` file
  Insert the content of file at the beginning of the generated C++ source file.
`--sql-prologue-file` file
  Insert the content of file at the beginning of the generated database schema file.
`--hxx-epilogue-file` file
  Insert the content of file at the end of the generated C++ header file.
`--ixx-epilogue-file` file
  Insert the content of file at the end of the generated C++ inline file.
`--cxx-epilogue-file` file
  Insert the content of file at the end of the generated C++ source file.
`--sql-epilogue-file` file
  Insert the content of file at the end of the generated database schema file.
`--odb-prologue` text
  Compile text before the input header file. This option allows you to add additional declarations, such as custom traits specializations, to the ODB compilation process.
`--odb-prologue-file` file
  Compile file contents before the input header file. Prologue files are compiled after all the prologue text fragments (`--odb-prologue` option).
`--odb-epilogue` text
  Compile text after the input header file. This option allows you to add additional declarations, such as custom traits specializations, to the ODB compilation process.
`--odb-epilogue-file` file
  Compile file contents after the input header file. Epilogue files are compiled after all the epilogue text fragments (`--odb-epilogue` option).
`--include-with-brackets`
  Use angle brackets (<>) instead of quotes ("") in the generated `#include` directives.
`--include-prefix` prefix
  Add prefix to the generated `#include` directive paths.
`--guard-prefix` prefix
  Add prefix to the generated header inclusion guards. The prefix is transformed to upper case and characters that are illegal in a preprocessor macro name are replaced with underscores.
`--options-file` file
  Read additional options from file with each option appearing on a separate line optionally followed by space and an option value. Empty lines and lines starting with `#` are ignored. Option values can be enclosed in double (`"`) or single (`'`) quotes to preserve leading and trailing whitespaces as well as to specify empty values. If the value itself contains trailing or leading quotes, enclose it with an extra pair of quotes, for example `'"x"'`. Non-leading and non-trailing quotes are interpreted as being part of the option value.

  The semantics of providing options in a file is equivalent to providing the same set of options in the same order on the command line at the point where the `--options-file` option is specified except that the shell escaping and quoting is not required. You can repeat this option to specify more than one options file.

`-x` option
  Pass option to the underlying C++ compiler (`g++`). The option value that doesn't start with `-` is considered the `g++` executable name.
`-v`
  Print the commands executed to run the stages of compilation.
`--trace`
  Trace the compilation process.
`--mysql-engine` engine
  Use engine instead of the default `InnoDB` in the generated database schema file. For more information on the storage engine options see the MySQL documentation. If you would like to use the database-default engine, pass `default` as the value for this option.
`--sqlite-lax-auto-id`
  Do not force monotonically increasing automatically-assigned object ids. In this mode the generated database schema omits the `AUTOINCREMENT` keyword which results in faster object persistence but may lead to automatically-assigned ids not being in a strictly ascending order. Refer to the SQLite documentation for details.

# DIAGNOSTICS

If the input file is not valid C++, `odb` will issue diagnostic messages to STDERR and exit with non-zero exit code.

# BUGS

Send bug reports to the odb-users@codesynthesis.com mailing list.