Trait psl_core::datamodel_connector::Connector
source · pub trait Connector: Send + Sync {
Show 55 methods
// Required methods
fn provider_name(&self) -> &'static str;
fn flavour(&self) -> Flavour;
fn name(&self) -> &str;
fn capabilities(&self) -> ConnectorCapabilities;
fn max_identifier_length(&self) -> usize;
fn referential_actions(&self) -> BitFlags<ReferentialAction>;
fn available_native_type_constructors(
&self
) -> &'static [NativeTypeConstructor];
fn scalar_type_for_native_type(
&self,
native_type: &NativeTypeInstance
) -> ScalarType;
fn default_native_type_for_scalar_type(
&self,
scalar_type: &ScalarType
) -> Option<NativeTypeInstance>;
fn native_type_is_default_for_scalar_type(
&self,
native_type: &NativeTypeInstance,
scalar_type: &ScalarType
) -> bool;
fn native_type_to_parts(
&self,
native_type: &NativeTypeInstance
) -> (&'static str, Vec<String>);
fn parse_native_type(
&self,
name: &str,
args: &[String],
span: Span,
diagnostics: &mut Diagnostics
) -> Option<NativeTypeInstance>;
fn validate_url(&self, url: &str) -> Result<(), String>;
// Provided methods
fn is_provider(&self, name: &str) -> bool { ... }
fn has_capability(&self, capability: ConnectorCapability) -> bool { ... }
fn allowed_relation_mode_settings(&self) -> BitFlags<RelationMode> { ... }
fn default_relation_mode(&self) -> RelationMode { ... }
fn emulated_referential_actions(&self) -> BitFlags<ReferentialAction> { ... }
fn allows_set_null_referential_action_on_non_nullable_fields(
&self,
_relation_mode: RelationMode
) -> bool { ... }
fn supports_composite_types(&self) -> bool { ... }
fn supports_named_primary_keys(&self) -> bool { ... }
fn supports_named_foreign_keys(&self) -> bool { ... }
fn supports_named_default_values(&self) -> bool { ... }
fn supports_referential_action(
&self,
relation_mode: &RelationMode,
action: ReferentialAction
) -> bool { ... }
fn scalar_filter_name(
&self,
scalar_type_name: String,
_native_type_name: Option<&str>
) -> Cow<'_, str> { ... }
fn string_filters(&self, input_object_name: &str) -> BitFlags<StringFilter> { ... }
fn validate_native_type_arguments(
&self,
_native_type: &NativeTypeInstance,
_scalar_type: &ScalarType,
_span: Span,
_: &mut Diagnostics
) { ... }
fn validate_enum(&self, _enum: EnumWalker<'_>, _: &mut Diagnostics) { ... }
fn validate_model(
&self,
_model: ModelWalker<'_>,
_: RelationMode,
_: &mut Diagnostics
) { ... }
fn validate_relation_field(
&self,
_field: RelationFieldWalker<'_>,
_: &mut Diagnostics
) { ... }
fn validate_datasource(
&self,
_: BitFlags<PreviewFeature>,
_: &Datasource,
_: &mut Diagnostics
) { ... }
fn validate_scalar_field_unknown_default_functions(
&self,
db: &ParserDatabase,
diagnostics: &mut Diagnostics
) { ... }
fn constraint_violation_scopes(&self) -> &'static [ConstraintScope] { ... }
fn find_native_type_constructor(
&self,
name: &str
) -> Option<&NativeTypeConstructor> { ... }
fn supports_scalar_lists(&self) -> bool { ... }
fn supports_enums(&self) -> bool { ... }
fn supports_json(&self) -> bool { ... }
fn supports_json_lists(&self) -> bool { ... }
fn supports_auto_increment(&self) -> bool { ... }
fn supports_non_id_auto_increment(&self) -> bool { ... }
fn supports_multiple_auto_increment(&self) -> bool { ... }
fn supports_non_indexed_auto_increment(&self) -> bool { ... }
fn supports_compound_ids(&self) -> bool { ... }
fn supports_decimal(&self) -> bool { ... }
fn supported_index_types(&self) -> BitFlags<IndexAlgorithm> { ... }
fn supports_index_type(&self, algo: IndexAlgorithm) -> bool { ... }
fn allows_relation_fields_in_arbitrary_order(&self) -> bool { ... }
fn should_suggest_missing_referencing_fields_indexes(&self) -> bool { ... }
fn native_type_to_string(&self, instance: &NativeTypeInstance) -> String { ... }
fn native_instance_error(
&self,
instance: &NativeTypeInstance
) -> NativeTypeErrorFactory { ... }
fn datamodel_completions(
&self,
_db: &ParserDatabase,
_position: SchemaPosition<'_>,
_completions: &mut CompletionList
) { ... }
fn datasource_completions(
&self,
_config: &Configuration,
_completion_list: &mut CompletionList
) { ... }
fn parse_datasource_properties(
&self,
_args: &mut HashMap<&str, (Span, &Expression)>,
_diagnostics: &mut Diagnostics
) -> DatasourceConnectorData { ... }
fn parse_json_datetime(
&self,
_str: &str,
_nt: Option<NativeTypeInstance>
) -> ParseResult<DateTime<FixedOffset>> { ... }
fn parse_json_bytes(
&self,
_str: &str,
_nt: Option<NativeTypeInstance>
) -> PrismaValueResult<Vec<u8>> { ... }
}
Expand description
The datamodel connector API.
Required Methods§
sourcefn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
The name of the provider, for string comparisons determining which connector we are on.
sourcefn flavour(&self) -> Flavour
fn flavour(&self) -> Flavour
The database flavour, divergences in database backends capabilities might consider us to use a different flavour, like in the case of CockroachDB. However other databases are less divergent as to consider sharing a flavour with others, like Planetscale and MySQL or Neon and Postgres, which respectively have the Mysql and Postgres flavours.
sourcefn capabilities(&self) -> ConnectorCapabilities
fn capabilities(&self) -> ConnectorCapabilities
The static list of capabilities for the connector.
sourcefn max_identifier_length(&self) -> usize
fn max_identifier_length(&self) -> usize
The maximum length of constraint names in bytes. Connectors without a limit should return usize::MAX.
sourcefn referential_actions(&self) -> BitFlags<ReferentialAction>
fn referential_actions(&self) -> BitFlags<ReferentialAction>
The referential actions supported by the connector.
sourcefn available_native_type_constructors(&self) -> &'static [NativeTypeConstructor]
fn available_native_type_constructors(&self) -> &'static [NativeTypeConstructor]
Returns all available native type constructors available through this connector. Powers the auto completion of the VSCode plugin.
sourcefn scalar_type_for_native_type(
&self,
native_type: &NativeTypeInstance
) -> ScalarType
fn scalar_type_for_native_type( &self, native_type: &NativeTypeInstance ) -> ScalarType
Returns the default scalar type for the given native type
sourcefn default_native_type_for_scalar_type(
&self,
scalar_type: &ScalarType
) -> Option<NativeTypeInstance>
fn default_native_type_for_scalar_type( &self, scalar_type: &ScalarType ) -> Option<NativeTypeInstance>
On each connector, each built-in Prisma scalar type (Boolean
,
String
, Float
, etc.) has a corresponding native type.
sourcefn native_type_is_default_for_scalar_type(
&self,
native_type: &NativeTypeInstance,
scalar_type: &ScalarType
) -> bool
fn native_type_is_default_for_scalar_type( &self, native_type: &NativeTypeInstance, scalar_type: &ScalarType ) -> bool
Same mapping as default_native_type_for_scalar_type()
, but in the opposite direction.
sourcefn native_type_to_parts(
&self,
native_type: &NativeTypeInstance
) -> (&'static str, Vec<String>)
fn native_type_to_parts( &self, native_type: &NativeTypeInstance ) -> (&'static str, Vec<String>)
Debug/error representation of a native type.
sourcefn parse_native_type(
&self,
name: &str,
args: &[String],
span: Span,
diagnostics: &mut Diagnostics
) -> Option<NativeTypeInstance>
fn parse_native_type( &self, name: &str, args: &[String], span: Span, diagnostics: &mut Diagnostics ) -> Option<NativeTypeInstance>
This function is used during Schema parsing to calculate the concrete native type.
fn validate_url(&self, url: &str) -> Result<(), String>
Provided Methods§
sourcefn is_provider(&self, name: &str) -> bool
fn is_provider(&self, name: &str) -> bool
Must return true whenever the passed in provider name is a match.
sourcefn has_capability(&self, capability: ConnectorCapability) -> bool
fn has_capability(&self, capability: ConnectorCapability) -> bool
Does the connector have this capability?
sourcefn allowed_relation_mode_settings(&self) -> BitFlags<RelationMode>
fn allowed_relation_mode_settings(&self) -> BitFlags<RelationMode>
The relation modes that can be set through the relationMode datasource argument.
sourcefn default_relation_mode(&self) -> RelationMode
fn default_relation_mode(&self) -> RelationMode
The default relation mode to assume for this connector.
sourcefn emulated_referential_actions(&self) -> BitFlags<ReferentialAction>
fn emulated_referential_actions(&self) -> BitFlags<ReferentialAction>
The referential actions supported when using relationMode = “prisma” by the connector. There are in fact scenarios in which the set of emulated referential actions supported may change depending on the connector. For example, Postgres’ NoAction mode behaves similarly to Restrict (raising an error if any referencing rows still exist when the constraint is checked), but with a subtle twist we decided not to emulate: NO ACTION allows the check to be deferred until later in the transaction, whereas RESTRICT does not.
sourcefn allows_set_null_referential_action_on_non_nullable_fields(
&self,
_relation_mode: RelationMode
) -> bool
fn allows_set_null_referential_action_on_non_nullable_fields( &self, _relation_mode: RelationMode ) -> bool
Most SQL databases reject table definitions with a SET NULL referential action referencing a non-nullable field, but that’s not true for all of them. This was introduced because Postgres accepts data definition language statements with the SET NULL referential action referencing non-nullable fields, although this would lead to a runtime error once the action is actually triggered.
fn supports_composite_types(&self) -> bool
fn supports_named_primary_keys(&self) -> bool
fn supports_named_foreign_keys(&self) -> bool
fn supports_named_default_values(&self) -> bool
fn supports_referential_action( &self, relation_mode: &RelationMode, action: ReferentialAction ) -> bool
sourcefn scalar_filter_name(
&self,
scalar_type_name: String,
_native_type_name: Option<&str>
) -> Cow<'_, str>
fn scalar_filter_name( &self, scalar_type_name: String, _native_type_name: Option<&str> ) -> Cow<'_, str>
This is used by the query engine schema builder.
For a given scalar type + native type combination, this method should return the name to be given to the filter input objects for the type. The significance of that name is that the resulting input objects will be cached by name, so for a given filter input object name, the filters should always be identical.
sourcefn string_filters(&self, input_object_name: &str) -> BitFlags<StringFilter>
fn string_filters(&self, input_object_name: &str) -> BitFlags<StringFilter>
This is used by the query engine schema builder. It is only called for filters of String fields and aggregates.
For a given filter input object type name returned by scalar_filter_name
, it should
return the string operations to be made available in the Client API.
Implementations of this method must always associate the same filters to the same input object type name. This is because the filter types are cached by name, so if different calls to the method return different filters, only the first return value will be used.
sourcefn validate_native_type_arguments(
&self,
_native_type: &NativeTypeInstance,
_scalar_type: &ScalarType,
_span: Span,
_: &mut Diagnostics
)
fn validate_native_type_arguments( &self, _native_type: &NativeTypeInstance, _scalar_type: &ScalarType, _span: Span, _: &mut Diagnostics )
Validate that the arguments passed to a native type attribute are valid.
fn validate_enum(&self, _enum: EnumWalker<'_>, _: &mut Diagnostics)
fn validate_model( &self, _model: ModelWalker<'_>, _: RelationMode, _: &mut Diagnostics )
fn validate_relation_field( &self, _field: RelationFieldWalker<'_>, _: &mut Diagnostics )
fn validate_datasource( &self, _: BitFlags<PreviewFeature>, _: &Datasource, _: &mut Diagnostics )
fn validate_scalar_field_unknown_default_functions( &self, db: &ParserDatabase, diagnostics: &mut Diagnostics )
sourcefn constraint_violation_scopes(&self) -> &'static [ConstraintScope]
fn constraint_violation_scopes(&self) -> &'static [ConstraintScope]
The scopes in which a constraint name should be validated. If empty, doesn’t check for name clashes in the validation phase.
fn find_native_type_constructor( &self, name: &str ) -> Option<&NativeTypeConstructor>
fn supports_scalar_lists(&self) -> bool
fn supports_enums(&self) -> bool
fn supports_json(&self) -> bool
fn supports_json_lists(&self) -> bool
fn supports_auto_increment(&self) -> bool
fn supports_non_id_auto_increment(&self) -> bool
fn supports_multiple_auto_increment(&self) -> bool
fn supports_non_indexed_auto_increment(&self) -> bool
fn supports_compound_ids(&self) -> bool
fn supports_decimal(&self) -> bool
fn supported_index_types(&self) -> BitFlags<IndexAlgorithm>
fn supports_index_type(&self, algo: IndexAlgorithm) -> bool
fn allows_relation_fields_in_arbitrary_order(&self) -> bool
sourcefn should_suggest_missing_referencing_fields_indexes(&self) -> bool
fn should_suggest_missing_referencing_fields_indexes(&self) -> bool
If true, the schema validator function checks whether the referencing fields in a @relation
attribute
are included in an index.