Class: TreasureData::Table

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

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Instance Method Summary collapse

Constructor Details

#initialize(client, db_name, table_name, type, schema, count, created_at = nil, updated_at = nil, estimated_storage_size = nil, last_import = nil, last_log_timestamp = nil) ⇒ Table

Returns a new instance of Table.



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/td/client/model.rb', line 101

def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil, last_import=nil, last_log_timestamp=nil)
  super(client)
  @db_name = db_name
  @table_name = table_name
  @type = type
  @schema = schema
  @count = count
  @created_at = created_at
  @updated_at = updated_at
  @estimated_storage_size = estimated_storage_size
  @last_import = last_import
  @last_log_timestamp = last_log_timestamp
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



115
116
117
# File 'lib/td/client/model.rb', line 115

def count
  @count
end

#db_nameObject (readonly) Also known as: database_name

Returns the value of attribute db_name.



115
116
117
# File 'lib/td/client/model.rb', line 115

def db_name
  @db_name
end

#estimated_storage_sizeObject (readonly)

Returns the value of attribute estimated_storage_size.



115
116
117
# File 'lib/td/client/model.rb', line 115

def estimated_storage_size
  @estimated_storage_size
end

#schemaObject (readonly)

Returns the value of attribute schema.



115
116
117
# File 'lib/td/client/model.rb', line 115

def schema
  @schema
end

#table_nameObject (readonly) Also known as: name

Returns the value of attribute table_name.



115
116
117
# File 'lib/td/client/model.rb', line 115

def table_name
  @table_name
end

#typeObject (readonly)

Returns the value of attribute type.



115
116
117
# File 'lib/td/client/model.rb', line 115

def type
  @type
end

Instance Method Details

#created_atObject



120
121
122
# File 'lib/td/client/model.rb', line 120

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

#databaseObject



136
137
138
# File 'lib/td/client/model.rb', line 136

def database
  @client.database(@db_name)
end

#deleteObject



144
145
146
# File 'lib/td/client/model.rb', line 144

def delete
  @client.delete_table(@db_name, @table_name)
end

#estimated_storage_size_stringObject



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/td/client/model.rb', line 160

def estimated_storage_size_string
  if @estimated_storage_size <= 1024*1024
    return "0.0 GB"
  elsif @estimated_storage_size <= 60*1024*1024
    return "0.01 GB"
  elsif @estimated_storage_size <= 60*1024*1024*1024
    "%.1f GB" % (@estimated_storage_size.to_f / (1024*1024*1024))
  else
    "%d GB" % (@estimated_storage_size.to_f / (1024*1024*1024)).to_i
  end
end

#export(storage_type, opts = {}) ⇒ Object



156
157
158
# File 'lib/td/client/model.rb', line 156

def export(storage_type, opts={})
  @client.export(@db_name, @table_name, storage_type, opts)
end

#identifierObject



140
141
142
# File 'lib/td/client/model.rb', line 140

def identifier
  "#{@db_name}.#{@table_name}"
end

#import(format, stream, size) ⇒ Object



152
153
154
# File 'lib/td/client/model.rb', line 152

def import(format, stream, size)
  @client.import(@db_name, @table_name, format, stream, size)
end

#last_importObject



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

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

#last_log_timestampObject



132
133
134
# File 'lib/td/client/model.rb', line 132

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

#tail(count, to = nil, from = nil) ⇒ Object



148
149
150
# File 'lib/td/client/model.rb', line 148

def tail(count, to=nil, from=nil)
  @client.tail(@db_name, @table_name, count, to, from)
end

#updated_atObject



124
125
126
# File 'lib/td/client/model.rb', line 124

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