rethinkdb-python

How to retrieve data from RethinkDB via Django view?

余生长醉 提交于 2020-01-17 05:37:48
问题 Am trying to view data from RethinkDB in Django via custom middleware. Below is the middleware code am using to connect to RethinkDB @singleton class rDBMiddleware(object): connection = None def __init__(self): if self.connection == None: self.connection = r.connect(host=' 192.x.x.x ', port=28015, db=' re_test ').repl() views.py - from app.utils import rwrapper from app.utils import fields class MyTable(rwrapper): _db_table = 'test_table' name = fields.CharField(max_length=60) skill = fields

How to retrieve data from RethinkDB via Django view?

↘锁芯ラ 提交于 2020-01-17 05:37:07
问题 Am trying to view data from RethinkDB in Django via custom middleware. Below is the middleware code am using to connect to RethinkDB @singleton class rDBMiddleware(object): connection = None def __init__(self): if self.connection == None: self.connection = r.connect(host=' 192.x.x.x ', port=28015, db=' re_test ').repl() views.py - from app.utils import rwrapper from app.utils import fields class MyTable(rwrapper): _db_table = 'test_table' name = fields.CharField(max_length=60) skill = fields

How to apply Greater than equal in python lambda expression in Rethinkdb

…衆ロ難τιáo~ 提交于 2019-12-25 16:54:01
问题 I have below json record in RethinkDB table. [{ "pid": 12, "sk": [ { "sid": 30, "et": 3 }, { "sid": 22, "et": 10 }, { "sid": 30, "et": 8 } ], "wc": [ { "wid": 7, "et": 8 }, { "wid": 3, "et": 6 }, { "wid": 9, "et": 7 } ] }] Like this one, I have millions of rows in the table. What am trying to achieve is to filter this json based on input sets of {sid,et} Am using below code in python (skObj is the input) :: skObj=[{'sid': 1, 'et': 9},{'sid': 27, 'et': 6}] cursor2=r.table('cube7').filter

Python unicode escape for RethinkDB match (regex) query

坚强是说给别人听的谎言 提交于 2019-12-13 18:16:44
问题 I am trying to perform a rethinkdb match query with an escaped unicode user provided search param: import re from rethinkdb import RethinkDB r = RethinkDB() search_value = u"\u05e5" # provided by user via flask search_value_escaped = re.escape(search_value) # results in u'\\\u05e5' -> # when encoded with "utf-8" gives "\ץ" as expected. conn = rethinkdb.connect(...) results_cursor_a = r.db(...).table(...).order_by(index="id").filter( lambda doc: doc.coerce_to("string").match(search_value) )

Rethinkdb atomic retrieve and update

和自甴很熟 提交于 2019-12-12 04:56:50
问题 Say I have the following data structure: { "name": "i1", "time": 1, "status": 1} { "name": "i2", "time": 2, "status": 1} { "name": "i3", "time": 3, "status": 1} { "name": "i4", "time": 4, "status": 2} I need to retrieve the item with the largest time and "status" = 1. Then update it's "status" to 2, all this atomically, so the same item can't be retrieved by other consumer in the same time. Is this possible with rethinkdb ? 回答1: Since atomicity in RethinkDB is only guaranteed on a per

Rethink DB Cross Cluster Replication

岁酱吖の 提交于 2019-12-11 10:59:51
问题 I have 3 different pool of clients in 3 different geographical locations. I need configure Rethinkdb with 3 different clusters and replicate data between the (insert, update and deletes). I do not want to use shard, only replication. I didn't found in documentation if this is possible. I didn't found in documentation how to configure multi-cluster replication. Any help is appreciated. 回答1: I think that multi cluster is just same a single clusters with nodes in different data center First, you

RethinkDB: “TypeError: 'Var' object is not callable” when using lambda function in filter

百般思念 提交于 2019-12-11 02:46:14
问题 In RethinkDB's data explorer, I'm running this query successfully using javascript: r.db('my_db').table('my_table').filter(function(row){return row('some_key').match(".sometext.")}) But when I'm running it correspondingly in python like this: r.db('my_db').table('my_table').filter(lambda row: row('some_key').match(".sometext.")) I'm getting the following error: TypeError: 'Var' object is not callable In [16]: rql = r.db('my_db').table('my_table').filter(lambda row: row('some_key').match("

RethinkDB: multiple comparisons filtering

流过昼夜 提交于 2019-12-11 02:44:50
问题 By the docs, it seems that in order to filter all users that are 30 years old OR 40 years old, I can do this (with python): r.table("users").filter((r.row["age"].eq(30)) | (r.row["age"].eq(40))).run(conn) Say I have a list based on input / request: [12, 14, 18, 88, 33 ...], how do I filter all the users that are in the age of one of the elements in the list above by iterating it (and not doing it hard coded)? 回答1: That's one way to do it valid_ages = [12, 14, 18, 88, 33] r.table("users")

How do I create a compound multi-index in rethinkdb?

爱⌒轻易说出口 提交于 2019-12-07 06:47:23
问题 I am using Rethinkdb 1.10.1 with the official python driver. I have a table of tagged things which are associated to one user: { "id": "PK", "user_id": "USER_PK", "tags": ["list", "of", "strings"], // Other fields... } I want to query by user_id and tag (say, to find all the things by user "tawmas" with tag "tag"). Starting with Rethinkdb 1.10 I can create a multi-index like this: r.table('things').index_create('tags', multi=True).run(conn) My query would then be: res = (r.table('things')

How do I create a compound multi-index in rethinkdb?

寵の児 提交于 2019-12-05 09:06:55
I am using Rethinkdb 1.10.1 with the official python driver. I have a table of tagged things which are associated to one user: { "id": "PK", "user_id": "USER_PK", "tags": ["list", "of", "strings"], // Other fields... } I want to query by user_id and tag (say, to find all the things by user "tawmas" with tag "tag"). Starting with Rethinkdb 1.10 I can create a multi-index like this: r.table('things').index_create('tags', multi=True).run(conn) My query would then be: res = (r.table('things') .get_all('TAG', index='tags') .filter(r.row['user_id'] == 'USER_PK').run(conn)) However, this query still