Nut/src/query.cpp

89 lines
2.8 KiB
C++
Raw Normal View History

2016-06-05 20:22:26 +08:00
/*!************************************************************************
2016-05-12 14:08:58 +08:00
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Nut is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#include "query.h"
2017-02-01 18:01:21 +08:00
NUT_BEGIN_NAMESPACE
2016-05-12 14:08:58 +08:00
2016-06-05 20:22:26 +08:00
QueryPrivate::QueryPrivate(QueryBase *parent) : q_ptr(parent),
2019-02-10 22:11:22 +08:00
database(nullptr), tableSet(nullptr), skip(-1), take(-1)
2016-06-05 20:22:26 +08:00
{
}
/*!
* \class Query
* \brief This class hold a query. A query can be used for getting database rows, editing or deleting without row fetching.
2016-06-10 16:14:31 +08:00
* A query can be used for getting data from database.
* \code
* auto q = db.posts()->createQuery();
* q->join(Post::commentsTable());
* q->orderBy(!Post::saveDateField() & Post::bodyField());
* q->setWhere(Post::idField() > 5);
*
* auto posts = q->toList();
* \endcode
* In below code posts is a QList<Post> that contain rows from database from this query:
* \code
* SELECT * FROM post WHERE post.id>5 ORDER BY post.saveDate DESC, post.body
* \endcode
2016-06-05 20:22:26 +08:00
*/
/*!
2016-06-10 16:14:31 +08:00
* \fn QList<T *> Query::toList(int count = -1)
2016-06-05 20:22:26 +08:00
* \param count Total rows must be returned
* \return This function return class itself
* This function return rows
*/
/*!
2016-06-10 16:14:31 +08:00
* \fn Query<T> *Query::setWhere(WherePhrase where)
* Where phrase is a phrase using table's static field methods.
* \code
* q->setWhere(Post::idField() == 4 || Post::titleField().isNull());
* \endcode
* In sql this is like below code:
* \code
* ... WHERE post.id=4 OR post.title IS NULL
* \endcode
2016-06-05 20:22:26 +08:00
* \param where Where phrase
* \return This function return class itself
*/
/*!
2016-06-10 16:14:31 +08:00
* \fn Query<T> *Query::orderBy(WherePhrase phrase)
2016-06-05 20:22:26 +08:00
* \param phrase Order phrase
* \return This function return class itself
* orderBy set a new order for this query. Order can be a hrase like that:
* \code
* query->orderBy(Post::idField());
* \endcode
* If you need more than one order field seprate them by & operator, example:
* \code
* query->orderBy(Post::idField() & Post::bodyField());
* \endcode
* Order can be also DESC, for that put exclamation mark near field
* \code
* query->orderBy(!Post::idField & Post::bodyField());
* \endcode
*/
2017-02-01 18:01:21 +08:00
NUT_END_NAMESPACE