SQLite connection with a small ORM layer on top of Poco::Data. Tables/columns are quoted identifiers; values are bound as literals. 更多...
#include <Database.h>
Public 成员函数 | |
| Connection (std::string connector, std::string connectionString) | |
| Opens a Poco::Data session; connector is e.g. "SQLite". | |
| ~Connection () | |
| Connection. | |
| Connection (const Connection &)=delete | |
| Connection & | operator= (const Connection &)=delete |
| bool | isConnected () const |
| True while the underlying session is open. | |
| void | close () |
| Closes the session (idempotent). | |
| eve::Result< void > | beginTransaction () |
Begins a nested-counted transaction (BEGIN on the outermost enter). | |
| eve::Result< void > | commitTransaction () |
Commits one nesting level (COMMIT when the outermost level exits). | |
| eve::Result< void > | rollbackTransaction () |
| Rolls back the whole open transaction and clears nesting. | |
| bool | begin () |
| Compatibility-only boolean facade over beginTransaction(). | |
| bool | commit () |
| Compatibility-only boolean facade over commitTransaction(). | |
| bool | rollback () |
| Compatibility-only boolean facade over rollbackTransaction(). | |
| bool | isInTransaction () const |
| True while at least one beginTransaction() nesting level is open. | |
| bool | inTransaction () const |
| Compatibility-only boolean alias of isInTransaction(). | |
| int | execute (const std::string &sql) |
| Executes a statement; returns the affected row count. | |
| std::vector< Row > | query (const std::string &sql) |
| Runs a SELECT and returns every row as name/value maps. | |
| std::string | queryJson (const std::string &sql) |
| Runs query() and serializes the rows to a JSON array. | |
| int | insert (const std::string &table, const Row &values) |
| Inserts a row map; returns the affected row count. | |
| int | upsert (const std::string &table, const Row &values) |
Insert-or-replace a row map (INSERT OR REPLACE); returns affected rows. | |
| int | update (const std::string &table, const Row &values, const std::string &whereClause) |
| Updates rows matching whereClause; returns the affected row count. | |
| int | remove (const std::string &table, const std::string &whereClause) |
| Deletes rows matching whereClause; returns the affected row count. | |
| int | insertJson (const std::string &table, const std::string &json) |
| Script-friendly insert: JSON must be an object of column/value pairs. | |
| int | upsertJson (const std::string &table, const std::string &json) |
| Script-friendly insert-or-replace from a JSON object. | |
| int | updateJson (const std::string &table, const std::string &json, const std::string &whereClause) |
| Script-friendly update; whereClause is raw SQL. | |
| int | updateByKey (const std::string &table, const Row &values, const std::string &key, const Value &id) |
| Updates a single row by primary key value. | |
| int | removeByKey (const std::string &table, const std::string &key, const Value &id) |
| Deletes a single row by primary key value. | |
| std::vector< Row > | queryByKey (const std::string &table, const std::string &key, const Value &id) |
| Selects rows where key == id. | |
| Model * | model (std::string table, std::string primaryKey="id") |
| Builds a script-facing Model repository for a table. @ownership Caller deletes. @lifetime Valid until the caller deletes it; must not outlive this Connection. | |
| Query * | from (std::string table) |
| Builds a fluent Query builder for a table. @ownership Caller deletes. @lifetime Valid until the caller deletes it; must not outlive this Connection. | |
| template<class T > | |
| int | save (const Mapping< T > &mapping, const T &object) |
| ORM helper: persists one mapped object. | |
| template<class Range , class Mapper > | |
| int | exportECS (const std::string &table, const Range &entities, Mapper mapper) |
| ORM helper: persists a range of mapped entities in one transaction. | |
详细描述
SQLite connection with a small ORM layer on top of Poco::Data. Tables/columns are quoted identifiers; values are bound as literals.
在文件 Database.h 第 71 行定义.
构造及析构函数说明
◆ Connection() [1/2]
| eve::database::Connection::Connection | ( | std::string | connector, |
| std::string | connectionString | ||
| ) |
Opens a Poco::Data session; connector is e.g. "SQLite".
在文件 Database.cpp 第 168 行定义.
◆ ~Connection()
| eve::database::Connection::~Connection | ( | ) |
◆ Connection() [2/2]
|
delete |
成员函数说明
◆ begin()
| bool eve::database::Connection::begin | ( | ) |
Compatibility-only boolean facade over beginTransaction().
在文件 Database.cpp 第 228 行定义.
引用了 beginTransaction() , 以及 eve::Result< void >::ok().
◆ beginTransaction()
| eve::Result< void > eve::database::Connection::beginTransaction | ( | ) |
Begins a nested-counted transaction (BEGIN on the outermost enter).
在文件 Database.cpp 第 188 行定义.
引用了 eve::Diagnostic::error(), execute(), eve::Result< T >::failure(), isConnected(), eve::PreconditionViolation , 以及 eve::Result< T >::success().
被这些函数引用 begin().
◆ close()
| void eve::database::Connection::close | ( | ) |
◆ commit()
| bool eve::database::Connection::commit | ( | ) |
Compatibility-only boolean facade over commitTransaction().
在文件 Database.cpp 第 230 行定义.
引用了 commitTransaction() , 以及 eve::Result< void >::ok().
◆ commitTransaction()
| eve::Result< void > eve::database::Connection::commitTransaction | ( | ) |
Commits one nesting level (COMMIT when the outermost level exits).
在文件 Database.cpp 第 198 行定义.
引用了 eve::Diagnostic::error(), execute(), eve::Result< T >::failure(), isConnected(), eve::PreconditionViolation , 以及 eve::Result< T >::success().
被这些函数引用 commit().
◆ execute()
| int eve::database::Connection::execute | ( | const std::string & | sql | ) |
Executes a statement; returns the affected row count.
在文件 Database.cpp 第 238 行定义.
引用了 execute() , 以及 isConnected().
被这些函数引用 beginTransaction(), close(), commitTransaction(), eve::database::Repository< T >::createTable(), execute(), insert(), remove(), rollbackTransaction(), update() , 以及 upsert().
◆ exportECS()
|
inline |
ORM helper: persists a range of mapped entities in one transaction.
Export ecs.
Execute.
Execute.
Execute.
在文件 Database.h 第 153 行定义.
◆ from()
| Query * eve::database::Connection::from | ( | std::string | table | ) |
Builds a fluent Query builder for a table. @ownership Caller deletes. @lifetime Valid until the caller deletes it; must not outlive this Connection.
在文件 Database.cpp 第 330 行定义.
◆ insert()
| int eve::database::Connection::insert | ( | const std::string & | table, |
| const Row & | values | ||
| ) |
Inserts a row map; returns the affected row count.
在文件 Database.cpp 第 261 行定义.
引用了 columns, execute(), key, literal, value , 以及 values.
被这些函数引用 eve::database::Repository< T >::insert() , 以及 insertJson().
◆ insertJson()
| int eve::database::Connection::insertJson | ( | const std::string & | table, |
| const std::string & | json | ||
| ) |
Script-friendly insert: JSON must be an object of column/value pairs.
在文件 Database.cpp 第 304 行定义.
引用了 insert().
被这些函数引用 eve::database::Model::insertJson().
◆ inTransaction()
| bool eve::database::Connection::inTransaction | ( | ) | const |
Compatibility-only boolean alias of isInTransaction().
在文件 Database.cpp 第 236 行定义.
引用了 isInTransaction().
◆ isConnected()
| bool eve::database::Connection::isConnected | ( | ) | const |
True while the underlying session is open.
在文件 Database.cpp 第 174 行定义.
被这些函数引用 beginTransaction(), commitTransaction(), execute(), query() , 以及 rollbackTransaction().
◆ isInTransaction()
| bool eve::database::Connection::isInTransaction | ( | ) | const |
True while at least one beginTransaction() nesting level is open.
在文件 Database.cpp 第 234 行定义.
被这些函数引用 inTransaction().
◆ model()
| Model * eve::database::Connection::model | ( | std::string | table, |
| std::string | primaryKey = "id" |
||
| ) |
Builds a script-facing Model repository for a table. @ownership Caller deletes. @lifetime Valid until the caller deletes it; must not outlive this Connection.
在文件 Database.cpp 第 327 行定义.
◆ operator=()
|
delete |
◆ query()
| std::vector< Row > eve::database::Connection::query | ( | const std::string & | sql | ) |
Runs a SELECT and returns every row as name/value maps.
在文件 Database.cpp 第 243 行定义.
引用了 column, isConnected() , 以及 result.
被这些函数引用 eve::database::Query::all(), eve::database::Repository< T >::all(), eve::database::Query::count(), eve::database::Query::firstJson(), queryByKey() , 以及 queryJson().
◆ queryByKey()
| std::vector< Row > eve::database::Connection::queryByKey | ( | const std::string & | table, |
| const std::string & | key, | ||
| const Value & | id | ||
| ) |
Selects rows where key == id.
在文件 Database.cpp 第 322 行定义.
引用了 key, literal , 以及 query().
被这些函数引用 eve::database::Repository< T >::find() , 以及 eve::database::Model::findJson().
◆ queryJson()
| std::string eve::database::Connection::queryJson | ( | const std::string & | sql | ) |
Runs query() and serializes the rows to a JSON array.
在文件 Database.cpp 第 259 行定义.
引用了 query().
被这些函数引用 eve::database::Model::allJson().
◆ remove()
| int eve::database::Connection::remove | ( | const std::string & | table, |
| const std::string & | whereClause | ||
| ) |
Deletes rows matching whereClause; returns the affected row count.
在文件 Database.cpp 第 300 行定义.
引用了 execute().
被这些函数引用 removeByKey().
◆ removeByKey()
| int eve::database::Connection::removeByKey | ( | const std::string & | table, |
| const std::string & | key, | ||
| const Value & | id | ||
| ) |
Deletes a single row by primary key value.
在文件 Database.cpp 第 318 行定义.
引用了 key, literal , 以及 remove().
被这些函数引用 eve::database::Model::remove() , 以及 eve::database::Repository< T >::remove().
◆ rollback()
| bool eve::database::Connection::rollback | ( | ) |
Compatibility-only boolean facade over rollbackTransaction().
在文件 Database.cpp 第 232 行定义.
◆ rollbackTransaction()
| eve::Result< void > eve::database::Connection::rollbackTransaction | ( | ) |
Rolls back the whole open transaction and clears nesting.
在文件 Database.cpp 第 212 行定义.
引用了 eve::Diagnostic::error(), execute(), eve::Result< T >::failure(), isConnected(), eve::PreconditionViolation , 以及 eve::Result< T >::success().
被这些函数引用 rollback().
◆ save()
|
inline |
ORM helper: persists one mapped object.
Saves save.
Inserts insert.
在文件 Database.h 第 145 行定义.
引用了 eve::database::Mapping< T >::table , 以及 eve::database::Mapping< T >::toRow().
◆ update()
| int eve::database::Connection::update | ( | const std::string & | table, |
| const Row & | values, | ||
| const std::string & | whereClause | ||
| ) |
Updates rows matching whereClause; returns the affected row count.
在文件 Database.cpp 第 289 行定义.
引用了 execute(), key, literal, value , 以及 values.
被这些函数引用 updateByKey() , 以及 updateJson().
◆ updateByKey()
| int eve::database::Connection::updateByKey | ( | const std::string & | table, |
| const Row & | values, | ||
| const std::string & | key, | ||
| const Value & | id | ||
| ) |
Updates a single row by primary key value.
在文件 Database.cpp 第 314 行定义.
引用了 key, literal, update() , 以及 values.
被这些函数引用 eve::database::Repository< T >::update() , 以及 eve::database::Model::updateJson().
◆ updateJson()
| int eve::database::Connection::updateJson | ( | const std::string & | table, |
| const std::string & | json, | ||
| const std::string & | whereClause | ||
| ) |
◆ upsert()
| int eve::database::Connection::upsert | ( | const std::string & | table, |
| const Row & | values | ||
| ) |
Insert-or-replace a row map (INSERT OR REPLACE); returns affected rows.
在文件 Database.cpp 第 275 行定义.
引用了 columns, execute(), key, literal, value , 以及 values.
被这些函数引用 upsertJson().
◆ upsertJson()
| int eve::database::Connection::upsertJson | ( | const std::string & | table, |
| const std::string & | json | ||
| ) |
该类的文档由以下文件生成:
- src/modules/database/Database.h
- src/modules/database/Database.cpp