You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it's not possible to configure a custom StructCompiler because MapperCompiler uses a hard-coded constant. This can be easily changed to use an option with the default value set to StructCompiler.
Examples
This could be configurable on a per-relation basis, with the ability to pre-configure it for all relations from a specific gateway instance.
Setting for all relations in a given gateway
# set it for all relations, this can be handled in `finalize_relations` because we have# access to gateway instance thereconfig=ROM::Configuration.new(:sql,'sqlite::memory',struct_compiler: MyStructCompiler)rom=ROM.container(config)
Setting per relation
classUsers < ROM::Relation[:sql]# the same method should be used in `finalize_relation` when we set it# via gateway configstruct_compilerMyStructCompilerschema(:users,infer: true)end
TODO
Tweak MapperCompiler so that it defines option :struct_compiler, reader: false, default: -> { StructCompiler } and use it in the initialize method options[:struct_compiler].new
Tweak FinalizeRelations so that #build_relation uses gateway.options[:struct_compiler] to configure Relation.struct_compiler
Tweak Relation.mapper_registry so that it passes configured struct_compiler to the MapperCompiler constructor
For the record, dry-struct 1.0 has support for "direct loading" i.e. without type checks. It's done internally via allocate + send(:initialize, attributes). It's ok to instantiate structs this way when the storage has internal type checks (e.g. in case of a SQL database). We probably want to use it for loading ROM::Structs because it's faster. Since it doesn't work for all cases, it should be an adapter-specific setting with possible manual override. We should also consider case where base class has constructor types in its definition (no idea if we should detect it automatically).
Currently, it's not possible to configure a custom
StructCompiler
becauseMapperCompiler
uses a hard-coded constant. This can be easily changed to use an option with the default value set toStructCompiler
.Examples
This could be configurable on a per-relation basis, with the ability to pre-configure it for all relations from a specific gateway instance.
Setting for all relations in a given gateway
Setting per relation
TODO
MapperCompiler
so that it definesoption :struct_compiler, reader: false, default: -> { StructCompiler }
and use it in theinitialize
methodoptions[:struct_compiler].new
FinalizeRelations
so that#build_relation
usesgateway.options[:struct_compiler]
to configureRelation.struct_compiler
Relation.mapper_registry
so that it passes configuredstruct_compiler
to theMapperCompiler
constructorResources
Refs #519
The text was updated successfully, but these errors were encountered: