-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented cursor and documentation
- Loading branch information
Christian Bader
committed
Sep 3, 2013
1 parent
eb8c4d6
commit b8b1258
Showing
15 changed files
with
525 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ parts/ | |
develop-eggs/ | ||
.installed.cfg | ||
crate.egg-info | ||
dist | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
=================== | ||
Crate Python Client | ||
=================== | ||
|
||
.. image:: http://www.crate-technology.com/assets/img/logo.png | ||
:width: 155px | ||
:height: 45px | ||
:alt: Crate-Technology | ||
:target: http://www.crate-technology.com/ | ||
|
||
Overview | ||
======== | ||
|
||
The crate client distribution is a nativ python | ||
client offering tools for interacting with the | ||
crate database. | ||
crate server. | ||
|
||
Installation | ||
============ | ||
|
||
Installing via pip | ||
------------------ | ||
|
||
To install the crate client via `pip | ||
<https://pypi.python.org/pypi/pip>`_ | ||
use the following command:: | ||
|
||
$ pip install crate | ||
|
||
To update use:: | ||
$ pip install -U crate | ||
|
||
Installing via easy_install | ||
--------------------------- | ||
|
||
If you prefer easy_install which is provided by | ||
`setuptools <https://pypi.python.org/pypi/setuptools/1.1>`_ | ||
use the following command:: | ||
|
||
$ easy_install crate | ||
|
||
For details about usage, please refer to the | ||
documentation found under the ``docs`` directory. | ||
To update use:: | ||
|
||
Developer specific documentation can be found | ||
in the ``DEVELOP.rst`` document. | ||
$ easy_install -U crate |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
apilevel = "2.0" | ||
|
||
#TODO: correct values after finshed implementation | ||
threadsafety = 1 | ||
paramstyle = "qmark" | ||
|
||
from .connection import connect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
from .cursor import Cursor | ||
|
||
|
||
class Connection(object): | ||
|
||
def __init__(self, servers, client): | ||
self.client = client | ||
|
||
def cursor(self): | ||
return Cursor(self) | ||
|
||
def close(self): | ||
pass | ||
|
||
def commit(self): | ||
pass | ||
|
||
def _connect(self, hosts): | ||
pass | ||
|
||
def _endpoint(self): | ||
pass | ||
|
||
|
||
def connect(servers=None, crate_client=None): | ||
return Connection(servers, crate_client) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
|
||
class Client(object): | ||
|
||
def __init__(self): | ||
self.response = {} | ||
|
||
def sql(self, stmt=None): | ||
return self.response | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from .exceptions import ProgrammingError | ||
|
||
|
||
class Cursor(): | ||
|
||
def __init__(self, connection): | ||
self.arraysize = 1 | ||
self.connection = connection | ||
self._closed = True | ||
|
||
def execute(self, sql): | ||
self._result = self.connection.client.sql(sql) | ||
self.rows = iter(self._result["rows"]) | ||
self._closed = False | ||
|
||
def executemany(self, sql): | ||
raise NotImplementedError | ||
|
||
def fetchone(self): | ||
return self.next() | ||
|
||
def next(self): | ||
try: | ||
return self._next() | ||
except StopIteration: | ||
return None | ||
|
||
def fetchmany(self, count=None): | ||
if count is None: | ||
count = self.arraysize | ||
if count == 0: | ||
return self.fetchall() | ||
result = [] | ||
for i in range(count): | ||
try: | ||
result.append(self._next()) | ||
except StopIteration: | ||
pass | ||
return result | ||
|
||
def fetchall(self): | ||
result = [] | ||
iterate = True | ||
while iterate: | ||
try: | ||
result.append(self._next()) | ||
except StopIteration: | ||
iterate = False | ||
return result | ||
|
||
def close(self): | ||
self._closed = True | ||
self._result = None | ||
|
||
def commit(self): | ||
""" | ||
Transactions not supported, nothing to do here. | ||
""" | ||
pass | ||
|
||
def setinputsizes(self, sizes): | ||
""" | ||
This can be used before a call to .execute*() to predefine memory areas | ||
for the operation's parameters. | ||
sizes is specified as a sequence — one item for each input parameter. | ||
The item should be a Type Object that corresponds to the input that will be used, | ||
or it should be an integer specifying the maximum length of a string parameter. | ||
If the item is None, then no predefined memory area will be reserved for | ||
that column (this is useful to avoid predefined areas for large inputs). | ||
This method would be used before the .execute*() method is invoked. | ||
Implementations are free to have this method do nothing and users are | ||
free to not use it. | ||
""" | ||
pass | ||
|
||
def setoutputsize(self, size, column=None): | ||
""" | ||
Set a column buffer size for fetches of large columns (e.g. LONGs, BLOBs, etc.). | ||
The column is specified as an index into the result sequence. | ||
Not specifying the column will set the default size for all large columns in the cursor. | ||
This method would be used before the .execute*() method is invoked. | ||
Implementations are free to have this method do nothing and users are free to not use | ||
it. | ||
""" | ||
pass | ||
|
||
@property | ||
def rowcount(self): | ||
if not self._closed: | ||
return len(self._result["rows"]) | ||
return -1 | ||
|
||
def _next(self): | ||
if not self._closed: | ||
return self.rows.next() | ||
else: | ||
raise ProgrammingError | ||
|
||
@property | ||
def description(self): | ||
if self._closed: | ||
return | ||
|
||
description = [] | ||
for col in self._result["cols"]: | ||
description.append((col, | ||
None, | ||
None, | ||
None, | ||
None, | ||
None, | ||
None)) | ||
return tuple(description) |
Oops, something went wrong.