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.



587
588
589
590
591
# File 'lib/supabase/postgrest/request_builder.rb', line 587

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

Instance Method Details

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



639
640
641
642
643
644
645
646
647
648
# File 'lib/supabase/postgrest/request_builder.rb', line 639

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



602
603
604
605
606
607
608
609
610
611
612
# File 'lib/supabase/postgrest/request_builder.rb', line 602

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



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

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



628
629
630
631
632
633
634
635
636
637
# File 'lib/supabase/postgrest/request_builder.rb', line 628

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



614
615
616
617
618
619
620
621
622
623
624
625
626
# File 'lib/supabase/postgrest/request_builder.rb', line 614

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