A base class of databases.
More...
#include <database.hpp>
|
| class | SchemaItem |
| | intermediate representation of single entity in relational database, table, index or sequence More...
|
| |
|
| | Database (const string &backendType, const string &connInfo) |
| | opens connection to backend, throw exception if fails or cannot found a Backend class More...
|
| |
| | Database (const Database &op) |
| | opens new connection to same database More...
|
| |
|
virtual | ~Database () |
| | closes database
|
| |
|
void | create () const |
| | creates database based on getSchema
|
| |
|
void | drop () const |
| | converts CREATE-statements (of getSchema) to DROP statements and executes them
|
| |
| bool | needsUpgrade () const |
| | returns true if schema of backend database is different from schema returned by getSchema. More...
|
| |
|
void | upgrade () const |
| | tries to upgrade database on disk so that schemas would be compatible
|
| |
| Records | query (const string &query) const |
| | executes SQL query More...
|
| |
|
template<class T > |
| Cursor< T > | cursor (const string &query) const |
| |
| void | insert (const string &table, const Record &r, const Split &fields=Split()) const |
| | executes SQL INSERT statement. More...
|
| |
| string | groupInsert (Record tables, Records fields, Records values, string sequence) const |
| | executes multiple INSERT-statements and assigns same 'row id' for first field of every record More...
|
| |
| void | delete_ (const string &table, const Expr &e=Expr()) const |
| | deletes rows from single table, deleted rows are selected by Expr if specified More...
|
| |
|
void | begin () const |
| | begins SQL transaction
|
| |
|
void | commit () const |
| | commits SQL transaction
|
| |
|
void | rollback () const |
| | cancels active SQL transaction
|
| |
|
|
bool | verbose |
| | verbosity, prints queries to cerr if true
|
| |
A base class of databases.
Can be used without inheriting own version of Database using query()-method. See Defining Database
◆ Database() [1/2]
| litesql::Database::Database |
( |
const string & |
backendType, |
|
|
const string & |
connInfo |
|
) |
| |
opens connection to backend, throw exception if fails or cannot found a Backend class
- Parameters
-
| backendType | backend type ("postgresql","mysql" or "sqlite3") |
| connInfo | connection params, syntax "param=value param=value ..." valid keys: host,user,password,database and port |
◆ Database() [2/2]
| litesql::Database::Database |
( |
const Database & |
op | ) |
|
opens new connection to same database
- Parameters
-
◆ delete_()
| void litesql::Database::delete_ |
( |
const string & |
table, |
|
|
const Expr & |
e = Expr() |
|
) |
| const |
deletes rows from single table, deleted rows are selected by Expr if specified
- Parameters
-
| table | target table |
| e | selection expression |
References query().
◆ getCurrentSchema()
queries 'schema' - table and converts results to SchemaItem-objects
- Returns
- SchemaItem-objects
Referenced by needsUpgrade(), and upgrade().
◆ getSchema()
| virtual std::vector<SchemaItem> litesql::Database::getSchema |
( |
| ) |
const |
|
inlineprotectedvirtual |
◆ groupInsert()
| string litesql::Database::groupInsert |
( |
Record |
tables, |
|
|
Records |
fields, |
|
|
Records |
values, |
|
|
string |
sequence |
|
) |
| const |
executes multiple INSERT-statements and assigns same 'row id' for first field of every record
- Parameters
-
| tables | destination tables for insert operation |
| fields | record of field names per table |
| values | record of values per table |
| sequence | sequence where row id-numbers are pulled |
- Returns
- new row id
References backend, litesql::Backend::groupInsert(), litesql::Split::join(), and verbose.
◆ insert()
| void litesql::Database::insert |
( |
const string & |
table, |
|
|
const Record & |
r, |
|
|
const Split & |
fields = Split() |
|
) |
| const |
◆ needsUpgrade()
| bool litesql::Database::needsUpgrade |
( |
| ) |
const |
◆ query()
| Records litesql::Database::query |
( |
const string & |
query | ) |
const |
◆ upgradeTable()
| void litesql::Database::upgradeTable |
( |
string |
name, |
|
|
string |
oldSchema, |
|
|
string |
newSchema |
|
) |
| const |
|
protected |
adds missing and removes extra fields to/from table (tries to preserve data).
copies data to a temporary table and then back to upgraded table because all backends do not support ALTER TABLE ADD ... - SQL statements.
- Parameters
-
| name | table name |
| oldSchema | current schema of table |
| newSchema | upgraded schema of table |
References litesql::Split::join().
Referenced by upgrade().
The documentation for this class was generated from the following files: