Class: TreasureData::Database

Inherits:
Model
  • Object
show all
Defined in:
lib/td/client/model.rb

Constant Summary collapse

PERMISSIONS =
[:administrator, :full_access, :import_only, :query_only]
PERMISSION_LIST_TABLES =
[:administrator, :full_access]

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Instance Method Summary collapse

Constructor Details

#initialize(client, db_name, tables = nil, count = nil, created_at = nil, updated_at = nil, org_name = nil, permission = nil) ⇒ Database

Returns a new instance of Database.

Parameters:

  • client (TreasureData::Client)
  • db_name (String)
  • tables (Array<Table>) (defaults to: nil)
  • count (Fixnum) (defaults to: nil)
  • created_at (String) (defaults to: nil)
  • updated_at (String) (defaults to: nil)
  • org_name (String) (defaults to: nil)
  • permission (String) (defaults to: nil)


72
73
74
75
76
77
78
79
80
# File 'lib/td/client/model.rb', line 72

def initialize(client, db_name, tables=nil, count=nil, created_at=nil, updated_at=nil, org_name=nil, permission=nil)
  super(client)
  @db_name = db_name
  @tables = tables
  @count = count
  @created_at = created_at
  @updated_at = updated_at
  @permission = permission.to_sym
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



85
# File 'lib/td/client/model.rb', line 85

attr_reader :org_name, :permission, :count

#org_nameObject (readonly)



85
86
87
# File 'lib/td/client/model.rb', line 85

def org_name
  @org_name
end

#permissionObject (readonly)



85
# File 'lib/td/client/model.rb', line 85

attr_reader :org_name, :permission, :count

Instance Method Details

#create_log_table(name) ⇒ true

Parameters:

  • name (String)

Returns:

  • (true)


100
101
102
# File 'lib/td/client/model.rb', line 100

def create_log_table(name)
  @client.create_log_table(@db_name, name)
end

#created_atTime?

Returns:

  • (Time, nil)


122
123
124
# File 'lib/td/client/model.rb', line 122

def created_at
  @created_at && !@created_at.empty? ? Time.parse(@created_at) : nil
end

#deleteSymbol

Returns:

  • (Symbol)


111
112
113
# File 'lib/td/client/model.rb', line 111

def delete
  @client.delete_database(@db_name)
end

#nameString

Returns db_name.

Returns:

  • (String)

    db_name



88
89
90
# File 'lib/td/client/model.rb', line 88

def name
  @db_name
end

#query(q) ⇒ Job

Parameters:

  • q (String)

Returns:



117
118
119
# File 'lib/td/client/model.rb', line 117

def query(q)
  @client.query(@db_name, q)
end

#table(table_name) ⇒ Table

Parameters:

  • table_name (String)

Returns:



106
107
108
# File 'lib/td/client/model.rb', line 106

def table(table_name)
  @client.table(@db_name, table_name)
end

#tablesArray<Table>

Returns:



93
94
95
96
# File 'lib/td/client/model.rb', line 93

def tables
  update_tables! unless @tables
  @tables
end

#update_tables!nil

Returns:

  • (nil)


132
133
134
135
136
137
138
139
# File 'lib/td/client/model.rb', line 132

def update_tables!
  @tables = @client.tables(@db_name)
  # provide Table objects with a reference to the parent Database to avoid
  # requesting the Database information (such as permission) every time
  @tables.each {|table|
    table.database = self
  }
end

#updated_atTime?

Returns:

  • (Time, nil)


127
128
129
# File 'lib/td/client/model.rb', line 127

def updated_at
  @updated_at && !@updated_at.empty? ? Time.parse(@updated_at) : nil
end