lib/td/client/api/table.rb in td-client-0.8.68 vs lib/td/client/api/table.rb in td-client-0.8.69
- old
+ new
@@ -3,11 +3,12 @@
####
## Table API
##
- # => {name:String => [type:Symbol, count:Integer]}
+ # @param [String] db
+ # @return [Array]
def list_tables(db)
code, body, res = get("/v3/table/list/#{e db}")
if code != "200"
raise_error("List tables failed", res)
end
@@ -29,76 +30,110 @@
result[name] = [type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days, primary_key, primary_key_type]
}
return result
end
+ # @param [String] db
+ # @param [String] table
+ # @param [String] type
+ # @return [true]
def create_log_or_item_table(db, table, type)
code, body, res = post("/v3/table/create/#{e db}/#{e table}/#{type}")
if code != "200"
raise_error("Create #{type} table failed", res)
end
return true
end
private :create_log_or_item_table
- # => true
+ # @param [String] db
+ # @param [String] table
+ # @return [true]
def create_log_table(db, table)
create_table(db, table, :log)
end
- # => true
+ # @param [String] db
+ # @param [String] table
+ # @param [String] primary_key
+ # @param [String] primary_key_type
+ # @return [true]
def create_item_table(db, table, primary_key, primary_key_type)
params = {'primary_key' => primary_key, 'primary_key_type' => primary_key_type}
create_table(db, table, :item, params)
end
+ # @param [String] db
+ # @param [String] table
+ # @param [String] type
+ # @param [Hash] params
+ # @return [true]
def create_table(db, table, type, params={})
schema = schema.to_s
code, body, res = post("/v3/table/create/#{e db}/#{e table}/#{type}", params)
if code != "200"
raise_error("Create #{type} table failed", res)
end
return true
end
private :create_table
- # => true
+ # @param [String] db
+ # @param [String] table1
+ # @param [String] table2
+ # @return [true]
def swap_table(db, table1, table2)
code, body, res = post("/v3/table/swap/#{e db}/#{e table1}/#{e table2}")
if code != "200"
raise_error("Swap tables failed", res)
end
return true
end
- # => true
+ # @param [String] db
+ # @param [String] table
+ # @param [String] schema_json
+ # @return [true]
def update_schema(db, table, schema_json)
code, body, res = post("/v3/table/update-schema/#{e db}/#{e table}", {'schema'=>schema_json})
if code != "200"
raise_error("Create schema table failed", res)
end
return true
end
+ # @param [String] db
+ # @param [String] table
+ # @param [Fixnum] expire_days
+ # @return [true]
def update_expire(db, table, expire_days)
code, body, res = post("/v3/table/update/#{e db}/#{e table}", {'expire_days'=>expire_days})
if code != "200"
raise_error("Update table expiration failed", res)
end
return true
end
- # => type:Symbol
+ # @param [String] db
+ # @param [String] table
+ # @return [Symbol]
def delete_table(db, table)
code, body, res = post("/v3/table/delete/#{e db}/#{e table}")
if code != "200"
raise_error("Delete table failed", res)
end
js = checked_json(body, %w[])
type = (js['type'] || '?').to_sym
return type
end
+ # @param [String] db
+ # @param [String] table
+ # @param [Fixnum] count
+ # @param [Fixnum] to
+ # @param [Fixnum] from
+ # @param [Proc] block
+ # @return [Array, nil]
def tail(db, table, count, to, from, &block)
params = {'format' => 'msgpack'}
params['count'] = count.to_s if count
params['to'] = to.to_s if to
params['from'] = from.to_s if from