Sha256: af7f45ce283aadc37941d0e297d9b77e249caa701a84d6e37cd32e315e443c01

Contents?: true

Size: 823 Bytes

Versions: 5

Compression:

Stored size: 823 Bytes

Contents

require "arel/visitors/sqlite"

module Arel
  module Visitors
    class SQLite
      def visit_PluckMap_BuildJsonObject(o, collector)
        collector << "json_object("
        visit o.args, collector
        collector << ")"
      end

      def visit_PluckMap_BuildJsonArray(o, collector)
        collector << "json_array("
        visit o.args, collector
        collector << ")"
      end

      def visit_PluckMap_JsonArrayAggregate(o, collector)
        collector << "json_group_array(json("
        visit o.arg, collector
        collector << "))"
      end

      def visit_PluckMap_JsonSubqueryAggregate(o, collector)
        sql = o.scope.select(o.select.as("object")).to_sql
        collector << "COALESCE((SELECT json_group_array(json(d.object)) FROM (#{sql}) AS d), json_array())"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pluck_map-2.0.0 lib/pluck_map/visitors/sqlite.rb
pluck_map-2.0.0.rc1 lib/pluck_map/visitors/sqlite.rb
pluck_map-1.0.0 lib/pluck_map/visitors/sqlite.rb
pluck_map-1.0.0.rc2 lib/pluck_map/visitors/sqlite.rb
pluck_map-1.0.0.rc1 lib/pluck_map/visitors/sqlite.rb