Comments (13)
- Not exactly singleton but the storage instance is designed to live as long as you need it
- Create one storage per one sqlite db, sync schema right after (optional), not one per call.
- Yes. The best way it to
typedef
a storage type bydecltype
of a return type of function that makes a storage. You can see example here
from sqlite_orm.
One more tip: initStorage
gotta be inline
if you want to include a header with it in several places
from sqlite_orm.
Thanks. I shall experiement it and decide. Do you how much memory Storage object takes? How much costly is contruction and destruction of it?
from sqlite_orm.
@Ninja-007 storage is very light. It holds data you passed in make_storage
call - member pointers, column/table names and table constraints objects, also one bool
indicating whether 'inmemory' db and one std::shared_ptr<database_connection>
from sqlite_orm.
@Ninja-007 is the question still actual?
from sqlite_orm.
No need of further help. So closing it.
Thanks for help.
from sqlite_orm.
Is it possible to return make_storage as pointer? It can be done by using make_storage_ptr.
I want to write class method which can call make_storage and return storage object. As return type is not known, it causes complier errors with auto keyword.
from sqlite_orm.
I found trick to do that without dealing with pointers.
The class member declaration should be
class XYZ
{
decltype(auto) GetDB() const;
decltype(auto) GetStaticDB() const;
};
in cpp of the class is
decltype(auto) XYZ::GetDB() const
{
return make_storage(GetDBPath(), ...);
}
decltype(auto) XYZ::GetStaticDB() const
{
static auto DB = GetDB();
return DB;
}
from sqlite_orm.
May be you can document it, it will be great for other users.
I keep it open, so you can see it easily. You may close it.
from sqlite_orm.
Pointers won't help you with type definitions. If you need an explicit storage type used trick from update.cpp
from sqlite_orm.
Thanks. My problem was creating make_storage equivalent function in class. As its return type is not know till runtime or hard to write at compile time, I was looking for pointer alternative. But it was solved by using decltype(auto) as return type. Compiler calculates it.
The update example also have typedef and dummy call Initstorage function. I cannot do it in class defination.
from sqlite_orm.
@Ninja-007 ok. Is the question still actual?
IMHO storage got to be located in a separate .hpp (and optionally .cpp) file located in Services
folder that contains project's services. This header may contain initStorage
function and custom types bindings if they exist.
from sqlite_orm.
Issue is solved. Thanks.
from sqlite_orm.
Related Issues (20)
- Templated Storage Schema - Compilation Issues HOT 10
- 怎样定义 make_storage 返回模板类型 的 c++类成员变量 HOT 1
- "no such table" error on existing database HOT 1
- Delete a foreign key HOT 3
- sqlite-orm fails to compile under uwp HOT 4
- C:\src\sqlite_orm\tests\schema\virtual_table.cpp(6): exception: no such module: FTS5: SQL logic error HOT 2
- I need to store a vector of vector<std::string> as a field in a persistent class, how can I do this? HOT 8
- add column sync_schema will recreate table HOT 12
- compile error with gcc 5.3.1 HOT 6
- Windows linker error SQLite3 HOT 3
- Warning on CMake >= 3.27 because of support for CMake >= 2.8.12
- Cannot Build my project HOT 2
- `SQLITE_DQS` Compile Option HOT 7
- Failed to compile origin/dev branch using GCC 8.3 HOT 2
- Do not understand select statement generation HOT 3
- Support for returning objects inside columns HOT 6
- Corrupted Databases HOT 10
- API has changed a bit : what is c<Type>? HOT 1
- why is this WITH not recursive? HOT 2
- FTS5 Options: Unindexed columns, prefix indexes, tokenizers & content HOT 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlite_orm.