Sha256: 2230c2d414d437d1b97624f9ae5da07aa3c322bca6e2001d98ea42c691d0c78f

Contents?: true

Size: 821 Bytes

Versions: 5

Compression:

Stored size: 821 Bytes

Contents

require "arel/visitors/postgresql"

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

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

      def visit_PluckMap_JsonArrayAggregate(o, collector)
        collector << "json_agg("
        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_agg(d.object) FROM (#{sql}) AS d), json_build_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/postgresql.rb
pluck_map-2.0.0.rc1 lib/pluck_map/visitors/postgresql.rb
pluck_map-1.0.0 lib/pluck_map/visitors/postgresql.rb
pluck_map-1.0.0.rc2 lib/pluck_map/visitors/postgresql.rb
pluck_map-1.0.0.rc1 lib/pluck_map/visitors/postgresql.rb