An implemenation of an Object Relational Mapping layer. More...
Classes | |
struct | Wt::Dbo::ptr_tuple< T0, T1,, T9 > |
A utility class for defining a tuple of database objects. More... | |
class | Wt::Dbo::SqlStatement |
Abstract base class for a prepared SQL statement. More... | |
class | Wt::Dbo::backend::Postgres |
A PostgreSQL connection. More... | |
class | Wt::Dbo::backend::Sqlite3 |
An SQLite3 connection. More... | |
class | Wt::Dbo::collection< C > |
An STL container for iterating query results. More... | |
class | Wt::Dbo::Exception |
Exception base class for Wt::Dbo. More... | |
class | Wt::Dbo::StaleObjectException |
Exception thrown when Wt::Dbo detects a concurrent modification More... | |
class | Wt::Dbo::ObjectNotFoundException |
Exception thrown when trying to load a non-existing object. More... | |
class | Wt::Dbo::NoUniqueResultException |
Exception thrown when a query unexpectedly finds a non-unique result. More... | |
class | Wt::Dbo::Dbo |
A base class for database objects. More... | |
class | Wt::Dbo::ptr< C > |
A smart pointer for database objects. More... | |
class | Wt::Dbo::Query< Result > |
A database query. More... | |
class | Wt::Dbo::Session |
A database session. More... | |
class | Wt::Dbo::SqlConnection |
Abstract base class for an SQL connection. More... | |
class | Wt::Dbo::sql_value_traits< V, Enable > |
Traits class for value types. More... | |
class | Wt::Dbo::sql_result_traits< Result > |
Traits class for result types. More... | |
class | Wt::Dbo::Transaction |
A database transaction. More... | |
Enumerations | |
enum | Wt::Dbo::RelationType { Wt::Dbo::ManyToOne, Wt::Dbo::ManyToMany } |
Type of an SQL relation. More... | |
Functions | |
template<class Action , typename V > | |
void | Wt::Dbo::field (Action &action, V &value, const std::string &name, int size=-1) |
Maps a database object field. | |
template<class Action , class C > | |
void | Wt::Dbo::belongsTo (Action &action, ptr< C > &value, const std::string &name) |
Maps the "One"-side of a ManyToOne relation. | |
template<class Action , class C > | |
void | Wt::Dbo::hasMany (Action &action, collection< ptr< C > > &value, RelationType type, const std::string &joinName, const std::string &joinId="") |
Maps the "Many"-side of a ManyToOne or ManyToMany relation. |
An implemenation of an Object Relational Mapping layer.
For an introduction, see the tutorial.
void Wt::Dbo::belongsTo | ( | Action & | action, | |
ptr< C > & | value, | |||
const std::string & | name | |||
) | [inline] |
Maps the "One"-side of a ManyToOne relation.
This function binds the pointer field value
to the database field name
+ "_id"
.
A belongsTo() will usually have a counter-part hasMany() declaration in the referenced class C
.
void Wt::Dbo::field | ( | Action & | action, | |
V & | value, | |||
const std::string & | name, | |||
int | size = -1 | |||
) | [inline] |
Maps a database object field.
This function binds the field value
to the database field name
.
The optional size
may be used as a hint for the needed storage. It is only useful for std::string or WString fields, and causes the schema to use a varchar(
size
)
for storing the field instead of an unlimited length string type.
You may want to specialize this method for a particular value type, if it is for example a composite type which should be persisted in multiple database fields.
For example:
void Wt::Dbo::hasMany | ( | Action & | action, | |
collection< ptr< C > > & | value, | |||
RelationType | type, | |||
const std::string & | joinName, | |||
const std::string & | joinId = "" | |||
) | [inline] |
Maps the "Many"-side of a ManyToOne or ManyToMany relation.
This function binds the collection field value
to contain objects (of type C
).
For a ManyToOne relation, the query is defined by the database field joinName
+ "_id"
in the table that matches C
. This should be the same name as passed to the matching belongsTo() method for the other side of the relation.
For a ManyToMany relation, the joinName
is the name of a linker table (this linker table may be schema qualified, e.g. "myschema.posts_tags"
. Thus, also for a ManyToMany relation, both sides of the relationship will have the same joinName passed to them. You may optionally specify the joinId
which is used to reference this side of the relationship in the join table. If joinId
is left blank, the value will be table name of the current class + "_id".
A hasMany() must have a counter-part belongsTo() or hasMany() declaration in the referenced class C
.