Git Product home page Git Product logo

Comments (13)

fnc12 avatar fnc12 commented on May 19, 2024
  1. Not exactly singleton but the storage instance is designed to live as long as you need it
  2. Create one storage per one sqlite db, sync schema right after (optional), not one per call.
  3. Yes. The best way it to typedef a storage type by decltype of a return type of function that makes a storage. You can see example here

from sqlite_orm.

fnc12 avatar fnc12 commented on May 19, 2024

One more tip: initStorage gotta be inline if you want to include a header with it in several places

from sqlite_orm.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

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.

fnc12 avatar fnc12 commented on May 19, 2024

@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.

fnc12 avatar fnc12 commented on May 19, 2024

@Ninja-007 is the question still actual?

from sqlite_orm.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

No need of further help. So closing it.
Thanks for help.

from sqlite_orm.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

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.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

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.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

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.

fnc12 avatar fnc12 commented on May 19, 2024

Pointers won't help you with type definitions. If you need an explicit storage type used trick from update.cpp

from sqlite_orm.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

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.

fnc12 avatar fnc12 commented on May 19, 2024

@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.

DonaldTrump88 avatar DonaldTrump88 commented on May 19, 2024

Issue is solved. Thanks.

from sqlite_orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.