Class: AxHub::Data::DataClient
- Inherits:
-
Object
- Object
- AxHub::Data::DataClient
- Defined in:
- lib/axhub_sdk/data/client.rb
Overview
Entry point for the ergonomic data layer; holds the per-client schema cache used by discover() (mirrors node DataClient).
Instance Method Summary collapse
- #discover(tenant_slug, app_slug, table, fresh: nil, ttl_ms: nil) ⇒ Object
-
#initialize(client, schema_cache: nil) ⇒ DataClient
constructor
A new instance of DataClient.
- #invalidate_schema(tenant_slug = nil, app_slug = nil, table = nil) ⇒ Object
- #scoped(tenant_slug) ⇒ Object
- #table(tenant_slug, app_slug, table) ⇒ Object
Constructor Details
#initialize(client, schema_cache: nil) ⇒ DataClient
Returns a new instance of DataClient.
214 215 216 217 218 219 220 221 |
# File 'lib/axhub_sdk/data/client.rb', line 214 def initialize(client, schema_cache: nil) @client = client @schema_cache = case schema_cache when SchemaCache then schema_cache when Hash then SchemaCache.new(**schema_cache.transform_keys(&:to_sym)) else SchemaCache.new end end |
Instance Method Details
#discover(tenant_slug, app_slug, table, fresh: nil, ttl_ms: nil) ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/axhub_sdk/data/client.rb', line 233 def discover(tenant_slug, app_slug, table, fresh: nil, ttl_ms: nil) key = Data.schema_cache_key(tenant_slug, app_slug, table) schema = @schema_cache.get_or_set(key, fresh: fresh, ttl_ms: ttl_ms) do Data.fetch_discovered_schema(@client, tenant_slug, app_slug, table, fresh: fresh, ttl_ms: ttl_ms) end DataTableClient.new(@client, tenant_slug, app_slug, schema.table, schema) end |
#invalidate_schema(tenant_slug = nil, app_slug = nil, table = nil) ⇒ Object
241 242 243 244 245 246 247 |
# File 'lib/axhub_sdk/data/client.rb', line 241 def invalidate_schema(tenant_slug = nil, app_slug = nil, table = nil) if !tenant_slug.nil? && !app_slug.nil? && !table.nil? @schema_cache.invalidate(Data.schema_cache_key(tenant_slug, app_slug, table)) return end @schema_cache.invalidate end |
#scoped(tenant_slug) ⇒ Object
229 230 231 |
# File 'lib/axhub_sdk/data/client.rb', line 229 def scoped(tenant_slug) TenantDataFactory.new(self, tenant_slug) end |
#table(tenant_slug, app_slug, table) ⇒ Object
223 224 225 226 227 |
# File 'lib/axhub_sdk/data/client.rb', line 223 def table(tenant_slug, app_slug, table) schema = table.is_a?(DataTableSchema) ? table : nil table_name = table.is_a?(DataTableSchema) ? table.table : table DataTableClient.new(@client, tenant_slug, app_slug, table_name, schema) end |