ROM Attribute identity

Hi,

There is a way in ROM to deal with identities?

Sometimes I play with monads to create my queries and I finish with things like that :

filter1 : ROM::SQL::Attribute
filter2 : ROM::SQL::Attribute
maybe_filter3 : Maybe(ROM::SQL::Attribute)

filter1 & filter2 & maybe_filter3.value_or(identity) # I would love this

As I don’t know where of if there is an identity inside ROM, I do this instead :

filters = filter1 & filter2
maybe_filter3.fmap { |filter| filters & filter }.value_or(filters)

I don’t find it very easy to read. At least harder than with an identity.

How can I deal with monads for ROM Attributes?

Thnaks :smiley:

Could you provide a more complete code example? My initial reaction is ‘but WHY?’ :slightly_smiling_face:

I am building a metric search engine, for example, you want the revenue metric, you ask a query like this one :

{
  metric: 'revenue',
  addon: ['previous_period', 'benchmark_period', 'by_analysis']
}

With this input, I will transform it into an SQL query.
Each addon modify by little the query, but sometimes some part of the database should not be filtered, like the analysis.

The base query builder will have a method like this:

        def extract_analysis_level
          None()
        end

And an addon could have this

        def extract_analysis_level
          Some(dimensions[:value].not(nil))
        end