2017-03-01 17:37:13 -08:00
|
|
|
|
.. image:: https://travis-ci.org/internetarchive/doublethink.svg?branch=master
|
|
|
|
|
:target: https://travis-ci.org/internetarchive/doublethink
|
2017-02-23 16:07:14 -08:00
|
|
|
|
|
2017-02-28 16:23:59 -08:00
|
|
|
|
doublethink
|
2015-10-30 22:28:51 +00:00
|
|
|
|
============
|
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
RethinkDB python library. Provides connection manager and ORM framework
|
|
|
|
|
(object-relational mapping, sometimes called ODM or OM for nosql databases).
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
Connection Manager
|
|
|
|
|
------------------
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
Three main purposes:
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
- round-robin connections among database servers
|
|
|
|
|
- make sure connections close at proper time
|
2015-10-30 22:28:51 +00:00
|
|
|
|
- retry retry-able queries on failure
|
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
Not currently a connection pool, because it doesn’t keep any connections open.
|
|
|
|
|
Should be possible to implement connection pooling without changing the API.
|
2017-05-22 14:28:22 -07:00
|
|
|
|
However, testing suggests there would be no appreciable performance gain from
|
|
|
|
|
connection pooling.
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
Usage Example
|
|
|
|
|
~~~~~~~~~~~~~
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
2017-02-23 16:07:14 -08:00
|
|
|
|
::
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
2017-02-28 16:23:59 -08:00
|
|
|
|
import doublethink
|
2017-03-01 11:20:27 -08:00
|
|
|
|
rr = doublethink.Rethinker(['db0.foo.com', 'db0.foo.com:38015', 'db1.foo.com'], 'my_db')
|
|
|
|
|
rr.table('mytable').insert({'foo':'bar','baz':2}).run()
|
|
|
|
|
for result in rr.table('mytable'):
|
2017-02-23 16:07:14 -08:00
|
|
|
|
print("result={}".format(result))
|
|
|
|
|
|
|
|
|
|
ORM
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
Simple yet powerful ORM system. *Does not enforce a schema.*
|
|
|
|
|
|
|
|
|
|
Usage Example
|
|
|
|
|
~~~~~~~~~~~~~
|
2015-10-30 22:28:51 +00:00
|
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
2017-02-28 16:23:59 -08:00
|
|
|
|
import doublethink
|
2017-02-23 16:07:14 -08:00
|
|
|
|
|
2017-03-01 11:20:27 -08:00
|
|
|
|
rr = doublethink.Rethinker(['db0.foo.com', 'db0.foo.com:38015', 'db1.foo.com'], 'my_db')
|
2017-02-23 16:07:14 -08:00
|
|
|
|
|
2017-02-28 16:23:59 -08:00
|
|
|
|
class MyTable(doublethink.Document):
|
2017-02-23 16:07:14 -08:00
|
|
|
|
pass
|
2017-03-01 11:20:27 -08:00
|
|
|
|
MyTable.table_create(rr)
|
2017-02-23 16:07:14 -08:00
|
|
|
|
|
2017-03-01 11:20:27 -08:00
|
|
|
|
doc1 = MyTable(rr, {'animal': 'elephant', 'size': 'large'})
|
2017-02-23 16:07:14 -08:00
|
|
|
|
doc1.save()
|
|
|
|
|
|
2017-03-07 12:44:52 -08:00
|
|
|
|
doc1_copy = MyTable.load(rr, doc1.id)
|
2017-02-23 16:07:14 -08:00
|
|
|
|
doc1_copy.food = 'bread'
|
|
|
|
|
doc1_copy.save()
|
|
|
|
|
|
|
|
|
|
doc1.first_name = 'Frankworth'
|
|
|
|
|
doc1.save()
|
|
|
|
|
|
|
|
|
|
doc1.refresh()
|
|
|
|
|
|
|
|
|
|
Service Registry
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
Now also has a ServiceRegistry class, a lightweight solution for service
|
|
|
|
|
discovery for distributed services. Maintains service info and status in
|
|
|
|
|
a rethinkdb table called “services”.
|
|
|
|
|
|