mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +08:00
Add PrimaryKey::new_or_insert
This commit is contained in:
parent
152683083b
commit
017757004e
@ -65,6 +65,18 @@ impl<'a> PrimaryKey<'a> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_or_insert(
|
||||||
|
path: &'a str,
|
||||||
|
fields: &mut impl MutFieldIdMapper,
|
||||||
|
) -> StdResult<Self, UserError> {
|
||||||
|
Ok(if path.contains(PRIMARY_KEY_SPLIT_SYMBOL) {
|
||||||
|
Self::Nested { name: path }
|
||||||
|
} else {
|
||||||
|
let field_id = fields.insert(path).ok_or(UserError::AttributeLimitReached)?;
|
||||||
|
Self::Flat { name: path, field_id }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &'a str {
|
pub fn name(&self) -> &'a str {
|
||||||
match self {
|
match self {
|
||||||
PrimaryKey::Flat { name, .. } => name,
|
PrimaryKey::Flat { name, .. } => name,
|
||||||
|
Loading…
Reference in New Issue
Block a user