An implemenation of an Object Relational Mapping layer. More...
Classes | |
class | Wt::Dbo::ForeignKeyConstraint |
Type that indicates one or more foreign key constraints. More... | |
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::FixedSqlConnectionPool |
A connection pool of fixed size. More... | |
class | Wt::Dbo::dbo_default_traits |
Default traits for a class mapped with Wt::Dbo. More... | |
class | Wt::Dbo::dbo_traits< C > |
Traits for a class mapped with Wt::Dbo. More... | |
class | Wt::Dbo::Dbo< C > |
A base class for database objects. More... | |
class | Wt::Dbo::ptr< C > |
A smart pointer for database objects. More... | |
class | Wt::Dbo::Query< Result, BindStrategy > |
A database query. More... | |
class | Wt::Dbo::QueryModel< Result > |
A Wt MVC Model to view/edit query results. More... | |
class | Wt::Dbo::Session |
A database session. More... | |
class | Wt::Dbo::SqlConnection |
Abstract base class for an SQL connection. More... | |
class | Wt::Dbo::SqlConnectionPool |
Abstract base class for a SQL connection pool. More... | |
class | Wt::Dbo::sql_value_traits< V, Enable > |
Traits class for value types. More... | |
class | Wt::Dbo::FieldInfo |
Description of a field. More... | |
class | Wt::Dbo::query_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 | |
ForeignKeyConstraint | Wt::Dbo::operator| (ForeignKeyConstraint lhs, ForeignKeyConstraint rhs) |
Combines two constraints. | |
template<class Action , typename V > | |
void | Wt::Dbo::id (Action &action, V &value, const std::string &name="id", int size=-1) |
Maps a natural primary key (id) field. | |
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, int size=-1) |
Maps the "One"-side of a ManyToOne relation. | |
template<class Action , class C > | |
void | Wt::Dbo::belongsTo (Action &action, ptr< C > &value, const std::string &name, ForeignKeyConstraint constraints, int size=-1) |
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) |
Maps the "Many"-side of a ManyToOne or ManyToMany 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, ForeignKeyConstraint constraints=NotNull) |
Maps the "Many"-side of a ManyToMany relation. | |
Variables | |
const ForeignKeyConstraint | Wt::Dbo::NotNull |
A constraint that prevents a null ptr. | |
const ForeignKeyConstraint | Wt::Dbo::OnUpdateCascade |
A constraint that cascades updates. | |
const ForeignKeyConstraint | Wt::Dbo::OnUpdateSetNull |
A constraint that cascades updates. | |
const ForeignKeyConstraint | Wt::Dbo::OnDeleteCascade |
A constraint that cascades deletes. | |
const ForeignKeyConstraint | Wt::Dbo::OnDeleteSetNull |
A constraint that cascades deletes. |
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, | ||
int | size = -1 |
||
) |
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::belongsTo | ( | Action & | action, |
ptr< C > & | value, | ||
const std::string & | name, | ||
ForeignKeyConstraint | constraints, | ||
int | size = -1 |
||
) |
Maps the "One"-side of a ManyToOne relation.
This overloaded method allows to specify constraints for the foreign key.
void Wt::Dbo::field | ( | Action & | action, |
V & | value, | ||
const std::string & | name, | ||
int | size = -1 |
||
) |
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 Wt::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 composite type which should be persisted in multiple database fields but not as a separate table (e.g. for natural composite primary keys, see id()).
For example:
struct Coordinate { int x, y; }; namespace Wt { namespace Dbo { template <class Action> void field(Action& action, Coordinate& coordinate, const std::string& name, int size = -1) { field(action, coordinate.x, name + "_x"); field(action, coordinate.y, name + "_y"); } } // namespace Dbo } // namespace Wt
To support a custom type that needs to be persisted as a single field, you should specialize sql_value_traits instead.
void Wt::Dbo::hasMany | ( | Action & | action, |
collection< ptr< C > > & | value, | ||
RelationType | type, | ||
const std::string & | joinName, | ||
const std::string & | joinId, | ||
ForeignKeyConstraint | constraints = NotNull |
||
) |
Maps the "Many"-side of a ManyToMany relation.
This function binds the collection field value
to contain objects (of type C
).
This overloaded method allows to customize the field name of the foreign id in the join table, and specify constraints for this foreign key. The only allowed value for type
is ManyToMany.
The joinId
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
.
void Wt::Dbo::hasMany | ( | Action & | action, |
collection< ptr< C > > & | value, | ||
RelationType | type, | ||
const std::string & | joinName | ||
) |
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. In the join table, this side of the the relation will be referenced using the table name + "_id" of the current class.
A hasMany() must have a counter-part belongsTo() or hasMany() declaration in the referenced class C
.
void Wt::Dbo::id | ( | Action & | action, |
V & | value, | ||
const std::string & | name = "id" , |
||
int | size = -1 |
||
) |
Maps a natural primary key (id) field.
A natural primary key field is optional. If you define one and its type is not long long
, you must specialize Wt::Dbo::dbo_traits to match the type V
as the IdType for this class. When not specified for a class, an auto-generated surrogate key field is used with the name specified by Wt::Dbo::dbo_traits::surrogateIdField(), which defaults to "id".
Unlike the default surrogate key, a natural id is not auto-generated and thus you need to give each object a unique value when creating a new object.
The id may be a composite type. In that case, you need to specialize Wt::Dbo::field().
const ForeignKeyConstraint Wt::Dbo::NotNull |
A constraint that prevents a null
ptr.
A database constraint which prevents that a ptr references no object and has a value of null
.
const ForeignKeyConstraint Wt::Dbo::OnDeleteCascade |
A constraint that cascades deletes.
A database constraint which propagates deletes of the referenced object to also delete the object(s) that reference it.
const ForeignKeyConstraint Wt::Dbo::OnDeleteSetNull |
A constraint that cascades deletes.
A database constraint which propagates deletes of the referenced object to also delete the objects that reference.
const ForeignKeyConstraint Wt::Dbo::OnUpdateCascade |
A constraint that cascades updates.
A database constraint which propagates updates to the natural primary key in the referenced table.
const ForeignKeyConstraint Wt::Dbo::OnUpdateSetNull |
A constraint that cascades updates.
A database constraint which sets the value of the ptr to null when the referenced primary key changes.