SqliteModernCpp / sqlite_modern_cpp

The C++14 wrapper around sqlite library
MIT License
904 stars 156 forks source link

Added blob_t alternative #159

Closed roussosalex closed 6 years ago

roussosalex commented 6 years ago

A simple alternative to the std::vector approach. Makes it easier to supply a pointer and size for arbitrary binary blobs.

aminroosta commented 6 years ago

@roussosalex Thank you for the PR, lack of operator >> for raw pointers is a valid point.
In fact we had a discussion in #122 on the interface of next version (v4).

My proposal is to change the meaning of operator >> for vector<T>.

// single row blob
vector<int> vblob;
db << "select numbers from tbl where id = 1" >> blob_t(vblob);
// multiple row int
vector<int> vrows;
db << "select age from tbl;" >> vrows;

The std::vector is an example here, this could/should work for all standard containers. blob_t can be partially specialized for different types (blob_t<vector<T>>, blob_t<T*,size_t> or blob_t<span<T>>). Heres is POC for blob_t #125

roussosalex commented 6 years ago

@aminroosta Thanks for the quick response. Your proposal seems reasonable, especially because specializing blob_t is a much cleaner solution than overloading the operator>> for custom types.