lib/flipper/adapters/sequel.rb in flipper-sequel-0.21.0 vs lib/flipper/adapters/sequel.rb in flipper-sequel-0.22.0
- old
+ new
@@ -95,14 +95,18 @@
end
result
end
def get_all
- db_gates = @gate_class.fetch(<<-SQL).to_a
- SELECT ff.key AS feature_key, fg.key, fg.value
- FROM #{@feature_class.table_name} ff
- LEFT JOIN #{@gate_class.table_name} fg ON ff.key = fg.feature_key
- SQL
+ feature_table = @feature_class.table_name.to_sym
+ gate_table = @gate_class.table_name.to_sym
+ features_sql = @feature_class.select(:key.qualify(feature_table).as(:feature_key))
+ .select_append(:key.qualify(gate_table))
+ .select_append(:value.qualify(gate_table))
+ .left_join(@gate_class.table_name.to_sym, feature_key: :key)
+ .sql
+
+ db_gates = @gate_class.fetch(features_sql).to_a
grouped_db_gates = db_gates.group_by(&:feature_key)
result = Hash.new { |hash, key| hash[key] = default_config }
features = grouped_db_gates.keys.map { |key| Flipper::Feature.new(key, self) }
features.each do |feature|
result[feature.key] = result_for_feature(feature, grouped_db_gates[feature.key])