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

Record (macros for crud operations) #89

Open
norman784 opened this issue Jul 12, 2022 · 0 comments
Open

Record (macros for crud operations) #89

norman784 opened this issue Jul 12, 2022 · 0 comments

Comments

@norman784
Copy link
Collaborator

Add a configurable macro to perform crud operations. If a config file exists it will use to fill the missing information for each model, why? Because it is most likely that you use different structs to execute queries over the same table.

{
  "users": {
    "primary_key": "id",
    "relations": {
      "posts": {
        "post_id": "id",
      },
    },
    // Not sure if this is the right name, but this will work as a field required for each operation, no matter what, useful for multitenancy 
    "constraints": {
      "tenant_id"
    },
  }
}
#[derive(Record)]
// You can pass the actions selectable, insertable, updatable or deletable, the default value is all of them
#[record(table = "users")]
struct User {
  firstname: String,
  lastname: String,
}

let user = User { .. };
User::insert(&pool, user, tenant_id);
user.update(&pool, tenant_id);
user.delete(&pool, tenant_id);
User::by_id(&pool, 5, tenant_id);

Records are not intended to use for other complex queries, the idea is to use it as a helper to reduce boilerplate of common straightforward queries.

Some considerations, it is annoying to pass the tenant over and over again, so there can be a way to apply an extension to axum that contains the pool and current tenant, so inside the crud functions it will retrieve the tenant (if any) from the extension, this will reduce even further the boilerplate.

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

1 participant