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

Why select and selectAll wants non-empty seq? #176

Open
inv2004 opened this issue Oct 14, 2022 · 2 comments
Open

Why select and selectAll wants non-empty seq? #176

inv2004 opened this issue Oct 14, 2022 · 2 comments

Comments

@inv2004
Copy link

inv2004 commented Oct 14, 2022

Hello, was trying to use norm for the first time, was reading documentation and it was very unclear for me:

Why the select requires one element in seq? I suppose model (table and etc) goes from type, why the element is needed here?

var customersFoo = @[newCustomer()]
dbConn.select(customersFoo, "User.email = ?", "foo@foo.foo")

echo()
@moigagoo
Copy link
Owner

This is because in general, there is no universal way to instantiate a type in Nim. That means, you have just the type, you can't in general create its instance.

Therefore Norm requires an container instance to put the data into. At least one instance is required, it can be copied to fit multiple rows.

@moigagoo
Copy link
Owner

We've discussed this topic outside of GitHub. It seems that with the introduction of default field values for objects, we can finally reliably use types instead of instances. Also, DateTime type now has a default value.

This means new flavors of the existing procs can already be added, the flavors that take type instead of instance and create a necessary instance on the fly and then call the regular flavor.

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