载入中...
搜索中...
未找到
eve::database::Connection类 参考

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
 
Connectionoperator= (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< Rowquery (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< RowqueryByKey (const std::string &table, const std::string &key, const Value &id)
 Selects rows where key == id.
 
Modelmodel (std::string table, std::string primaryKey="id")
 Builds a script-facing Model repository for a table.
 
Queryfrom (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.h62 行定义.

构造及析构函数说明

◆ Connection() [1/2]

eve::database::Connection::Connection ( std::string  connector,
std::string  connectionString 
)

Opens a Poco::Data session; connector is e.g. "SQLite".

在文件 Database.cpp87 行定义.

引用了 query().

◆ ~Connection()

eve::database::Connection::~Connection ( )

在文件 Database.cpp92 行定义.

引用了 close().

◆ Connection() [2/2]

eve::database::Connection::Connection ( const Connection )
delete

成员函数说明

◆ close()

void eve::database::Connection::close ( )

Closes the session (idempotent).

在文件 Database.cpp94 行定义.

被这些函数引用 ~Connection().

◆ execute()

int eve::database::Connection::execute ( const std::string &  sql)

Executes a statement; returns the affected row count.

在文件 Database.cpp98 行定义.

引用了 execute(), isConnected() , 以及 query().

被这些函数引用 eve::database::Repository< T >::createTable(), execute(), exportECS(), insert(), remove() , 以及 update().

◆ exportECS()

template<class Range , class Mapper >
int eve::database::Connection::exportECS ( const std::string &  table,
const Range entities,
Mapper  mapper 
)
inline

ORM helper: persists a range of mapped entities in one transaction.

在文件 Database.h112 行定义.

引用了 execute(), insert() , 以及 query().

◆ from()

Query * eve::database::Connection::from ( std::string  table)

Builds a fluent Query builder for a table.

在文件 Database.cpp173 行定义.

◆ insert()

int eve::database::Connection::insert ( const std::string &  table,
const Row values 
)

Inserts a row map; returns the affected row count.

在文件 Database.cpp121 行定义.

引用了 columns, data, execute(), query(), value , 以及 values.

被这些函数引用 exportECS(), eve::database::Repository< T >::insert(), insertJson() , 以及 save().

◆ 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.cpp150 行定义.

引用了 insert() , 以及 query().

被这些函数引用 eve::database::Model::insertJson().

◆ isConnected()

bool eve::database::Connection::isConnected ( ) const

True while the underlying session is open.

在文件 Database.cpp93 行定义.

被这些函数引用 execute() , 以及 query().

◆ model()

Model * eve::database::Connection::model ( std::string  table,
std::string  primaryKey = "id" 
)

Builds a script-facing Model repository for a table.

在文件 Database.cpp170 行定义.

◆ operator=()

◆ query()

std::vector< Row > eve::database::Connection::query ( const std::string &  sql)

◆ 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.cpp165 行定义.

引用了 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.cpp119 行定义.

引用了 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.cpp146 行定义.

引用了 execute() , 以及 query().

被这些函数引用 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.cpp161 行定义.

引用了 query() , 以及 remove().

被这些函数引用 eve::database::Model::remove() , 以及 eve::database::Repository< T >::remove().

◆ save()

template<class T >
int eve::database::Connection::save ( const Mapping< T > &  mapping,
const T object 
)
inline

ORM helper: persists one mapped object.

在文件 Database.h106 行定义.

引用了 insert() , 以及 query().

◆ 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.cpp135 行定义.

引用了 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.cpp157 行定义.

引用了 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.cpp153 行定义.

引用了 query() , 以及 update().


该类的文档由以下文件生成: