warcprox/README.rst

70 lines
1.7 KiB
ReStructuredText
Raw Normal View History

.. image:: https://travis-ci.org/nlevitt/doublethink.svg?branch=master
:target: https://travis-ci.org/nlevitt/doublethink
2017-02-23 16:07:14 -08:00
doublethink
============
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).
2017-02-23 16:07:14 -08:00
Connection Manager
------------------
2017-02-23 16:07:14 -08:00
Three main purposes:
2017-02-23 16:07:14 -08:00
- round-robin connections among database servers
- make sure connections close at proper time
- retry retry-able queries on failure
2017-02-23 16:07:14 -08:00
Not currently a connection pool, because it doesnt keep any connections open.
Should be possible to implement connection pooling without changing the API.
2017-02-23 16:07:14 -08:00
Usage Example
~~~~~~~~~~~~~
2017-02-23 16:07:14 -08:00
::
import doublethink
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
~~~~~~~~~~~~~
::
import doublethink
2017-02-23 16:07:14 -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
class MyTable(doublethink.Document):
2017-02-23 16:07:14 -08:00
pass
MyTable.table_create(rr)
2017-02-23 16:07:14 -08:00
doc1 = MyTable(rr, {'animal': 'elephant', 'size': 'large'})
2017-02-23 16:07:14 -08:00
doc1.save()
doc1_copy = MyTable.get(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”.