mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 09:56:28 +00:00 
			
		
		
		
	Add PrimaryKey::new_or_insert
This commit is contained in:
		@@ -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,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user