16
16
# Copyright 2010-2016 RethinkDB, all rights reserved.
17
17
18
18
import warnings
19
+ from types import SimpleNamespace
20
+
21
+ from rethinkdb import net
22
+ # pylint: disable=redefined-builtin
23
+ from rethinkdb .query import (
24
+ add , and_ , april , args , asc , august , avg , binary , bit_and , bit_not , bit_or ,
25
+ bit_sal , bit_sar , bit_xor , branch , ceil , circle , contains , count , db ,
26
+ db_create , db_drop , db_list , december , desc , distance , distinct , div , do ,
27
+ epoch_time , eq , error , february , floor , format , friday , ge , geojson , grant ,
28
+ group , gt , http , info , intersects , iso8601 , january , json , july , june , le ,
29
+ line , literal , lt , make_timezone , map , march , max , maxval , may , min , minval ,
30
+ mod , monday , mul , ne , not_ , november , now , object , october , or_ , point ,
31
+ polygon , random , range , reduce , round , row , saturday , september , sub , sum ,
32
+ sunday , table , table_create , table_drop , table_list , thursday , time , tuesday ,
33
+ type_of , union , uuid , wednesday , js
34
+ )
35
+ # pylint: enable=redefined-builtin
19
36
20
- from rethinkdb import errors # , version
21
-
22
- __all__ = ["r" , "RethinkDB" ]
23
37
__version__ = "2.5.0"
24
38
25
-
26
- class RethinkDB :
39
+ # Create the r namespace object containing all query functions
40
+ r = SimpleNamespace ()
41
+
42
+ query_functions = {
43
+ 'add' : add , 'and_' : and_ , 'april' : april , 'args' : args , 'asc' : asc ,
44
+ 'august' : august , 'avg' : avg , 'binary' : binary , 'bit_and' : bit_and ,
45
+ 'bit_not' : bit_not , 'bit_or' : bit_or , 'bit_sal' : bit_sal , 'bit_sar' : bit_sar ,
46
+ 'bit_xor' : bit_xor , 'branch' : branch , 'ceil' : ceil , 'circle' : circle ,
47
+ 'contains' : contains , 'count' : count , 'db' : db , 'db_create' : db_create ,
48
+ 'db_drop' : db_drop , 'db_list' : db_list , 'december' : december , 'desc' : desc ,
49
+ 'distance' : distance , 'distinct' : distinct , 'div' : div , 'do' : do ,
50
+ 'epoch_time' : epoch_time , 'eq' : eq , 'error' : error , 'february' : february ,
51
+ 'floor' : floor , 'format' : format , 'friday' : friday , 'ge' : ge , 'geojson' : geojson ,
52
+ 'grant' : grant , 'group' : group , 'gt' : gt , 'http' : http , 'info' : info ,
53
+ 'intersects' : intersects , 'iso8601' : iso8601 , 'january' : january , 'json' : json ,
54
+ 'july' : july , 'june' : june , 'le' : le , 'line' : line , 'literal' : literal ,
55
+ 'lt' : lt , 'make_timezone' : make_timezone , 'map' : map , 'march' : march ,
56
+ 'max' : max , 'maxval' : maxval , 'may' : may , 'min' : min , 'minval' : minval ,
57
+ 'mod' : mod , 'monday' : monday , 'mul' : mul , 'ne' : ne , 'not_' : not_ ,
58
+ 'november' : november , 'now' : now , 'object' : object , 'october' : october ,
59
+ 'or_' : or_ , 'point' : point , 'polygon' : polygon , 'random' : random ,
60
+ 'range' : range , 'reduce' : reduce , 'round' : round , 'row' : row ,
61
+ 'saturday' : saturday , 'september' : september , 'sub' : sub , 'sum' : sum ,
62
+ 'sunday' : sunday , 'table' : table , 'table_create' : table_create ,
63
+ 'table_drop' : table_drop , 'table_list' : table_list , 'thursday' : thursday ,
64
+ 'time' : time , 'tuesday' : tuesday , 'type_of' : type_of , 'union' : union ,
65
+ 'uuid' : uuid , 'wednesday' : wednesday , 'js' : js
66
+ }
67
+
68
+ for name , func in query_functions .items ():
69
+ setattr (r , name , func )
70
+
71
+
72
+ class Client :
27
73
"""
28
- RethinkDB serves as an entrypoint for queries .
74
+ Client is a wrapper around RethinkDB connection handling .
29
75
30
76
It constructs the connection handlers and event loops, re-exports internal modules for easier
31
77
use, and sets the event loop.
@@ -34,23 +80,11 @@ class RethinkDB:
34
80
def __init__ (self ):
35
81
super ().__init__ ()
36
82
37
- # pylint: disable=import-outside-toplevel
38
- from rethinkdb import ast , net , query
39
-
40
- # Re-export internal modules for backward compatibility
41
- self .ast = ast
42
- self .errors = errors
43
83
self .net = net
44
- self .query = query
45
84
46
85
net .Connection ._r = self
47
86
self .connection_type = None
48
87
49
- # Dynamically assign every re-exported internal module's function to self
50
- for module in (self .net , self .query , self .ast , self .errors ):
51
- for function_name in module .__all__ :
52
- setattr (self , function_name , getattr (module , function_name ))
53
-
54
88
# Ensure the `make_connection` function is not overridden accidentally
55
89
self .make_connection = self .net .make_connection
56
90
self .set_loop_type (None )
@@ -83,12 +117,9 @@ def set_loop_type(self, library=None) -> None:
83
117
if library is None or self .connection_type is None :
84
118
self .connection_type = self .net .DefaultConnection
85
119
86
- def connect (self , * args , ** kwargs ):
120
+ def connect (self , * connect_args , ** kwargs ):
87
121
"""
88
122
Make a connection to the database.
89
123
"""
90
124
91
- return self .make_connection (self .connection_type , * args , ** kwargs )
92
-
93
-
94
- r = RethinkDB ()
125
+ return self .make_connection (self .connection_type , * connect_args , ** kwargs )
0 commit comments