# 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`, `pgsql`, `sqlite`, and `tracer`.
`--generate-query`|`-q`
  Generate query support code. Without this support you cannot use views and 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 and PostgreSQL databases 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 and views. Objects and views 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 qualified name of a smart pointer class template, for example, `std::auto_ptr`. In the latter case, the ODB compiler constructs the object or view pointer by adding a single template argument of the object or view type to the qualified name, for example `std::auto_ptr<object>`. The ODB runtime uses object and view pointers to return, and, in case of objects, pass and cache dynamically allocated instances of object and view types.

  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.

`--table-prefix` prefix
  Add prefix to table and index names. The prefix is added to both names that were specified with the `db table` pragma and those that were automatically derived from class names. If you require a separator, such as an underscore, between the prefix and the name, then you should include it into the prefix value.
`--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.
`--include-regex` regex
  Add regex to the list of regular expressions used to transform generated `#include` directive paths. The argument to this option is a Perl-like regular expression in the form `/pattern/replacement/`. Any character can be used as a delimiter instead of `/` and the delimiter can be escaped inside `pattern` and `replacement` with a backslash (`\`). You can specify multiple regular expressions by repeating this option. All the regular expressions are tried in the order specified and the first expression that matches is used.

  As an example, the following expression transforms include paths in the form `foo/bar-odb.h` to paths in the form `foo/generated/bar-odb.h`:

  `%foo/(.+)-odb.h%foo/generated/$1-odb.h%`

  See also the REGEX AND SHELL QUOTING section below.

`--include-regex-trace`
  Trace the process of applying regular expressions specified with the `--include-regex` option. Use this option to find out why your regular expressions don't do what you expected them to do.
`--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.

# REGEX AND SHELL QUOTING

When entering a regular expression argument in the shell command line it is often necessary to use quoting (enclosing the argument in `" "` or `' '`) in order to prevent the shell from interpreting certain characters, for example, spaces as argument separators and `$` as variable expansions.

Unfortunately it is hard to achieve this in a manner that is portable across POSIX shells, such as those found on GNU/Linux and UNIX, and Windows shell. For example, if you use `" "` for quoting you will get a wrong result with POSIX shells if your expression contains `$`. The standard way of dealing with this on POSIX systems is to use `' '` instead. Unfortunately, Windows shell does not remove `' '` from arguments when they are passed to applications. As a result you may have to use `' '` for POSIX and `" "` for Windows (`$` is not treated as a special character on Windows).

Alternatively, you can save regular expression options into a file, one option per line, and use this file with the `--options-file` option. With this approach you don't need to worry about shell quoting.

# 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.