Class: Postgrest::Client

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

Constant Summary collapse

DEFAULT_SCHEMA =
'public'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, headers: {}, schema: DEFAULT_SCHEMA) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/postgrest/client.rb', line 9

def initialize(url:, headers: {}, schema: DEFAULT_SCHEMA)
  @url = URI(url)
  @headers = headers
  @schema = schema
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/postgrest/client.rb', line 7

def headers
  @headers
end

#schemaObject (readonly)

Returns the value of attribute schema.



7
8
9
# File 'lib/postgrest/client.rb', line 7

def schema
  @schema
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/postgrest/client.rb', line 7

def url
  @url
end

Instance Method Details

#from(table) ⇒ Object

Raises:



15
16
17
18
19
# File 'lib/postgrest/client.rb', line 15

def from(table)
  raise MissingTableError if table.nil? || table.empty?

  Builders::QueryBuilder.new(url: "#{url}/#{table}", headers: headers, schema: schema)
end