Skip to content

Commit 74d7ea5

Browse files
committed
Added docstrings
1 parent 40b949d commit 74d7ea5

File tree

6 files changed

+562
-18
lines changed

6 files changed

+562
-18
lines changed

cpyint

lib/mysqlx/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,34 @@
3131
from .result import (ColumnMetaData, Row, Result, BufferingResult, RowResult,
3232
SqlResult)
3333
from .statement import (Statement, FilterableStatement, SqlStatement,
34-
AddStatement, RemoveStatement, DeleteStatement,
35-
CreateCollectionIndexStatement,
34+
AddStatement, RemoveStatement, ModifyStatement,
35+
SelectStatement, InsertStatement, DeleteStatement,
36+
UpdateStatement, CreateCollectionIndexStatement,
3637
DropCollectionIndexStatement)
3738
from .dbdoc import DbDoc
3839

3940

4041
def get_session(settings):
42+
"""Creates a XSession instance using the provided connection data.
43+
44+
Args:
45+
settings (dict): Connection data used to connect to the database.
46+
47+
Returns:
48+
mysqlx.XSession: XSession object.
49+
"""
4150
return XSession(settings)
4251

4352

4453
def get_node_session(settings):
54+
"""Creates a NodeSession instance using the provided connection data.
55+
56+
Args:
57+
settings (dict): Connection data used to connect to the database.
58+
59+
Returns:
60+
mysqlx.XSession: XSession object.
61+
"""
4562
return NodeSession(settings)
4663

4764

@@ -63,6 +80,7 @@ def get_node_session(settings):
6380

6481
# mysqlx.statement
6582
"DbDoc", "Statement", "FilterableStatement", "SqlStatement",
66-
"AddStatement", "RemoveStatement", "DeleteStatement",
83+
"AddStatement", "RemoveStatement", "ModifyStatement", "SelectStatement",
84+
"InsertStatement", "DeleteStatement", "UpdateStatement",
6785
"CreateCollectionIndexStatement", "DropCollectionIndexStatement",
6886
]

lib/mysqlx/connection.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,41 +126,109 @@ def get_row_result(self, cmd, *args):
126126

127127

128128
class BaseSession(object):
129+
"""Base functionality for Session classes through the X Protocol.
130+
131+
This class encloses the core functionality to be made available on both
132+
the XSession and NodeSession classes, such functionality includes:
133+
134+
- Accessing available schemas.
135+
- Schema management operations.
136+
- Enabling/disabling warning generation.
137+
- Retrieval of connection information.
138+
139+
Args:
140+
settings (dict): Connection data used to connect to the database.
141+
"""
129142
def __init__(self, settings):
130143
self._settings = settings
131144
self._connection = Connection(self._settings)
132145
self._connection.connect()
133146

134147
def get_schema(self, name):
148+
"""Retrieves a Schema object from the current session by it's name.
149+
150+
Args:
151+
name (string): The name of the Schema object to be retrieved.
152+
153+
Returns:
154+
mysqlx.Schema: The Schema object with the given name.
155+
"""
135156
return Schema(self, name)
136157

137158
def drop_schema(self, name):
159+
"""Drops the schema with the specified name.
160+
161+
Args:
162+
name (string): The name of the Schema object to be retrieved.
163+
"""
138164
self._connection.execute_nonquery(
139165
"sql", _DROP_DATABASE_QUERY.format(name), True)
140166

141167
def create_schema(self, name):
168+
"""Creates a schema on the database and returns the corresponding
169+
object.
170+
171+
Args:
172+
name (string): A string value indicating the schema name.
173+
"""
142174
self._connection.execute_nonquery(
143175
"sql", _CREATE_DATABASE_QUERY.format(name), True)
144176
return Schema(self, name)
145177

146178
def start_transaction(self):
179+
"""Starts a transaction context on the server.
180+
"""
147181
self._connection.execute_nonquery("START TRANSACTION")
148182

149183
def commit(self):
184+
"""Commits all the operations executed after a call to
185+
startTransaction().
186+
"""
150187
self._connection.execute_nonquery("COMMIT")
151188

152-
def roillback(self):
189+
def rollback(self):
190+
"""Discards all the operations executed after a call to
191+
startTransaction().
192+
"""
153193
self._connection.execute_nonquery("ROLLBACK")
154194

155195

156196
class XSession(BaseSession):
197+
"""Enables interaction with an X Protocol enabled MySQL Product.
198+
199+
The functionality includes:
200+
201+
- Accessing available schemas.
202+
- Schema management operations.
203+
- Enabling/disabling warning generation.
204+
- Retrieval of connection information.
205+
206+
Args:
207+
settings (dict): Connection data used to connect to the database.
208+
"""
157209
def __init__(self, settings):
158210
super(XSession, self).__init__(settings)
159211

160212

161213
class NodeSession(BaseSession):
214+
"""Enables interaction with an X Protocol enabled MySQL Server.
215+
216+
The functionality includes:
217+
218+
- Accessing available schemas.
219+
- Schema management operations.
220+
- Enabling/disabling warning generation.
221+
- Retrieval of connection information.
222+
- Includes SQL Execution.
223+
224+
Args:
225+
settings (dict): Connection data used to connect to the database.
226+
"""
162227
def __init__(self, settings):
163228
super(NodeSession, self).__init__(settings)
164229

165230
def sql(self, sql):
231+
"""Creates a :class:`mysqlx.SqlStatement` object to allow running the
232+
SQL statement on the target MySQL Server.
233+
"""
166234
return SqlStatement(self._connection, sql)

0 commit comments

Comments
 (0)