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

stricter registration of fields in a table? #645

Closed
denzor200 opened this issue Jan 17, 2021 · 4 comments
Closed

stricter registration of fields in a table? #645

denzor200 opened this issue Jan 17, 2021 · 4 comments

Comments

@denzor200
Copy link
Contributor

denzor200 commented Jan 17, 2021

How about this?

#include <sqlite_orm/sqlite_orm.h>

using namespace sqlite_orm;

struct User {
  std::string username;
  std::string password;
  bool isActive;
};

struct User2 : User {};
struct User3 : User {};

int main() {
  auto storage = make_storage(
      "storage.sqlite", ///

      /// ALL RIGHT: all fields were registered
      make_table("users", ///
                 make_column("username", &User::username, primary_key()),
                 make_column("password", &User::password),
                 make_column("isActive", &User::isActive)),

      /// ALL RIGHT: 'isActive' field were ignored, other fields were registered
      make_table("users2", ///
                 make_column("username", &User2::username, primary_key()),
                 make_column("password", &User2::password),
                 ignored(&User2::isActive)),

      /// FAILED: 'isActive' field was skipped
      make_table("users3", ///
                 make_column("username", &User3::username, primary_key()),
                 make_column("password", &User3::password))

  );
  return 0;
}

compatibility with the previous version will be lost a little .. But I think it's worth it.

@fnc12
Copy link
Owner

fnc12 commented Jan 17, 2021

Thanks for submitting this.
Two questions:

  1. what profit we will get?
  2. how to implement this?

@denzor200
Copy link
Contributor Author

denzor200 commented Jan 17, 2021

  1. On a large number of tables, it is very easy to miss the "make_column" and suffer sitting in the debugger (
  2. It is not easy, but it is possible. Let's take a look at the "pfr" library, implemented in pure C++14, with no additional dependencies. I believe that we can repeat.
    https://github.com/boostorg/pfr

@fnc12
Copy link
Owner

fnc12 commented Jan 17, 2021

  1. It will be fixed in this Reverse engineering complex databases - automatically generate storage definition and data structures #450 . Probably you'll like it more
  2. prf looks like magic_get by Anton Polukhin from yandex company. This is a great library and Anton is a brilliant C++ coder but there is not need to add magic_get's functionality in sqlite_orm if we can solve it using codegen.

@denzor200
Copy link
Contributor Author

Ok. I have no answers

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

No branches or pull requests

2 participants