Class: TableStore

Inherits:
Object
  • Object
show all
Defined in:
lib/tablestore-ruby-sdk.rb

Constant Summary collapse

DEFAULT_ENCODING =
'utf8'
DEFAULT_SOCKET_TIMEOUT =
50
DEFAULT_MAX_CONNECTION =
50
DEFAULT_LOGGER_NAME =
'tablestore-client'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, access_key_id, access_key_secret, instance_name, **kwargs) ⇒ TableStore

Returns a new instance of TableStore.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tablestore-ruby-sdk.rb', line 16

def initialize(base_url, access_key_id, access_key_secret, instance_name, **kwargs)
  # 初始化TableStoreClient实例。
  # end_point是TableStoreClient服务的地址(例如 'http://instance.cn-hangzhou.TableStoreClient.aliyun.com'),必须以'http://'或'https://'开头。
  # access_key_id是访问TableStoreClient服务的accessid,通过官方网站申请或通过管理员获取。
  # access_key_secret是访问TableStoreClient服务的accesskey,通过官方网站申请或通过管理员获取。
  # instance_name是要访问的实例名,通过官方网站控制台创建或通过管理员获取。
  # sts_token是访问TableStoreClient服务的STS token,从STS服务获取,具有有效期,过期后需要重新获取。
  # encoding请求参数的字符串编码类型,默认是utf8。
  # socket_timeout是连接池中每个连接的Socket超时,单位为秒,可以为int或float。默认值为50。
  # max_connection是连接池的最大连接数。默认为50,
  # logger_name用来在请求中打DEBUG日志,或者在出错时打ERROR日志。
  # retry_policy定义了重试策略,默认的重试策略为 DefaultRetryPolicy。你可以继承 RetryPolicy 来实现自己的重试策略,请参考 DefaultRetryPolicy 的代码。

  #self.validate_parameter(end_point, access_key_id, access_key_secret, instance_name)
  #sts_token = kwargs.get('sts_token')

  self.base_url            = base_url
  self.access_key_id       = access_key_id
  self.access_key_secret   = access_key_secret
  self.instance_name       = instance_name

  #示例:创建一个TableStoreClient实例
  # from tablestore.client import TableStoreClient
  # client = TableStoreClient('your_instance_endpoint', 'your_user_id', 'your_user_key', 'your_instance_name')
end

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def access_key_id
  @access_key_id
end

#access_key_secretObject

Returns the value of attribute access_key_secret.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def access_key_secret
  @access_key_secret
end

#base_urlObject

Returns the value of attribute base_url.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def base_url
  @base_url
end

#instance_nameObject

Returns the value of attribute instance_name.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def instance_name
  @instance_name
end

Instance Method Details

#_batch_get_row(request) ⇒ Object



119
120
121
122
123
124
# File 'lib/tablestore-ruby-sdk.rb', line 119

def _batch_get_row(request)
  api_name = 'BatchGetRow'
  body = TableStoreClient.new.make_batch_get_row(request)
  response = post_request(body, api_name)
  TableStoreClient.new.decode_batch_get_row(response.body)
end

#_batch_write_row(request) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/tablestore-ruby-sdk.rb', line 126

def _batch_write_row(request)
  api_name = 'BatchWriteRow'
  body = TableStoreClient.new.make_batch_write_row(request)
  response = post_request(body, api_name)
  if response.code == 200
    'write succeed!'
  end
end

#_create_table(table_meta, table_option, reserved_throughput) ⇒ Object

tables



43
44
45
46
47
48
49
50
# File 'lib/tablestore-ruby-sdk.rb', line 43

def _create_table(table_meta, table_option, reserved_throughput)
  api_name = 'CreateTable'
  body = TableStoreClient.new.encode_create_table(table_meta, table_option, reserved_throughput)
  response = post_request(body, api_name)
  if response.code == 200
    "create table #{table_meta.table_name} succeed!"
  end
end

#_delete_row(table_name, row, condition) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/tablestore-ruby-sdk.rb', line 110

def _delete_row(table_name, row, condition)
  api_name = 'DeleteRow'
  body = TableStoreClient.new.encode_delete_row(table_name, row, condition)
  response = post_request(body, api_name)
  if response.code == 200
    'delete succeed!'
  end
end

#_delete_table(table_name) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/tablestore-ruby-sdk.rb', line 68

def _delete_table(table_name)
  api_name = 'DeleteTable'
  body = TableStoreClient.new.encode_delete_table(table_name)
  response = post_request(body, api_name)
  if response.code == 200
    "delete table #{table_name} succeed!"
  end
end

#_get_range(request) ⇒ Object

rows



78
79
80
81
82
83
# File 'lib/tablestore-ruby-sdk.rb', line 78

def _get_range(request)
  api_name = 'GetRange'
  body = TableStoreClient.new.encode_get_range_request(request)
  response = post_request(body, api_name)
  TableStoreClient.new.decode_get_range_request(response.body)
end

#_get_row(table_name, primary_key, columns_to_get = nil, column_filter = nil, max_version = 1) ⇒ Object



94
95
96
97
98
99
# File 'lib/tablestore-ruby-sdk.rb', line 94

def _get_row(table_name, primary_key, columns_to_get=nil, column_filter=nil, max_version=1)
  api_name = 'GetRow'
  body = TableStoreClient.new.encode_get_row(table_name, primary_key, columns_to_get, column_filter, max_version)
  response = post_request(body, api_name)
  TableStoreClient.new.decode_get_row(response.body)
end

#_list_tableObject



52
53
54
55
56
57
# File 'lib/tablestore-ruby-sdk.rb', line 52

def _list_table
  api_name = "ListTable"
  body = TableStoreClient.new.encode_list_table
  response = post_request(body, api_name)
  TableStoreClient.new.decode_list_table(response.body)
end

#_put_row(table_name, row, condition) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/tablestore-ruby-sdk.rb', line 85

def _put_row(table_name, row, condition)
  api_name = 'PutRow'
  body = TableStoreClient.new.encode_put_row(table_name, row, condition)
  response = post_request(body, api_name)
  if response.code == 200
    'write succeed!'
  end
end

#_update_row(table_name, row, condition) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/tablestore-ruby-sdk.rb', line 101

def _update_row(table_name, row, condition)
  api_name = 'UpdateRow'
  body = TableStoreClient.new.encode_update_row(table_name, row, condition)
  response = post_request(body, api_name)
  if response.code == 200
    'update succeed!'
  end
end

#_update_table(table_name, table_option, reserved_throughput = nil) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/tablestore-ruby-sdk.rb', line 59

def _update_table(table_name, table_option, reserved_throughput=nil)
  api_name = 'UpdateTable'
  body = TableStoreClient.new.encode_update_table(table_name, table_option, reserved_throughput)
  response = post_request(body, api_name)
  if response.code == 200
    "update table #{table_name} succeed!"
  end
end