Skip to content

Commit

Permalink
Final Release Candidate version
Browse files Browse the repository at this point in the history
Add response and apply_vendor utils function.
Add init docstring to every class.
  • Loading branch information
MatteoGuadrini committed Feb 19, 2022
2 parents db4ae0f + e8559a8 commit b00ba97
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Show an information of a specific database

`Session` objects should respond to the following methods.

> ATTENTION: Session object it will come instantiated if the Connection object contains a `connection` value. `database` value is optional.
> ATTENTION: Session object it will come instantiated if the `connection` value contains a compliant API Connection object. `database` value is optional.
#### Session attributes

Expand Down
2 changes: 1 addition & 1 deletion __info__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

"""Information variable used by modules on this package."""

__version__ = '0.0.9'
__version__ = '0.0.9.rc'
__author__ = 'Matteo Guadrini'
__email__ = 'matteo.guadrini@hotmail.it'
__homepage__ = 'https://github.com/MatteoGuadrini/nosqlapi'
4 changes: 4 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ The ``Session`` object represents the *session* to a database. With this object
Session attributes
------------------

.. py:attribute:: connection
``Connection`` or other compliant object of server in current session

.. py:attribute:: description
This read-only attribute contains the *session* parameters (can be ``str``, ``tuple`` or ``dict``).
Expand Down
44 changes: 22 additions & 22 deletions docs/source/interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Globals

``api_level`` is a global variable to check compatibility with the names defined in this document. Currently the level is *1.0*.

``CONNECTION`` is a global variable where to save a ``Connection`` object.
``CONNECTION`` is a global variable where to save a global ``Connection`` object.

``SESSION`` is a global variable where to save a ``Session`` object.
``SESSION`` is a global variable where to save a global ``Session`` object.

Exceptions
**********
Expand All @@ -47,26 +47,26 @@ All defined exceptions derive from the general exception ``Error`` based on ``Ex
>>> raise Error("Don't use this, but its subclasses!")
======================= ============= ===========
Name Base Description
======================= ============= ===========
Error Exception Exception that is the base class of all other error exceptions. Use only for checks.
UnknownError Error Exception raised when an unspecified error occurred.
ConnectError Error Exception raised for errors that are related to the database connection.
CloseError Error Exception raised for errors that are related to the database close connection.
DatabaseError Error Exception raised for errors that are related to the database, generally.
DatabaseCreationError DatabaseError Exception raised for errors that are related to the creation of a database.
DatabaseDeletionError DatabaseError Exception raised for errors that are related to the deletion of a database.
SessionError Error Exception raised for errors that are related to the session, generally.
SessionInsertingError SessionError Exception raised for errors that are related to the inserting data on a database session.
SessionUpdatingError SessionError Exception raised for errors that are related to the updating data on a database session.
SessionDeletingError SessionError Exception raised for errors that are related to the deletion data on a database session.
SessionClosingError SessionError Exception raised for errors that are related to the closing database session.
SessionFindingError SessionError Exception raised for errors that are related to the finding data on a database session.
SessionACLError SessionError Exception raised for errors that are related to the grant or revoke permission on a database.
SelectorError Error Exception raised for errors that are related to the selectors in general.
SelectorAttributeError SelectorError Exception raised for errors that are related to the selectors attribute.
======================= ============= ===========
========================== ================= ===========
Name Base Description
========================== ================= ===========
``Error`` ``Exception`` Exception that is the base class of all other error exceptions. Use only for checks.
``UnknownError`` ``Error`` Exception raised when an unspecified error occurred.
``ConnectError`` ``Error`` Exception raised for errors that are related to the database connection.
``CloseError`` ``Error`` Exception raised for errors that are related to the database close connection.
``DatabaseError`` ``Error`` Exception raised for errors that are related to the database, generally.
``DatabaseCreationError`` ``DatabaseError`` Exception raised for errors that are related to the creation of a database.
``DatabaseDeletionError`` ``DatabaseError`` Exception raised for errors that are related to the deletion of a database.
``SessionError`` ``Error`` Exception raised for errors that are related to the session, generally.
``SessionInsertingError`` ``SessionError`` Exception raised for errors that are related to the inserting data on a database session.
``SessionUpdatingError`` ``SessionError`` Exception raised for errors that are related to the updating data on a database session.
``SessionDeletingError`` ``SessionError`` Exception raised for errors that are related to the deletion data on a database session.
``SessionClosingError`` ``SessionError`` Exception raised for errors that are related to the closing database session.
``SessionFindingError`` ``SessionError`` Exception raised for errors that are related to the finding data on a database session.
``SessionACLError`` ``SessionError`` Exception raised for errors that are related to the grant or revoke permission on a database.
``SelectorError`` ``Error`` Exception raised for errors that are related to the selectors in general.
``SelectorAttributeError`` ``SelectorError`` Exception raised for errors that are related to the selectors attribute.
========================== ================= ===========

The tree of exceptions:

Expand Down
15 changes: 14 additions & 1 deletion docs/source/nosqlapi_common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,17 @@ The ``cursor_response`` function allows you to convert a Response object into a
resp = connection.databases()
print(resp) # Response object
print(cursor_response(resp)) # [('db1', 'db2')]
print(cursor_response(resp)) # [('db1', 'db2')]
The ``apply_vendor`` function allows you to rename representation object from *nosqlapi* to other name

.. code-block:: pycon
>>> import nosqlapi
>>> class Response(nosqlapi.Response): ...
>>> resp = Response('some data')
>>> resp
<nosqlapi Response object>
>>> nosqlapi.apply_vendor('pymongo')
>>> resp
<pymongo Response object>
7 changes: 6 additions & 1 deletion docs/source/package.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
nosqlapi package
================

The package nosqlapi is a collection of interface and utility class and functions for build your own NOSQL python package.
The package nosqlapi is a collection of interface, utility class and functions for build your own NOSQL python package.

This library offers API-based interfaces described above, helping to build a more coherent and integrated python library
for a NOSQL database, with names similar to another library using the same interfaces.

The benefit of using ``nosqlapi`` is to standardize the names and syntax for the end user, so as to make as few changes as possible to your software.

Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion nosqlapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from nosqlapi.common import (Int, Inet, Ascii, Time, SmallInt, Decimal, Timestamp, Counter, Date, Text, Blob,
Boolean, Double, Uuid, Duration, Float, Varint, Varchar)
from nosqlapi.common.exception import *
from nosqlapi.common.utils import api, Manager, global_session, cursor_response
from nosqlapi.common.utils import api, Manager, global_session, cursor_response, apply_vendor, response
from nosqlapi.docdb import DocConnection, DocSelector, DocSession, DocResponse, DocBatch
from nosqlapi.graphdb import GraphConnection, GraphSelector, GraphSession, GraphResponse, GraphBatch
from nosqlapi.kvdb import KVConnection, KVSelector, KVSession, KVResponse, KVBatch
Expand Down
6 changes: 5 additions & 1 deletion nosqlapi/columndb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def filtering(self):

@filtering.setter
def filtering(self, value: bool):
"""Filter data"""
"""Set filtering data
:param value: Boolean value
:return: None
"""
value_ = bool(value)
if not isinstance(value_, bool):
raise ValueError(f'{value_} must be bool')
Expand Down
33 changes: 24 additions & 9 deletions nosqlapi/columndb/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class Table:
"""Represents table as container of columns"""

def __init__(self, name, *columns, **options):
"""Table object
:param name: Name of table
:param columns: Columns
:param options: Options
"""
self._name = name
self._columns = [column for column in columns]
self._options = options
Expand Down Expand Up @@ -96,31 +102,31 @@ def primary_key(self, value: str):
def add_column(self, *columns):
"""Adding one or more column object to table
:param columns: column objects
:param columns: Column objects
:return: None
"""
self._columns.extend(columns)

def delete_column(self, index=-1):
"""Deleting one column to table
:param index: number of index
:param index: Number of index
:return: None
"""
self._columns.pop(index)

def set_option(self, option):
"""Update options
:param option: dict options
:param option: Dict options
:return: None
"""
self._options.update(option)

def add_row(self, *rows):
"""Add one or more row into columns
:param rows: tuple of objects
:param rows: Tuple of objects
:return: None
"""
for row in rows:
Expand All @@ -133,7 +139,7 @@ def add_row(self, *rows):
def delete_row(self, row=-1):
"""Delete one row into columns
:param row: index of row
:param row: Index of row
:return: None
"""
for column in self.columns:
Expand All @@ -149,15 +155,15 @@ def get_rows(self):
def add_index(self, index):
"""Adding index to index property
:param index: name or Index object
:param index: Name or Index object
:return: None
"""
self._index.append(index)

def delete_index(self, index=-1):
"""Deleting index to index property
:param index: name or Index object
:param index: Name or Index object
:return: None
"""
self._index.pop(index)
Expand Down Expand Up @@ -187,6 +193,15 @@ class Column:
"""Represents column as container of values"""

def __init__(self, name, of_type=None, max_len=None, auto_increment=False, primary_key=False, default=None):
"""Column object
:param name: Name of column
:param of_type: Type of column
:param max_len: Max length of column
:param auto_increment: Boolean value (default False)
:param primary_key: Set this column like a primary key
:param default: Default function for generate data
"""
self.name = name
self._of_type = of_type if of_type is not None else object
self.max_len = max_len
Expand Down Expand Up @@ -233,7 +248,7 @@ def append(self, data=None):
"""Appending data to column.
If auto_increment is True, the value is incremented automatically.
:param data: any type of data
:param data: Any type of data
:return: None
"""
if self.max_len and len(self._data) >= self.max_len:
Expand All @@ -257,7 +272,7 @@ def append(self, data=None):
def pop(self, index=-1):
"""Deleting value
:param index: number of index
:param index: Number of index
:return: None
"""
self._data.pop(index)
Expand Down
2 changes: 1 addition & 1 deletion nosqlapi/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
SelectorAttributeError)
from nosqlapi.common.orm import (Null, List, Map, Int, Inet, Ascii, Time, SmallInt, Decimal, Timestamp, Counter,
Date, Text, Blob, Boolean, Double, Uuid, Duration, Float, Varint, Varchar, Array)
from nosqlapi.common.utils import api, Manager, global_session, cursor_response
from nosqlapi.common.utils import api, Manager, global_session, cursor_response, apply_vendor, response
44 changes: 44 additions & 0 deletions nosqlapi/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ def __init__(self,
ssl_verify_cert=None,
max_allowed_packet=None
):
"""Instantiate Connection object
:param host: Name of host that contains database
:param user: Username for connect to the host
:param password: Password for connect to the host
:param database: Name of database
:param port: Tcp port
:param bind_address: Hostname or an IP address for multiple network interfaces
:param read_timeout: Timeout for reading from the connection in seconds
:param write_timeout: Timeout for writing from the connection in seconds
:param ssl: Ssl connection established
:param ssl_ca: Ssl CA file specified
:param ssl_cert: Ssl certificate file specified
:param tls: Tls connection established
:param ssl_key: Ssl private key file specified
:param ssl_verify_cert: Verify certificate file
:param max_allowed_packet: Max size of packet sent to server in bytes
"""
self.host = host
self.user = user
self.password = password
Expand Down Expand Up @@ -160,6 +178,15 @@ class Selector(ABC):
"""Selector abstract class"""

def __init__(self, selector=None, fields=None, partition=None, condition=None, order=None, limit=None):
"""Instantiate Selector object
:param selector: Selector part of the query string
:param fields: Return fields
:param partition: Partition or collection of data
:param condition: Condition of query
:param order: Order by specific selector
:param limit: Limit result
"""
self.selector = selector
self.fields = fields
self.partition = partition
Expand Down Expand Up @@ -251,6 +278,11 @@ class Session(ABC):
"""Server session abstract class"""

def __init__(self, connection, database=None):
"""Instantiate Session object
:param connection: Connection object or other object to serve connection
:param database: database name
"""
self._item_count = 0
self._description = ()
self._database = database
Expand Down Expand Up @@ -444,6 +476,13 @@ class Response(ABC):
__slots__ = ('_data', '_code', '_header', '_error')

def __init__(self, data, code=None, header=None, error=None):
"""Instantiate Response object
:param data: Data from operation
:param code: Exit code of operation
:param header: Header of operation
:param error: Error string or Exception class
"""
self._data = data
self._code = code
self._header = header
Expand Down Expand Up @@ -507,6 +546,11 @@ class Batch(ABC):
"""Batch abstract class"""

def __init__(self, batch, session=None):
"""Instantiate Batch object
:param batch: List of commands
:param session: Session object or other compliant object
"""
self._session = session
self._batch = batch

Expand Down
Loading

0 comments on commit b00ba97

Please sign in to comment.