On Friday, July 20, 2018 at 3:17:54 PM UTC-7, Karl He wrote:
>
> So for Sequel 5 this syntax was deprecated:
>
> ```
> :a
> :a__b
> :a__b__c
> ```
>
> The problem I'm having is that we would pass around these qualified 
> identifier symbols and modify them. For example:
>
> ```
> foreign_key [column], :"#{table}_persistent", :on_delete => :cascade
> ``` 
>

> With the old syntax I could basically ignore whether it was qualified or 
> not and just add `_persistent`, with the new identifiers there doesn't 
> appear to be an easy way to handle this:
>
> ```
> [30] pry(main)> Sequel[:a]
> => #<Sequel::SQL::Identifier @value=>"a">
> [31] pry(main)> Sequel[:a][:b]
> => #<Sequel::SQL::QualifiedIdentifier @table=>"a", @column=>:b>
> [32] pry(main)> Sequel[:a][:b][:c]
> => #<Sequel::SQL::QualifiedIdentifier 
> @table=>#<Sequel::SQL::QualifiedIdentifier @table=>"a", @column=>:b>, 
> @column=>:c>
> ```
>
> The interface for Identifier and QualifiedIdentifier doesn't match, and 
> there doesn't seem to be a way to modify an existing identifier, so to 
> create a modified identifier I'd need to do something like this:
>
> ```
> old = Sequel[:a][:b]
> new = Sequel[old.table]["#{old.column}_persistent"]
> ```
>
> Which is complicated further if it's double qualified or not qualified.
>
> To be honest I'm not sure what the best solution here is, so I was 
> wondering if there was a better way to do this.
>

def add_persistent(obj)
  case obj
  when Sequel::SQL::Identifier
    obj.class.new(obj.value)
  when Sequel::SQL::QualifiedIdentifier
    obj.class.new(obj.table, add_persistent(obj.column))
  when String, Symbol
    "#{obj}_persistent"
  # any other types you want to support
  end
end

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to