pub struct FieldDefinition {
pub name: String,
pub field_type: FieldType,
pub assertion: Option<String>,
pub default: Option<String>,
pub value: Option<String>,
pub permissions: Option<BTreeMap<String, String>>,
pub readonly: bool,
pub flexible: bool,
}Expand description
Immutable field definition for table schemas.
Represents a single field in a SurrealDB table schema along with its constraints, defaults, and permissions.
§Examples
use surql::schema::{FieldDefinition, FieldType};
let email = FieldDefinition::new("email", FieldType::String);
assert_eq!(email.to_surql("user"), "DEFINE FIELD email ON TABLE user TYPE string;");Fields§
§name: StringField name (supports dot notation for nested fields).
field_type: FieldTypeField type.
assertion: Option<String>Optional SurrealQL assertion expression.
default: Option<String>Optional default value expression.
value: Option<String>Optional computed-value expression.
permissions: Option<BTreeMap<String, String>>Optional per-action permission rules keyed by action name.
readonly: boolWhether the field is read-only after creation.
flexible: boolWhether the field allows flexible schema.
Implementations§
Source§impl FieldDefinition
impl FieldDefinition
Sourcepub fn new(name: impl Into<String>, field_type: FieldType) -> Self
pub fn new(name: impl Into<String>, field_type: FieldType) -> Self
Construct a new FieldDefinition with only the required members.
Other members default to empty/false and can be set via chainable
with_* setters.
Sourcepub fn with_assertion(self, assertion: impl Into<String>) -> Self
pub fn with_assertion(self, assertion: impl Into<String>) -> Self
Set the assertion expression.
Sourcepub fn with_default(self, default: impl Into<String>) -> Self
pub fn with_default(self, default: impl Into<String>) -> Self
Set the default value expression.
Sourcepub fn with_value(self, value: impl Into<String>) -> Self
pub fn with_value(self, value: impl Into<String>) -> Self
Set the computed-value expression.
Sourcepub fn with_permissions<I, K, V>(self, permissions: I) -> Self
pub fn with_permissions<I, K, V>(self, permissions: I) -> Self
Attach per-action permissions.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the field definition against SurrealDB identifier rules.
Returns SurqlError::Validation for an empty name, empty segments,
or segments that contain invalid characters.
Sourcepub fn to_surql(&self, table: &str) -> String
pub fn to_surql(&self, table: &str) -> String
Render the DEFINE FIELD statement for this field on the given table.
§Examples
use surql::schema::{FieldDefinition, FieldType};
let f = FieldDefinition::new("email", FieldType::String)
.with_assertion("string::is::email($value)");
assert_eq!(
f.to_surql("user"),
"DEFINE FIELD email ON TABLE user TYPE string ASSERT string::is::email($value);",
);Sourcepub fn to_surql_with_options(&self, table: &str, if_not_exists: bool) -> String
pub fn to_surql_with_options(&self, table: &str, if_not_exists: bool) -> String
Render with optional IF NOT EXISTS clause.
Trait Implementations§
Source§impl Clone for FieldDefinition
impl Clone for FieldDefinition
Source§fn clone(&self) -> FieldDefinition
fn clone(&self) -> FieldDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FieldDefinition
impl Debug for FieldDefinition
Source§impl<'de> Deserialize<'de> for FieldDefinition
impl<'de> Deserialize<'de> for FieldDefinition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for FieldDefinition
impl PartialEq for FieldDefinition
Source§impl Serialize for FieldDefinition
impl Serialize for FieldDefinition
impl Eq for FieldDefinition
impl StructuralPartialEq for FieldDefinition
Auto Trait Implementations§
impl Freeze for FieldDefinition
impl RefUnwindSafe for FieldDefinition
impl Send for FieldDefinition
impl Sync for FieldDefinition
impl Unpin for FieldDefinition
impl UnsafeUnpin for FieldDefinition
impl UnwindSafe for FieldDefinition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request