manager
¶
-
class
pyhs.manager.
Manager
(read_servers=None, write_servers=None, debug=False)¶ High-level client for HandlerSocket.
This should be used in most cases except ones that you need fine-grained control over index management, low-level operations, etc. For such cases
ReadSocket
andWriteSocket
can be used.Constructor initializes both read and write sockets.
Parameters: - read_servers (list of tuples or None) – list of tuples that define HandlerSocket read
instances. See format in
HandlerSocket
constructor. - write_servers (list of tuples or None) – list of tuples that define HandlerSocket write
instances. Format is the same as in
read_servers
. - debug (bool) – enable debug mode by passing
True
.
-
find
(db, table, operation, fields, values, index_name=None, limit=0, offset=0)¶ Finds rows that meet
values
with comparisonoperation
in givendb
andtable
.Returns a list of lists of pairs. First item in pair is field name, second is its value. For example, if two rows with two columns each are returned:
[[('field', 'first_row_value'), ('otherfield', 'first_row_othervalue')], [('field', 'second_row_value'), ('otherfield', 'second_row_othervalue')]]
Parameters: - db (string) – database name
- table (string) – table name
- operation (string) – logical comparison operation to use over
columns
. Currently allowed operations are defined inFIND_OPERATIONS
. Only one operation is allowed per call. - fields (list) – list of table’s fields to get, ordered by inclusion into the index.
- values (list) – values to compare to, ordered the same way as items
in
fields
. - index_name (string or None) – name of the index to open, default is
PRIMARY
. - limit (integer) – optional limit of results. Default is one row.
In case multiple rows are expected to be returned,
limit
must be set explicitly, HS wont get all found rows by default. - offset (integer) – optional offset of rows to search for.
Return type: list of lists of tuples
-
insert
(db, table, fields, index_name=None)¶ Inserts a single row into given
table
.Parameters: - db (string) – database name.
- table (string) – table name.
- fields (list of lists) – list of (column, value) pairs to insert into the
table
. - index_name (string or None) – name of the index to open, default is
PRIMARY
.
Return type: bool
-
update
(db, table, operation, fields, values, update_values, index_name=None, limit=0, offset=0, return_original=False)¶ Update row(s) that meet conditions defined by
operation
,fields
values
in a giventable
.Parameters: - db (string) – database name
- table (string) – table name
- operation (string) – logical comparison operation to use over
columns
. Currently allowed operations are defined inFIND_OPERATIONS
. Only one operation is allowed per call. - fields (list) – list of table’s fields to use, ordered by inclusion into the index.
- values (list) – values to compare to, ordered the same way as items
in
fields
. - update_values (list) – values to update, ordered the same way as items
in
fields
. - index_name (string or None) – name of the index to open, default is
PRIMARY
. - limit (integer) – optional limit of rows. Default is one row.
In case multiple rows are expected to be updated,
limit
must be set explicitly, HS wont update all found rows by default. - offset (integer) – optional offset of rows to search for.
- return_original (bool) – if set to
True
, method will return a list of original values in affected rows. Otherwise - number of affected rows (this is default behaviour).
Return type: int or list
-
incr
(db, table, operation, fields, values, step=['1'], index_name=None, limit=0, offset=0, return_original=False)¶ Increments row(s) that meet conditions defined by
operation
,fields
values
in a giventable
.Parameters: - db (string) – database name
- table (string) – table name
- operation (string) – logical comparison operation to use over
columns
. Currently allowed operations are defined inFIND_OPERATIONS
. Only one operation is allowed per call. - fields (list) – list of table’s fields to use, ordered by inclusion into the index.
- values (list) – values to compare to, ordered the same way as items
in
fields
. - step (list) – list of increment steps, ordered the same way as items
in
fields
. - index_name (string or None) – name of the index to open, default is
PRIMARY
. - limit (integer) – optional limit of rows. Default is one row.
In case multiple rows are expected to be updated,
limit
must be set explicitly, HS wont update all found rows by default. - offset (integer) – optional offset of rows to search for.
- return_original (bool) – if set to
True
, method will return a list of original values in affected rows. Otherwise - number of affected rows (this is default behaviour).
Return type: int or list
-
decr
(db, table, operation, fields, values, step=['1'], index_name=None, limit=0, offset=0, return_original=False)¶ Decrements row(s) that meet conditions defined by
operation
,fields
values
in a giventable
.Parameters: - db (string) – database name
- table (string) – table name
- operation (string) – logical comparison operation to use over
columns
. Currently allowed operations are defined inFIND_OPERATIONS
. Only one operation is allowed per call. - fields (list) – list of table’s fields to use, ordered by inclusion into the index.
- values (list) – values to compare to, ordered the same way as items
in
fields
. - step (list) – list of decrement steps, ordered the same way as items
in
fields
. - index_name (string or None) – name of the index to open, default is
PRIMARY
. - limit (integer) – optional limit of rows. Default is one row.
In case multiple rows are expected to be updated,
limit
must be set explicitly, HS wont update all found rows by default. - offset (integer) – optional offset of rows to search for.
- return_original (bool) – if set to
True
, method will return a list of original values in affected rows. Otherwise - number of affected rows (this is default behaviour).
Return type: int or list
-
delete
(db, table, operation, fields, values, index_name=None, limit=0, offset=0, return_original=False)¶ Delete row(s) that meet conditions defined by
operation
,fields
values
in a giventable
.Parameters: - db (string) – database name
- table (string) – table name
- operation (string) – logical comparison operation to use over
columns
. Currently allowed operations are defined inFIND_OPERATIONS
. Only one operation is allowed per call. - fields (list) – list of table’s fields to use, ordered by inclusion into the index.
- values (list) – values to compare to, ordered the same way as items
in
fields
. - index_name (string or None) – name of the index to open, default is
PRIMARY
. - limit (integer) – optional limit of rows. Default is one row.
In case multiple rows are expected to be deleted,
limit
must be set explicitly, HS wont delete all found rows by default. - offset (integer) – optional offset of rows to search for.
- return_original (bool) – if set to
True
, method will return a list of original values in affected rows. Otherwise - number of affected rows (this is default behaviour).
Return type: int or list
-
get
(db, table, fields, value)¶ A wrapper over
find()
that gets a single row with a single field look up.Returns a list of pairs. First item in pair is field name, second is its value.
If multiple result rows, different comparison operation or composite indexes are needed please use
find()
instead.Parameters: - db (string) – database name.
- table (string) – table name.
- fields (list) – list of table’s fields to get, ordered by inclusion into the index. First item must always be the look up field.
- value (string) – a look up value.
Return type: list of tuples
-
purge
()¶ Purges all read and write connections. All requests after that operation will open new connections, index caches will be cleaned too.
- read_servers (list of tuples or None) – list of tuples that define HandlerSocket read
instances. See format in