Sqlite_orm: What if a data member is a std::shared_ptr<T>?

Created on 5 Sep 2018  路  6Comments  路  Source: fnc12/sqlite_orm

Is it possible to store/retrieve structs where at least one data member is a smart pointer?

Any example?

Thanks!!

question

All 6 comments

There is an example already located in readme. std::shared_ptr and std::unique_ptr map to a storage as a nullable types by default as is. Also you can bind your custom type as a nullable. For example nullable enum

Ok, but the general case where std::shared_ptr holds a class does not work, right? Need to implement the relationship between entities with foreign keys, correct? That is, the following will not compile ever:

    class Category
    {
    public:
        std::string                 m_name;
        bool                        m_real_expense_or_income;
    };
    class StatementLine
    {
    public:
        std::shared_ptr<Category>   m_category;
       }

Thanks!

yes, std::shared_ptr works out of the box only if you use basic types like int, float, std::string and other that can map to a column. The thing you want is the same thing you were asking in https://github.com/fnc12/sqlite_orm/issues/184

I apologize if I repeated the question.. Thanks for answering though.

@juandent was it clear for you or do I need to answer it somehow another way?

I think I get it: basically connect entities with foreign/primary keys.

Thank you so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juandent picture juandent  路  5Comments

algobot76 picture algobot76  路  7Comments

ahahahahalo picture ahahahahalo  路  11Comments

kungfu-origin picture kungfu-origin  路  10Comments

yetkinozturk picture yetkinozturk  路  11Comments