Skip to main content

LanguageBackend

Trait LanguageBackend 

Source
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§

Source

fn scalar_to_type(&self, scalar: &ScalarType) -> &'static str

Maps a Nautilus scalar type to the target language’s type name.

Source

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).

Source

fn not_in_suffix(&self) -> &'static str

Suffix for the “not in collection” operator.

Python: "not_in" — TypeScript: "notIn"

Source

fn startswith_suffix(&self) -> &'static str

Suffix for the “starts with” string operator.

Python: "startswith" — TypeScript: "startsWith"

Source

fn endswith_suffix(&self) -> &'static str

Suffix for the “ends with” string operator.

Python: "endswith" — TypeScript: "endsWith"

Source

fn null_suffix(&self) -> &'static str

Suffix for the null-check operator.

Python: "is_null" — TypeScript: "isNull"

Source

fn null_literal(&self) -> &'static str

The null literal in this language (Python: "None", TS: "null").

Source

fn true_literal(&self) -> &'static str

The boolean true literal (Python: "True", TS: "true").

Source

fn false_literal(&self) -> &'static str

The boolean false literal (Python: "False", TS: "false").

Source

fn string_literal(&self, s: &str) -> String

Format a string literal (Python: "\"hello\"", TS: "'hello'").

Source

fn empty_array_literal(&self) -> &'static str

The empty-array factory expression (Python: "Field(default_factory=list)", TS: "[]").

Provided Methods§

Source

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.

Source

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.

Source

fn get_filter_operators_for_scalar( &self, scalar: &ScalarType, ) -> Vec<FilterOperator>

Returns the filter operators available for a given scalar type.

Source

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).

Source

fn enum_variant_literal(&self, variant: &str) -> String

Format an enum variant as a default value (Python: unquoted, TS: single-quoted).

Source

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.

Source

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.

Source

fn get_default_value(&self, field: &FieldIr) -> Option<String>

Returns the default value expression for a field, or None if no default.

Implementors§