Sha256: 2504f1b6309cf51a8d476b5ea1a3e52ea1c4ff8c351953d91cb335b85352be70

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

module Tinybird
  module Query
    class Get
      include Tinybird::Callable
      include Tinybird::Requestable

      requestable method: :get

      ALLOWED_FORMATS = %w[CSV CSVWithoutHeader CSVWithNames JSON TSV TSVWithoutHeader TSVWithNames PrettyCompact JSONEachRow Parquet].freeze

      attr_reader :sql, :format, :headers

      def initialize(sql: "", format: "JSON", headers: {})
        @sql = sql
        @format = format
        @headers = headers
        validate_format!
      end

      private

      def path_segment
        "v0/sql?q=#{formatted_sql}"
      end

      def body
        nil
      end

      def formatted_sql
        "#{sql} FORMAT #{format}"
      end

      def validate_format!
        raise InvalidFormatError, "Invalid format: #{format}. Supported formats are: #{ALLOWED_FORMATS.join(", ")}" unless ALLOWED_FORMATS.include?(format)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tinybird-0.1.1 lib/tinybird/query/get.rb