WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
framework::sqlite::SQLiteDatabaseModel Class Referenceabstract

Providing SELECT, INSERT, UPDATE, DELETE or raw queries for SQLiteDatabase. More...

#include <SQLiteDatabaseModel.h>

Public Member Functions

 SQLiteDatabaseModel (const SQLiteDatabaseModel &)=delete
 
SQLiteDatabaseModeloperator= (const SQLiteDatabaseModel &)=delete
 
 SQLiteDatabaseModel (SQLiteDatabaseModel &&other) noexcept=default
 
SQLiteDatabaseModeloperator= (SQLiteDatabaseModel &&other) noexcept=default
 
utility::SQLiteResult raw (const std::string &query)
 Raw SQL query.
 
virtual void createTable (const std::vector< std::pair< std::string, std::string > > &attributes={})
 Create table.
 
virtual void dropTable ()
 Delete table.
 
virtual void recreateTable (const std::vector< std::pair< std::string, std::string > > &attributes={})
 Delete and create table.
 
virtual utility::SQLiteResult insert (const std::unordered_map< std::string, std::string > &attributes={})
 INSERT row.
 
virtual void update (const std::unordered_map< std::string, std::string > &attributes, const std::string &fieldName, const std::string &fieldValue)
 UPDATE table.
 
virtual void deleteQuery (const std::string &fieldName, const std::string &fieldValue)
 Delete from table.
 
virtual void deleteQuery (const std::unordered_map< std::string, std::string > &attributes={})
 Delete from table.
 
utility::SQLiteResult selectAll ()
 SELECT all.
 
virtual utility::SQLiteResult selectByField (const std::string &fieldName, const std::string &fieldValue)
 SELECT with condition.
 
virtual utility::SQLiteResult selectByField (const std::unordered_map< std::string, std::string > &attributes)
 SELECT with condition.
 
virtual std::string_view getDatabaseName () const =0
 
virtual std::string_view getTableName () const =0
 

Static Public Attributes

static constexpr std::string_view databaseName = ""
 
static constexpr std::string_view tableName = ""
 

Protected Member Functions

utility::SQLiteResult execute (const std::string &query)
 Execute raw query.
 

Static Protected Member Functions

static bool isNumber (std::string_view source)
 Check that string represent number.
 
static std::string convertToValue (std::string_view source)
 If source is string surrounds it with quotes.
 

Protected Attributes

std::shared_ptr< SQLiteDatabasedatabase
 

Friends

class SQLiteManager
 

Detailed Description

Providing SELECT, INSERT, UPDATE, DELETE or raw queries for SQLiteDatabase.

Definition at line 20 of file SQLiteDatabaseModel.h.

Constructor & Destructor Documentation

◆ SQLiteDatabaseModel()

framework::sqlite::SQLiteDatabaseModel::SQLiteDatabaseModel ( )

Definition at line 81 of file SQLiteDatabaseModel.cpp.

Member Function Documentation

◆ convertToValue()

string framework::sqlite::SQLiteDatabaseModel::convertToValue ( std::string_view source)
staticprotected

If source is string surrounds it with quotes.

Parameters
sourceAttribute value
Returns

Definition at line 43 of file SQLiteDatabaseModel.cpp.

◆ createTable()

void framework::sqlite::SQLiteDatabaseModel::createTable ( const std::vector< std::pair< std::string, std::string > > & attributes = {})
virtual

Create table.

Parameters
attributesfield name - field description
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 92 of file SQLiteDatabaseModel.cpp.

◆ deleteQuery() [1/2]

virtual void framework::sqlite::SQLiteDatabaseModel::deleteQuery ( const std::string & fieldName,
const std::string & fieldValue )
virtual

Delete from table.

Parameters
fieldNamefor condition
fieldValuefor condition
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

◆ deleteQuery() [2/2]

virtual void framework::sqlite::SQLiteDatabaseModel::deleteQuery ( const std::unordered_map< std::string, std::string > & attributes = {})
virtual

Delete from table.

Parameters
attributeskey - value condition
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

◆ dropTable()

void framework::sqlite::SQLiteDatabaseModel::dropTable ( )
virtual

Delete table.

Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 106 of file SQLiteDatabaseModel.cpp.

◆ execute()

utility::SQLiteResult framework::sqlite::SQLiteDatabaseModel::execute ( const std::string & query)
protected

Execute raw query.

Parameters
queryraw query
Returns
execution result

Definition at line 48 of file SQLiteDatabaseModel.cpp.

◆ insert()

utility::SQLiteResult framework::sqlite::SQLiteDatabaseModel::insert ( const std::unordered_map< std::string, std::string > & attributes = {})
virtual

INSERT row.

Parameters
attributesfield name - field value
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 118 of file SQLiteDatabaseModel.cpp.

◆ isNumber()

bool framework::sqlite::SQLiteDatabaseModel::isNumber ( std::string_view source)
staticprotected

Check that string represent number.

Parameters
sourceAttribute value
Returns
true if source is correct number, false otherwise

Definition at line 11 of file SQLiteDatabaseModel.cpp.

◆ raw()

utility::SQLiteResult framework::sqlite::SQLiteDatabaseModel::raw ( const std::string & query)

Raw SQL query.

Parameters
querySQL query
Returns
result of SELECT query, empty string otherwise
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 87 of file SQLiteDatabaseModel.cpp.

◆ recreateTable()

void framework::sqlite::SQLiteDatabaseModel::recreateTable ( const std::vector< std::pair< std::string, std::string > > & attributes = {})
virtual

Delete and create table.

Parameters
attributesfield name- field description
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 111 of file SQLiteDatabaseModel.cpp.

◆ selectAll()

utility::SQLiteResult framework::sqlite::SQLiteDatabaseModel::selectAll ( )

SELECT all.

Returns
all rows from table
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 165 of file SQLiteDatabaseModel.cpp.

◆ selectByField() [1/2]

virtual utility::SQLiteResult framework::sqlite::SQLiteDatabaseModel::selectByField ( const std::string & fieldName,
const std::string & fieldValue )
virtual

SELECT with condition.

Parameters
fieldNamefor condition
fieldValuefor condition
Returns
all rows that accept condition
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

◆ selectByField() [2/2]

virtual utility::SQLiteResult framework::sqlite::SQLiteDatabaseModel::selectByField ( const std::unordered_map< std::string, std::string > & attributes)
virtual

SELECT with condition.

Parameters
valuesfield name - field value
Returns
all rows that accept condition
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

◆ update()

void framework::sqlite::SQLiteDatabaseModel::update ( const std::unordered_map< std::string, std::string > & attributes,
const std::string & fieldName,
const std::string & fieldValue )
virtual

UPDATE table.

Parameters
attributesnew values
fieldNamefor condition
fieldValuefor condition
Exceptions
framework::exceptions::SQLite3Exceptionsqlite3_errmsg

Definition at line 132 of file SQLiteDatabaseModel.cpp.

Friends And Related Symbol Documentation

◆ SQLiteManager

friend class SQLiteManager
friend

Definition at line 153 of file SQLiteDatabaseModel.h.

Member Data Documentation

◆ database

std::shared_ptr<SQLiteDatabase> framework::sqlite::SQLiteDatabaseModel::database
protected

Definition at line 27 of file SQLiteDatabaseModel.h.

◆ databaseName

std::string_view framework::sqlite::SQLiteDatabaseModel::databaseName = ""
staticconstexpr

Definition at line 23 of file SQLiteDatabaseModel.h.

◆ tableName

std::string_view framework::sqlite::SQLiteDatabaseModel::tableName = ""
staticconstexpr

Definition at line 24 of file SQLiteDatabaseModel.h.


The documentation for this class was generated from the following files: