-
Notifications
You must be signed in to change notification settings - Fork 12
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
Multiple secondary keys from a single record #143
Comments
Actually, no, it's not linked. You can have as many Here are some examples:
Each time it is a new key whether it is custom or not, you can have a mix of the two without any problem. And you can create as many as you want. Does this answer your questions? |
Thank you, yes that did answer my question. I still think it would be very useful to be able to return an arbitrary number of secondary keys for a record using a function or by implementing a trait for the struct? Just a hypothetical example here - let's say each struct in the database represented a country. A person could use an enum CountryKey {
City(String)
State(String)
}
struct CountryValue {
cities: Vec<String>,
states: Vec<String>,
}
let united_states = CountryValue {
cities: vec!["Houston", "San Antonio", "Galveston"], // etc.
states: vec!["Texas"], // etc.
} The custom [City("Houston"), City("San Antonio"), City("Galveston"), State("Texas")] And then when searching the database for |
It's an interesting idea, I see several things in your example:
|
According to the documentation regarding secondary keys a custom function can be defined in the macro that can be used to finagle a secondary key from the user's struct.
The following tells
native_db
to use the user-supplied functioncustom_name
to get the secondary key for the struct:I wonder, is
#[secondary_key]
necessary if#[native_db(secondary_key(custom_name, optional))]
is defined?The user-defined
custom_name
function returns anOption<String>
as the secondary key:Since, according to the documentation, users can define "define it or not, define one or more" I assume it should be possible to return multiple secondary keys for a single struct?
If so, I'd like to propose an additional
secondary_keys
definition that can return aVec<T>
rather than anOption<T>
. If the secondary key isn'toptional
, an emptyVec
would fail.I get the impression that
native_db
's internal structure should support this, it's just a matter of implementing the feature? Any thoughts?The text was updated successfully, but these errors were encountered: