Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating database with REAL array column #1057

Closed
crabiner opened this issue Jun 20, 2022 · 10 comments
Closed

creating database with REAL array column #1057

crabiner opened this issue Jun 20, 2022 · 10 comments
Labels

Comments

@crabiner
Copy link

I have a database created using
CREATE TABLE "TestRealArray" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "real_array" REAL[] NOT NULL )
I can view the database using "DB Browser for SQLite" and the type of the column is shown as REAL []
how can I create such a columnt using sqlite_orm?

@fnc12
Copy link
Owner

fnc12 commented Jun 20, 2022

not sure that you can but type is actually isn't important in SQLite. You can insert any type of data in real_array column actually: blob, null, int, double, text. Type is affinity not a rule in SQLite.

@fnc12 fnc12 added the question label Jun 20, 2022
@crabiner
Copy link
Author

Thanks for the answer!
How would I save an array of floats in sqlite_orm?

@fnc12
Copy link
Owner

fnc12 commented Jun 20, 2022

it depends on how you want to do it in raw SQLite. There is plenty of ways of doing it. How would you do it in raw SQLite?

@crabiner
Copy link
Author

I'm using pony ORM in python to create db containing for example a column called "rotation" holding a vector with the following data
[-2.244766578150064e-32,-4.1646004162569874e-33,-0.7071067811865474,0.7071067811865477]
I need to read this on sqlite_orm c++ and also be able to write a similar table using the sqlite_orm c++ that can be read by pony ORM python

@fnc12
Copy link
Owner

fnc12 commented Jun 20, 2022

you need to understand how pony ORM inserts rotation vector and implement the same way of extracting data. Good news: sqlite_orm allows you implementing any type of serialization/deserialization for custom type and you can inspect it in examples folder. E.g. https://github.com/fnc12/sqlite_orm/blob/master/examples/nullable_enum_binding.cpp, https://github.com/fnc12/sqlite_orm/blob/master/examples/enum_binding.cpp. If you have any questions please feel free to ask

@crabiner
Copy link
Author

Big like on the custom type feature
I'm taking that as home work to try to implement the string above to a new custom type of float array

Would you recommend the custom type struct to be

struct FloatArray{
    std::vector<float> farray;
};

?

@fnc12
Copy link
Owner

fnc12 commented Jun 22, 2022

why not. It is the easiest way of doing it. Your main goal here is to understand how data is serialized by pony ORM and make symmetric deserialization of FloatArray

@crabiner
Copy link
Author

Amazing!
I ended up supporting std::vector directly
by implementing the functions below

and I was even able to load a database created by sqlite_orm c++ into another orm called pony in python
I will open a new question I have in another issue about reading a pony orm database in sqlite_orm

    template<>
    struct type_printer<std::vector<float> > : public text_printer;

template<>
    struct statement_binder<std::vector<float> >

    template<>
    struct field_printer<std::vector<float> >;

    template<>
    struct row_extractor<std::vector<float> >

@fnc12
Copy link
Owner

fnc12 commented Jul 25, 2022

@crabiner ok good for you. Can we close this issue?

@crabiner
Copy link
Author

Yes thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants