9 #ifndef litesql_datasource_hpp
10 #define litesql_datasource_hpp
29 std::vector<FieldType> fdatas;
30 T::getFieldTypes(fdatas);
50 : db(db_), sel(sel_) {
61 idq.result(T::Id.fullName());
68 cq.limit(0).offset(0);
69 cq.result(
"count(*)");
78 return db.template cursor<T>(sel);
86 std::vector<T>
all()
const {
95 sel.orderBy(f.fullName(), asc);
104 sel.source(
id.table());
105 sel.where(
id == T::Id);
106 sel.orderBy(f.fullName(), asc);
used to iterate results of SQL statement, creates objects of type T from retrieved records.
Definition: cursor.hpp:21
template class which holds SelectQuery for selecting objects of type T
Definition: datasource.hpp:35
size_t count() const
returns number of objects in result set
Definition: datasource.hpp:65
std::vector< T > all() const
returns all objects in result set.
Definition: datasource.hpp:86
DataSource & orderBy(FieldType f, bool asc=true)
modifies SelectQuery to order result set
Definition: datasource.hpp:94
SelectQuery objectQuery() const
returns SelectQuery which selects objects
Definition: datasource.hpp:73
DataSource & orderByRelation(FieldType id, FieldType f, bool asc=true)
modifies SelectQuery to order result set by external table
Definition: datasource.hpp:103
DataSource(const Database &db_, const SelectQuery &sel_)
Definition: datasource.hpp:49
DataSource(const Database &db_, const Expr &e=Expr())
Definition: datasource.hpp:44
SelectQuery idQuery() const
returns SelectQuery which selects ID-numbers of objects
Definition: datasource.hpp:58
Cursor< T > cursor() const
returns cursor for query
Definition: datasource.hpp:77
T one() const
returns first object in result set.
Definition: datasource.hpp:82
const Database & getDatabase() const
returns database reference
Definition: datasource.hpp:54
A base class of databases.
Definition: database.hpp:33
Records query(const std::string &query) const
executes SQL query
Definition: database.cpp:240
A base class for expression in WHERE - clause.
Definition: expr.hpp:18
a class that helps creating SELECT-SQL statements.
Definition: selectquery.hpp:20
SelectQuery selectObjectQuery(const std::vector< FieldType > &fdatas, const Expr &e=Expr())
returns SelectQuery which selects objects of type T
contains SelectQuery-class.
int atoi(const std::string &s)
string version of atoi