rename identifier into primaryKey; fix #514

This commit is contained in:
qdequele 2020-03-09 18:40:49 +01:00
parent 8ffa80883a
commit c984d8d5a5
No known key found for this signature in database
GPG key ID: B3F0A000EBF11745
24 changed files with 142 additions and 142 deletions

View file

@ -6,7 +6,7 @@ pub type SResult<T> = Result<T, Error>;
#[derive(Debug)]
pub enum Error {
FieldNameNotFound(String),
IdentifierAlreadyPresent,
PrimaryKeyAlreadyPresent,
MaxFieldsLimitExceeded,
}
@ -15,7 +15,7 @@ impl fmt::Display for Error {
use self::Error::*;
match self {
FieldNameNotFound(field) => write!(f, "The field {:?} doesn't exist", field),
IdentifierAlreadyPresent => write!(f, "The schema already have an identifier. It's impossible to update it"),
PrimaryKeyAlreadyPresent => write!(f, "The schema already have an primary key. It's impossible to update it"),
MaxFieldsLimitExceeded => write!(f, "The maximum of possible reattributed field id has been reached"),
}
}

View file

@ -6,7 +6,7 @@ use std::collections::{HashMap, HashSet};
pub struct Schema {
fields_map: FieldsMap,
identifier: Option<FieldId>,
primary_key: Option<FieldId>,
ranked: HashSet<FieldId>,
displayed: HashSet<FieldId>,
@ -20,7 +20,7 @@ impl Schema {
pub fn new() -> Schema {
Schema {
fields_map: FieldsMap::default(),
identifier: None,
primary_key: None,
ranked: HashSet::new(),
displayed: HashSet::new(),
indexed: Vec::new(),
@ -29,7 +29,7 @@ impl Schema {
}
}
pub fn with_identifier(name: &str) -> Schema {
pub fn with_primary_key(name: &str) -> Schema {
let mut fields_map = FieldsMap::default();
let field_id = fields_map.insert(name).unwrap();
@ -43,7 +43,7 @@ impl Schema {
Schema {
fields_map,
identifier: Some(field_id),
primary_key: Some(field_id),
ranked: HashSet::new(),
displayed,
indexed,
@ -52,17 +52,17 @@ impl Schema {
}
}
pub fn identifier(&self) -> Option<&str> {
self.identifier.map(|id| self.fields_map.name(id).unwrap())
pub fn primary_key(&self) -> Option<&str> {
self.primary_key.map(|id| self.fields_map.name(id).unwrap())
}
pub fn set_identifier(&mut self, name: &str) -> SResult<FieldId> {
if self.identifier.is_some() {
return Err(Error::IdentifierAlreadyPresent)
pub fn set_primary_key(&mut self, name: &str) -> SResult<FieldId> {
if self.primary_key.is_some() {
return Err(Error::PrimaryKeyAlreadyPresent)
}
let id = self.insert(name)?;
self.identifier = Some(id);
self.primary_key = Some(id);
self.set_indexed(name)?;
self.set_displayed(name)?;