Class: Postgrest::Builders::QueryBuilder
- Inherits:
-
Object
- Object
- Postgrest::Builders::QueryBuilder
- Defined in:
- lib/postgrest/builders/query_builder.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #delete(extra_headers: {}) ⇒ Object
-
#initialize(url:, headers:, schema:) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #insert(values) ⇒ Object
- #select(*columns, extra_headers: {}) ⇒ Object
- #update(values, extra_headers: {}) ⇒ Object
- #upsert(values, extra_headers: {}) ⇒ Object
Constructor Details
#initialize(url:, headers:, schema:) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
8 9 10 11 12 |
# File 'lib/postgrest/builders/query_builder.rb', line 8 def initialize(url:, headers:, schema:) @uri = URI(url) @headers = headers @schema = schema end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/postgrest/builders/query_builder.rb', line 6 def headers @headers end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/postgrest/builders/query_builder.rb', line 6 def schema @schema end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/postgrest/builders/query_builder.rb', line 6 def uri @uri end |
Instance Method Details
#delete(extra_headers: {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/postgrest/builders/query_builder.rb', line 40 def delete(extra_headers: {}) extra_headers[:Prefer] ||= 'return=representation' request = HTTP.new(uri: uri, http_method: :delete, headers: headers.merge(extra_headers)) FilterBuilder.new(request) end |
#insert(values) ⇒ Object
22 23 24 |
# File 'lib/postgrest/builders/query_builder.rb', line 22 def insert(values) upsert(values, extra_headers: { Prefer: 'return=representation' }) end |
#select(*columns, extra_headers: {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/postgrest/builders/query_builder.rb', line 14 def select(*columns, extra_headers: {}) columns.compact! columns = ['*'] if columns.length.zero? request = HTTP.new(uri: uri, query: { select: columns.join(',') }, headers: headers.merge(extra_headers)) FilterBuilder.new(request) end |
#update(values, extra_headers: {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/postgrest/builders/query_builder.rb', line 33 def update(values, extra_headers: {}) extra_headers[:Prefer] ||= 'return=representation' request = HTTP.new(uri: uri, body: values, http_method: :patch, headers: headers.merge(extra_headers)) FilterBuilder.new(request) end |
#upsert(values, extra_headers: {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/postgrest/builders/query_builder.rb', line 26 def upsert(values, extra_headers: {}) extra_headers[:Prefer] ||= 'return=representation,resolution=merge-duplicates' request = HTTP.new(uri: uri, body: values, http_method: :post, headers: headers.merge(extra_headers)) BaseBuilder.new(request) end |