pub trait LanguageBackend {
Show 19 methods
// Required methods
fn scalar_to_type(&self, scalar: &ScalarType) -> &'static str;
fn array_type(&self, inner: &str) -> String;
fn not_in_suffix(&self) -> &'static str;
fn startswith_suffix(&self) -> &'static str;
fn endswith_suffix(&self) -> &'static str;
fn null_suffix(&self) -> &'static str;
fn null_literal(&self) -> &'static str;
fn true_literal(&self) -> &'static str;
fn false_literal(&self) -> &'static str;
fn string_literal(&self, s: &str) -> String;
fn empty_array_literal(&self) -> &'static str;
// Provided methods
fn is_auto_generated(&self, field: &FieldIr) -> bool { ... }
fn numeric_operators(&self, type_name: &str) -> Vec<FilterOperator> { ... }
fn get_filter_operators_for_scalar(
&self,
scalar: &ScalarType,
) -> Vec<FilterOperator> { ... }
fn get_filter_operators_for_field(
&self,
field: &FieldIr,
enums: &HashMap<String, EnumIr>,
) -> Vec<FilterOperator> { ... }
fn enum_variant_literal(&self, variant: &str) -> String { ... }
fn relation_type(&self, target_model: &str) -> String { ... }
fn get_base_type(
&self,
field: &FieldIr,
enums: &HashMap<String, EnumIr>,
) -> String { ... }
fn get_default_value(&self, field: &FieldIr) -> Option<String> { ... }
}Expand description
Common interface for language-specific code generation backends.
§Abstract methods
Backends must implement the four type-mapping primitives and the four operator-naming conventions.
§Default methods
Everything else — is_auto_generated, the numeric-operator helper, and the
full filter-operator builders — is provided as a default implementation that
composes the abstract methods. Backends only override these defaults when
their language genuinely diverges from the shared logic.
Required Methods§
Sourcefn scalar_to_type(&self, scalar: &ScalarType) -> &'static str
fn scalar_to_type(&self, scalar: &ScalarType) -> &'static str
Maps a Nautilus scalar type to the target language’s type name.
Sourcefn array_type(&self, inner: &str) -> String
fn array_type(&self, inner: &str) -> String
Wraps a type name in the language’s array/list syntax.
Examples: "List[T]" (Python) vs "T[]" (TypeScript).
Sourcefn not_in_suffix(&self) -> &'static str
fn not_in_suffix(&self) -> &'static str
Suffix for the “not in collection” operator.
Python: "not_in" — TypeScript: "notIn"
Sourcefn startswith_suffix(&self) -> &'static str
fn startswith_suffix(&self) -> &'static str
Suffix for the “starts with” string operator.
Python: "startswith" — TypeScript: "startsWith"
Sourcefn endswith_suffix(&self) -> &'static str
fn endswith_suffix(&self) -> &'static str
Suffix for the “ends with” string operator.
Python: "endswith" — TypeScript: "endsWith"
Sourcefn null_suffix(&self) -> &'static str
fn null_suffix(&self) -> &'static str
Suffix for the null-check operator.
Python: "is_null" — TypeScript: "isNull"
Sourcefn null_literal(&self) -> &'static str
fn null_literal(&self) -> &'static str
The null literal in this language (Python: "None", TS: "null").
Sourcefn true_literal(&self) -> &'static str
fn true_literal(&self) -> &'static str
The boolean true literal (Python: "True", TS: "true").
Sourcefn false_literal(&self) -> &'static str
fn false_literal(&self) -> &'static str
The boolean false literal (Python: "False", TS: "false").
Sourcefn string_literal(&self, s: &str) -> String
fn string_literal(&self, s: &str) -> String
Format a string literal (Python: "\"hello\"", TS: "'hello'").
Sourcefn empty_array_literal(&self) -> &'static str
fn empty_array_literal(&self) -> &'static str
The empty-array factory expression (Python: "Field(default_factory=list)", TS: "[]").
Provided Methods§
Sourcefn is_auto_generated(&self, field: &FieldIr) -> bool
fn is_auto_generated(&self, field: &FieldIr) -> bool
Returns true for fields whose values are supplied automatically by the
database: autoincrement(), uuid(), or now().
This implementation is identical for Python and TypeScript. The Rust
backend intentionally differs (it exposes now() fields as writable),
which is why it lives in type_helpers.rs and does not use this trait.
Sourcefn numeric_operators(&self, type_name: &str) -> Vec<FilterOperator>
fn numeric_operators(&self, type_name: &str) -> Vec<FilterOperator>
Returns the standard comparison operators (lt, lte, gt, gte,
in, not_in/notIn) for a numeric-like type.
Sourcefn get_filter_operators_for_scalar(
&self,
scalar: &ScalarType,
) -> Vec<FilterOperator>
fn get_filter_operators_for_scalar( &self, scalar: &ScalarType, ) -> Vec<FilterOperator>
Returns the filter operators available for a given scalar type.
Sourcefn get_filter_operators_for_field(
&self,
field: &FieldIr,
enums: &HashMap<String, EnumIr>,
) -> Vec<FilterOperator>
fn get_filter_operators_for_field( &self, field: &FieldIr, enums: &HashMap<String, EnumIr>, ) -> Vec<FilterOperator>
Returns filter operators for a field, considering its resolved type (scalar, enum, or relation).
Sourcefn enum_variant_literal(&self, variant: &str) -> String
fn enum_variant_literal(&self, variant: &str) -> String
Format an enum variant as a default value (Python: unquoted, TS: single-quoted).
Sourcefn relation_type(&self, target_model: &str) -> String
fn relation_type(&self, target_model: &str) -> String
Resolves the base type name for a relation field.
Python uses the model name directly; TypeScript appends Model.
Sourcefn get_base_type(
&self,
field: &FieldIr,
enums: &HashMap<String, EnumIr>,
) -> String
fn get_base_type( &self, field: &FieldIr, enums: &HashMap<String, EnumIr>, ) -> String
Returns the bare base type for a field without array or optional wrappers.
Sourcefn get_default_value(&self, field: &FieldIr) -> Option<String>
fn get_default_value(&self, field: &FieldIr) -> Option<String>
Returns the default value expression for a field, or None if no default.