Database Objects (Dbo)

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::FixedSqlConnectionPool
 A connection pool of fixed size. 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, BindStrategy >
 A database query. More...
class  Wt::Dbo::QueryModel< Result >
 A Wt MVC Model to view the results of a 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::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

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.

Detailed Description

An implemenation of an Object Relational Mapping layer.

For an introduction, see the tutorial.


Enumeration Type Documentation

Type of an SQL relation.

Enumerator:
ManyToOne  Many-to-One relationship.
ManyToMany  Many-to-Many relationship.


Function Documentation

template<class Action, class C>
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.

See also:
hasMany()

template<class Action, typename V>
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 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.

For example:

 struct Coordinate {
   int x, y;
 };

 namespace Wt {
   namespace Dbo {

     template <class Action>
     void field(Action& action, Coordinate& coordinate, const std::string& name)
     {
       field(action, coordinate.x, name + "_x");
       field(action, coordinate.y, name + "_y");
     }

   } // namespace Wt
 } // namespace dbo

To support a custom type that needs to be persisted as a single field, you should specialize sql_value_traits instead.

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 = "" 
) [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.

See also:
belongsTo()


Generated on Thu May 20 18:14:32 2010 for Wt by doxygen 1.5.6