Separation of DB and ORM functionality request
There is some functionality which does not need table(s), for example drop_table, user_version. These operate above ORM functionality. Creating ORM storage object to use this functionality is not always possible and logical. For example, checking existence of table, checking version of database. I see there are two alternatives.
- Creation of separate class which deals with database functionality and adding make_db equivalent to make_storage without tables. (preferred)
- extending make_storage to make tables optional.
DB -int user_version() -void user_version(int value) -bool table_exists(const std::string &tableName) -std::string libversion() -void drop_table(const std::string &tableName) -int changes()??? -int total_changes()??? -int64 last_insert_rowid()??? -std::string current_timestamp(sqlite3 *db)???
Possible candidates with modification -void backup_table(sqlite3 *db) -void create_table(sqlite3 *db, const std::string &tableName) -void copy_table(sqlite3 *db, const std::string &name) -void rename_table(sqlite3 *db, const std::string &oldName, const std::string &newName)
This is excess over-engineering. Separation will make interface complicated.
If you do not need columns you can create a storage with no columns with auto emptyStorage = make_storage("empty.sqlite");
Thanks, let me try it.
What will happen when I call select (i.e. CRUD) on this make_storage("empty.sqlite"); instance?
You'll get compile time error with static_assert that tells you that type isn't mapped to the storage
auto DB = make_storage(GetDBPath());
DB.table_exists("TableNames");
sqlite_orm/sqlite_orm.h:5049: error: ‘sqlite_orm::storage_t<>::impl_type {aka struct sqlite_orm::storage_impl<>}’ has no member named ‘table_exists’ return this->impl.table_exists(tableName, db); ~~~~~~~~~~~^~~~~~~~~~~~
Ok. I'll fix it now
Thanks, closed.
When I calll sync_schema one Storage without tables, I do not get compile errors. These functions get called.
template<class ...Ts>
struct storage_impl {
std::map<std::string, sync_schema_result> sync_schema(sqlite3 *, bool) {
return {};
}
std::map<std::string, sync_schema_result> sync_schema_simulate(sqlite3 *, bool) {
return {};
}
};
.
That's correct. You get empty map cause there are no mapped types in a storage.
OK, Can you put assert there?
No. It works correctly. sync_schema syncs tables. If there are no tables you get empty map and 0 tables are synced. There is nothing incorrect here.
OK