Class: ForestAdminDatasourceSnowflake::Collection
- Inherits:
-
ForestAdminDatasourceToolkit::Collection
- Object
- ForestAdminDatasourceToolkit::Collection
- ForestAdminDatasourceSnowflake::Collection
- Defined in:
- lib/forest_admin_datasource_snowflake/collection.rb
Constant Summary collapse
- READ_ONLY_MESSAGE =
'forest_admin_datasource_snowflake is read-only.'.freeze
- ReadOnlyError =
ForestAdminDatasourceToolkit::Exceptions::ForestException
Instance Attribute Summary collapse
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #aggregate(_caller, filter, aggregation, limit = nil) ⇒ Object
- #create(_caller, _data) ⇒ Object
- #delete(_caller, _filter) ⇒ Object
-
#initialize(datasource, table_name) ⇒ Collection
constructor
A new instance of Collection.
- #list(_caller, filter, projection) ⇒ Object
- #update(_caller, _filter, _data) ⇒ Object
Constructor Details
#initialize(datasource, table_name) ⇒ Collection
Returns a new instance of Collection.
12 13 14 15 16 17 18 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 12 def initialize(datasource, table_name) super @table_name = table_name @json_columns = [] fetch_fields enable_count end |
Instance Attribute Details
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
10 11 12 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 10 def table_name @table_name end |
Instance Method Details
#aggregate(_caller, filter, aggregation, limit = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 25 def aggregate(_caller, filter, aggregation, limit = nil) sql, binds, group_columns = Utils::Query.new( self, filter: filter, aggregation: aggregation, limit: limit ).to_aggregate_sql raw_rows = execute_raw(sql, binds) raw_rows.map do |row| value = coerce_value(row.first) group_hash = group_columns.each_with_index.to_h { |col, i| [col, coerce_for_column(col, row[i + 1])] } { 'value' => value, 'group' => group_hash } end end |
#create(_caller, _data) ⇒ Object
41 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 41 def create(_caller, _data) = raise(ReadOnlyError, READ_ONLY_MESSAGE) |
#delete(_caller, _filter) ⇒ Object
43 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 43 def delete(_caller, _filter) = raise(ReadOnlyError, READ_ONLY_MESSAGE) |
#list(_caller, filter, projection) ⇒ Object
20 21 22 23 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 20 def list(_caller, filter, projection) sql, binds = Utils::Query.new(self, projection: projection, filter: filter).to_sql execute_to_hashes(sql, binds, projection.to_a) end |
#update(_caller, _filter, _data) ⇒ Object
42 |
# File 'lib/forest_admin_datasource_snowflake/collection.rb', line 42 def update(_caller, _filter, _data) = raise(ReadOnlyError, READ_ONLY_MESSAGE) |