7 #ifndef litesql_database_hpp
8 #define litesql_database_hpp
26 EqualName(
const std::string& name) : m_name(name) {};
37 std::string backendType;
43 void openDatabase() noexcept(
false);
51 std::string name, type, sql;
52 SchemaItem(
const std::string& n,
const std::string& t,
const std::string& s)
53 : name(n), type(t), sql(s) {}
60 return std::vector<SchemaItem>();
73 void upgradeTable(
const std::string& name,
const std::string& oldSchema,
const std::string& newSchema)
const;
75 bool addColumn(
const std::string & name,
const ColumnDefinition & column_def)
const;
86 Database(
const std::string& backendType,
const std::string& connInfo);
109 std::cerr <<
query << std::endl;
120 const std::vector<std::string>& fields=std::vector<std::string>())
const;
131 const std::string& sequence)
const;
Definition: database.hpp:23
Definition: database.hpp:18
used to iterate results of SQL statement, creates objects of type T from retrieved records.
Definition: cursor.hpp:21
intermediate representation of single entity in relational database, table, index or sequence
Definition: database.hpp:49
A base class of databases.
Definition: database.hpp:33
bool needsUpgrade() const
returns true if schema of backend database is different from schema returned by getSchema.
Definition: database.cpp:205
void insert(const std::string &table, const Record &r, const std::vector< std::string > &fields=std::vector< std::string >()) const
executes SQL INSERT statement.
Definition: database.cpp:247
void rollback() const
cancels active SQL transaction
Definition: database.hpp:142
void delete_(const std::string &table, const Expr &e=Expr()) const
deletes rows from single table, deleted rows are selected by Expr if specified
Definition: database.cpp:277
std::vector< SchemaItem > getCurrentSchema() const
queries 'schema' - table and converts results to SchemaItem-objects
Definition: database.cpp:47
void create() const
creates database based on getSchema
Definition: database.cpp:179
void upgrade() const
tries to upgrade database on disk so that schemas would be compatible
Definition: database.cpp:219
void commit() const
commits SQL transaction
Definition: database.hpp:140
virtual ~Database()
closes database
Definition: database.cpp:176
Database(const std::string &backendType, const std::string &connInfo)
opens connection to backend, throw exception if fails or cannot found a Backend class
void drop() const
converts CREATE-statements (of getSchema) to DROP statements and executes them
Definition: database.cpp:188
void upgradeTable(const std::string &name, const std::string &oldSchema, const std::string &newSchema) const
adds missing and removes extra fields to/from table (tries to preserve data).
Definition: database.cpp:94
virtual std::vector< SchemaItem > getSchema() const
returns database schema.
Definition: database.hpp:59
void storeSchemaItem(const SchemaItem &s) const
stores SchemaItem to 'schema' - table (deletes old versions)
Definition: database.cpp:35
std::unique_ptr< Backend > backend
backend implementation
Definition: database.hpp:46
void begin() const
begins SQL transaction
Definition: database.hpp:138
Records query(const std::string &query) const
executes SQL query
Definition: database.cpp:240
std::string groupInsert(const Record &tables, const Records &fields, const Records &values, const std::string &sequence) const
executes multiple INSERT-statements and assigns same 'row id' for first field of every record
Definition: database.cpp:261
bool verbose
verbosity, prints queries to cerr if true
Definition: database.hpp:79
A base class for expression in WHERE - clause.
Definition: expr.hpp:18
SQL data row wrapper.
Definition: types.hpp:20
Contains Expr-class hierarchy and operator overloadings for them.
std::vector< Record > Records
shortcut
Definition: types.hpp:26