Class: Mode::Sdk::Actions::TableUpsert

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/sdk/actions/table_upsert.rb

Overview

Represents a create or replace action for a table in Mode's public warehouse

Defined Under Namespace

Classes: InvalidError

Instance Method Summary collapse

Constructor Details

#initialize(table, action, options = {}) ⇒ Mode::Sdk::Actions::TableUpsert

Construct a new TableUpsert instance

Parameters:

  • table (Mode::Sdk::Table)

    the table to create or replace

  • action (Symbol)

    the action (:create or :replace)

  • options (optional, Hash) (defaults to: {})

    hash of options

Options Hash (options):

  • :clean (true, false)

    whether to clean table data


22
23
24
25
26
# File 'lib/mode/sdk/actions/table_upsert.rb', line 22

def initialize(table, action, options = {})
  @table   = table
  @action  = action
  @options = options
end

Instance Method Details

#performMode::Sdk::Client::Response

Perform the create or replace action

Returns:

Raises:


35
36
37
38
39
40
41
42
43
44
# File 'lib/mode/sdk/actions/table_upsert.rb', line 35

def perform
  response = Mode::Sdk::Client.send(
    verb, path, data, expect: [202, 400])

  unless response.code == 202
    fail InvalidError, "Could not #{action} table: #{response.body}"
  end

  response
end