forked from basho/riak-python-client
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtable.py
More file actions
102 lines (83 loc) · 2.99 KB
/
Copy pathtable.py
File metadata and controls
102 lines (83 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 2010-present Basho Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class Table(object):
"""
The ``Table`` object allows you to access properties on a Riak
timeseries table and query timeseries data.
"""
def __init__(self, client, name):
"""
Returns a new ``Table`` instance.
:param client: A :class:`RiakClient <riak.client.RiakClient>`
instance
:type client: :class:`RiakClient <riak.client.RiakClient>`
:param name: The table"s name
:type name: string
"""
if not isinstance(name, str):
raise TypeError("Table name must be a string")
self._client = client
self.name = name
def __str__(self):
return self.name
def __repr__(self):
return self.name
def new(self, rows, columns=None):
"""
A shortcut for manually instantiating a new
:class:`~riak.ts_object.TsObject`
:param rows: An list of lists with timeseries data
:type rows: list
:param columns: An list of Column names and types. Optional.
:type columns: list
:rtype: :class:`~riak.ts_object.TsObject`
"""
from riak.ts_object import TsObject
return TsObject(self._client, self, rows, columns)
def describe(self):
"""
Retrieves a timeseries table"s description.
:rtype: :class:`TsObject <riak.ts_object.TsObject>`
"""
return self._client.ts_describe(self)
def get(self, key):
"""
Gets a value from a timeseries table.
:param key: The timeseries value"s key.
:type key: list
:rtype: :class:`TsObject <riak.ts_object.TsObject>`
"""
return self._client.ts_get(self, key)
def delete(self, key):
"""
Deletes a value from a timeseries table.
:param key: The timeseries value"s key.
:type key: list or dict
:rtype: boolean
"""
return self._client.ts_delete(self, key)
def query(self, query, interpolations=None):
"""
Queries a timeseries table.
:param query: The timeseries query.
:type query: string
:rtype: :class:`TsObject <riak.ts_object.TsObject>`
"""
return self._client.ts_query(self, query, interpolations)
def stream_keys(self, timeout=None):
"""
Streams keys from a timeseries table.
:rtype: list
"""
return self._client.ts_stream_keys(self, timeout)