Class: Supabase::Postgrest::RequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/supabase/postgrest/request_builder.rb

Overview

Entry point for table operations — produced by Client#from(table). Each method builds an appropriate sub-builder (Select / Filter / Query) and returns it for chaining.

Instance Method Summary collapse

Constructor Details

#initialize(session, path, headers) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



593
594
595
596
597
# File 'lib/supabase/postgrest/request_builder.rb', line 593

def initialize(session, path, headers)
  @session = session
  @path = path
  @headers = headers
end

Instance Method Details

#delete(count: nil, returning: Types::ReturnMethod::REPRESENTATION) ⇒ Object



645
646
647
648
649
650
651
652
653
654
# File 'lib/supabase/postgrest/request_builder.rb', line 645

def delete(count: nil, returning: Types::ReturnMethod::REPRESENTATION)
  method, params, headers, body = RequestPrep.pre_delete(
    count: count, returning: returning
  )
  request = RequestConfig.new(
    session: @session, path: @path, http_method: method,
    headers: headers.merge(@headers), params: params, json: body
  )
  FilterRequestBuilder.new(request)
end

#insert(json, count: nil, returning: Types::ReturnMethod::REPRESENTATION, upsert: false, default_to_null: true) ⇒ Object



608
609
610
611
612
613
614
615
616
617
618
# File 'lib/supabase/postgrest/request_builder.rb', line 608

def insert(json, count: nil, returning: Types::ReturnMethod::REPRESENTATION,
           upsert: false, default_to_null: true)
  method, params, headers, body = RequestPrep.pre_insert(
    json, count: count, returning: returning, upsert: upsert, default_to_null: default_to_null
  )
  request = RequestConfig.new(
    session: @session, path: @path, http_method: method,
    headers: headers.merge(@headers), params: params, json: body
  )
  QueryRequestBuilder.new(request)
end

#select(*columns, count: nil, head: nil) ⇒ Object



599
600
601
602
603
604
605
606
# File 'lib/supabase/postgrest/request_builder.rb', line 599

def select(*columns, count: nil, head: nil)
  method, params, headers, json = RequestPrep.pre_select(*columns, count: count, head: head)
  request = RequestConfig.new(
    session: @session, path: @path, http_method: method,
    headers: headers.merge(@headers), params: params, json: json
  )
  SelectRequestBuilder.new(request)
end

#update(json, count: nil, returning: Types::ReturnMethod::REPRESENTATION) ⇒ Object



634
635
636
637
638
639
640
641
642
643
# File 'lib/supabase/postgrest/request_builder.rb', line 634

def update(json, count: nil, returning: Types::ReturnMethod::REPRESENTATION)
  method, params, headers, body = RequestPrep.pre_update(
    json, count: count, returning: returning
  )
  request = RequestConfig.new(
    session: @session, path: @path, http_method: method,
    headers: headers.merge(@headers), params: params, json: body
  )
  FilterRequestBuilder.new(request)
end

#upsert(json, count: nil, returning: Types::ReturnMethod::REPRESENTATION, ignore_duplicates: false, on_conflict: "", default_to_null: true) ⇒ Object



620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/supabase/postgrest/request_builder.rb', line 620

def upsert(json, count: nil, returning: Types::ReturnMethod::REPRESENTATION,
           ignore_duplicates: false, on_conflict: "", default_to_null: true)
  method, params, headers, body = RequestPrep.pre_upsert(
    json, count: count, returning: returning,
    ignore_duplicates: ignore_duplicates, on_conflict: on_conflict,
    default_to_null: default_to_null
  )
  request = RequestConfig.new(
    session: @session, path: @path, http_method: method,
    headers: headers.merge(@headers), params: params, json: body
  )
  QueryRequestBuilder.new(request)
end