Module: TreasureData::API::Database

Included in:
TreasureData::API
Defined in:
lib/td/client/api/database.rb

Instance Method Summary collapse

Instance Method Details

#create_database(db, opts = {}) ⇒ true

Parameters:

  • db (String)
  • opts (Hash) (defaults to: {})

Returns:

  • (true)


40
41
42
43
44
45
46
47
# File 'lib/td/client/api/database.rb', line 40

def create_database(db, opts={})
  params = opts.dup
  code, body, res = post("/v3/database/create/#{e db}", params)
  if code != "200"
    raise_error("Create database failed", res)
  end
  return true
end

#delete_database(db) ⇒ true

Parameters:

  • db (String)

Returns:

  • (true)


29
30
31
32
33
34
35
# File 'lib/td/client/api/database.rb', line 29

def delete_database(db)
  code, body, res = post("/v3/database/delete/#{e db}")
  if code != "200"
    raise_error("Delete database failed", res)
  end
  return true
end

#list_databasesArray<String>

Returns names as array.

Returns:

  • (Array<String>)

    names as array



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/td/client/api/database.rb', line 9

def list_databases
  code, body, res = get("/v3/database/list")
  if code != "200"
    raise_error("List databases failed", res)
  end
  js = checked_json(body, %w[databases])
  result = {}
  js["databases"].each {|m|
    name = m['name']
    count = m['count']
    created_at = m['created_at']
    updated_at = m['updated_at']
    permission = m['permission']
    result[name] = [count, created_at, updated_at, nil, permission] # set nil to org for API compatibiilty
  }
  return result
end