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 (const Connection &)=delete | |
| Connection & | operator= (const Connection &)=delete |
| bool | isConnected () const |
| True while the underlying session is open. | |
| void | close () |
| Closes the session (idempotent). | |
| 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 | 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 | 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. | |
| Query * | from (std::string table) |
| Builds a fluent Query builder for a table. | |
| 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 第 62 行定义.
构造及析构函数说明
◆ Connection() [1/2]
| eve::database::Connection::Connection | ( | std::string | connector, |
| std::string | connectionString | ||
| ) |
◆ ~Connection()
| eve::database::Connection::~Connection | ( | ) |
在文件 Database.cpp 第 92 行定义.
引用了 close().
◆ Connection() [2/2]
|
delete |
成员函数说明
◆ close()
| void eve::database::Connection::close | ( | ) |
◆ execute()
Executes a statement; returns the affected row count.
在文件 Database.cpp 第 98 行定义.
引用了 execute(), isConnected() , 以及 query().
被这些函数引用 eve::database::Repository< T >::createTable(), execute(), exportECS(), insert(), remove() , 以及 update().
◆ exportECS()
|
inline |
ORM helper: persists a range of mapped entities in one transaction.
在文件 Database.h 第 112 行定义.
◆ from()
| Query * eve::database::Connection::from | ( | std::string | table | ) |
Builds a fluent Query builder for a table.
在文件 Database.cpp 第 173 行定义.
◆ insert()
Inserts a row map; returns the affected row count.
在文件 Database.cpp 第 121 行定义.
引用了 columns, data, execute(), query(), value , 以及 values.
被这些函数引用 exportECS(), eve::database::Repository< T >::insert(), insertJson() , 以及 save().
◆ insertJson()
Script-friendly insert: JSON must be an object of column/value pairs.
在文件 Database.cpp 第 150 行定义.
被这些函数引用 eve::database::Model::insertJson().
◆ isConnected()
| bool eve::database::Connection::isConnected | ( | ) | const |
True while the underlying session is open.
在文件 Database.cpp 第 93 行定义.
◆ model()
| Model * eve::database::Connection::model | ( | std::string | table, |
| std::string | primaryKey = "id" |
||
| ) |
Builds a script-facing Model repository for a table.
在文件 Database.cpp 第 170 行定义.
◆ 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 第 103 行定义.
引用了 isConnected() , 以及 query().
被这些函数引用 eve::database::Query::all(), eve::database::Repository< T >::all(), Connection(), eve::database::Query::count(), execute(), exportECS(), eve::database::Query::firstJson(), insert(), insertJson(), query(), queryByKey(), queryJson(), remove(), removeByKey(), save(), update(), updateByKey() , 以及 updateJson().
◆ 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 第 165 行定义.
引用了 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 第 119 行定义.
引用了 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 第 146 行定义.
被这些函数引用 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 第 161 行定义.
被这些函数引用 eve::database::Model::remove() , 以及 eve::database::Repository< T >::remove().
◆ save()
◆ 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 第 135 行定义.
引用了 execute(), query(), 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 第 157 行定义.
引用了 query(), 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 | ||
| ) |
Script-friendly update; whereClause is raw SQL.
在文件 Database.cpp 第 153 行定义.
该类的文档由以下文件生成:
- src/modules/database/Database.h
- src/modules/database/Database.cpp