Skip to content

Commit 1fd4d58

Browse files
committed
Change importing of RethinkDB class
1 parent 7167597 commit 1fd4d58

File tree

6 files changed

+19
-31
lines changed

6 files changed

+19
-31
lines changed

README.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ $ pip install rethinkdb
1616
The main difference with the previous driver (except the name of the package) is we are **not** importing RethinkDB as `r`. If you would like to use `RethinkDB`'s python driver as a drop in replacement, you should do the following:
1717

1818
```python
19-
from rethinkdb import RethinkDB
19+
from rethinkdb import r
2020

21-
r = RethinkDB()
2221
connection = r.connect(db='test')
2322
```
2423

@@ -40,9 +39,8 @@ sockets. This example shows how to create a table, populate with data, and get e
4039
document.
4140

4241
```python
43-
from rethinkdb import RethinkDB
42+
from rethinkdb import r
4443

45-
r = RethinkDB()
4644
connection = r.connect(db='test')
4745

4846
r.table_create('marvel').run(connection)
@@ -64,13 +62,12 @@ introduced into the standard library.
6462

6563
```python
6664
import asyncio
67-
from rethinkdb import RethinkDB
65+
from rethinkdb import r
6866

6967
# Native coroutines are supported in Python ≥ 3.5. In Python 3.4, you should
7068
# use the @asyncio.couroutine decorator instead of "async def", and "yield from"
7169
# instead of "await".
7270
async def main():
73-
r = RethinkDB()
7471
r.set_loop_type('asyncio')
7572
connection = await r.connect(db='test')
7673

@@ -96,10 +93,9 @@ asyncio.get_event_loop().run_until_complete(main())
9693

9794
```python
9895
import gevent
99-
from rethinkdb import RethinkDB
96+
from rethinkdb import r
10097

10198
def main():
102-
r = RethinkDB()
10399
r.set_loop_type('gevent')
104100
connection = r.connect(db='test')
105101

@@ -122,13 +118,12 @@ gevent.joinall([gevent.spawn(main)])
122118
Tornado mode is compatible with Tornado < 5.0.0. Tornado 5 is not supported.
123119

124120
```python
125-
from rethinkdb import RethinkDB
121+
from rethinkdb import r
126122
from tornado import gen
127123
from tornado.ioloop import IOLoop
128124

129125
@gen.coroutine
130126
def main():
131-
r = RethinkDB()
132127
r.set_loop_type('tornado')
133128
connection = yield r.connect(db='test')
134129

@@ -152,11 +147,10 @@ IOLoop.current().run_sync(main)
152147
### Trio mode
153148

154149
```python
155-
from rethinkdb import RethinkDB
150+
from rethinkdb import r
156151
import trio
157152

158153
async def main():
159-
r = RethinkDB()
160154
r.set_loop_type('trio')
161155
async with trio.open_nursery() as nursery:
162156
async with r.open(db='test', nursery=nursery) as conn:
@@ -191,12 +185,11 @@ await db_pool.close()
191185
### Twisted mode
192186

193187
```python
194-
from rethinkdb import RethinkDB
188+
from rethinkdb import r
195189
from twisted.internet import reactor, defer
196190

197191
@defer.inlineCallbacks
198192
def main():
199-
r = RethinkDB()
200193
r.set_loop_type('twisted')
201194
connection = yield r.connect(db='test')
202195

@@ -219,7 +212,7 @@ reactor.run()
219212
```
220213

221214
## Misc
222-
Although we recommend to use the import used in the examples, to help the migration from rethinkdb<2.4 we introduced a shortcut which can easily replace the old `import rethinkdb as r` import with `from rethinkdb import r`.
215+
To help the migration from rethinkdb<2.4 we introduced a shortcut which can easily replace the old `import rethinkdb as r` import with `from rethinkdb import r`.
223216

224217
## Run tests
225218
In the `Makefile` you can find three different test commands: `test-unit`, `test-integration` and `test-remote`. As RethinkDB has dropped the support of Windows, we would like to ensure that those of us who are using Windows for development can still contribute. Because of this, we support running integration tests against Digital Ocean Droplets as well.

tests/helpers.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import os
2-
from rethinkdb import RethinkDB
2+
from rethinkdb import r
33

44

55
INTEGRATION_TEST_DB = 'integration_test'
66

77

88
class IntegrationTestCaseBase(object):
9-
r = RethinkDB()
109
conn = None
1110

1211
def connect(self):
13-
self.conn = self.r.connect(
14-
host=self.rethinkdb_host
12+
self.conn = r.connect(
13+
host=rethinkdb_host
1514
)
1615

1716
def setup_method(self):
18-
self.rethinkdb_host=os.getenv('RETHINKDB_HOST')
17+
rethinkdb_host=os.getenv('RETHINKDB_HOST')
1918

2019
self.connect()
2120

22-
if INTEGRATION_TEST_DB not in self.r.db_list().run(self.conn):
23-
self.r.db_create(INTEGRATION_TEST_DB).run(self.conn)
21+
if INTEGRATION_TEST_DB not in r.db_list().run(self.conn):
22+
r.db_create(INTEGRATION_TEST_DB).run(self.conn)
2423

2524
self.conn.use(INTEGRATION_TEST_DB)
2625

2726
def teardown_method(self):
28-
self.r.db_drop(INTEGRATION_TEST_DB).run(self.conn)
27+
r.db_drop(INTEGRATION_TEST_DB).run(self.conn)
2928
self.conn.close()

tests/integration/test_asyncio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from collections import namedtuple
44
import pytest
5-
from rethinkdb import RethinkDB
5+
from rethinkdb import r
66
from rethinkdb.errors import ReqlRuntimeError
77

88
Helper = namedtuple("Helper", "r connection")
@@ -20,7 +20,6 @@ async def test_flow():
2020
not supported in 3.5.
2121
"""
2222

23-
r = RethinkDB()
2423
r.set_loop_type("asyncio")
2524

2625
connection = await r.connect(os.getenv("REBIRTHDB_HOST"))

tests/integration/test_asyncio_coroutine.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from asyncio import coroutine
44
import pytest
5-
from rethinkdb import RethinkDB
5+
from rethinkdb import r
66
from rethinkdb.errors import ReqlRuntimeError
77

88

@@ -15,7 +15,6 @@
1515
@coroutine
1616
def test_flow_couroutine_paradigm():
1717

18-
r = RethinkDB()
1918
r.set_loop_type("asyncio")
2019

2120
connection = yield from r.connect(os.getenv("REBIRTHDB_HOST"))

tests/integration/test_tornado.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from collections import namedtuple
44
import pytest
5-
from rethinkdb import RethinkDB
5+
from rethinkdb import r
66
from rethinkdb.errors import ReqlRuntimeError
77

88
Helper = namedtuple("Helper", "r connection")
@@ -18,7 +18,6 @@ async def test_tornado_connect(io_loop):
1818
not supported in 3.5.
1919
"""
2020

21-
r = RethinkDB()
2221
r.set_loop_type("tornado")
2322

2423
connection = await r.connect(os.getenv("REBIRTHDB_HOST"))

tests/integration/test_trio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
from async_generator import async_generator, yield_
66
import pytest
7-
from rethinkdb import RethinkDB
7+
from rethinkdb import r
88
from rethinkdb.errors import ReqlRuntimeError
99
import trio
1010

1111

1212
INTEGRATION_TEST_DB = 'integration_test'
13-
r = RethinkDB()
1413
r.set_loop_type('trio')
1514

1615

0 commit comments

Comments
 (0)