Skip to content

Commit

Permalink
First stable release 1.0.0
Browse files Browse the repository at this point in the history
Add production test. Complete classifiers.
Add column, document, node and properties function decorator.
  • Loading branch information
MatteoGuadrini committed Mar 31, 2022
2 parents b00ba97 + b9fbd26 commit b79ed94
Show file tree
Hide file tree
Showing 43 changed files with 1,088 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ jobs:
executor: python/default
steps:
- checkout
- run: pip install pytest
- run: sudo python setup.py install
- run: sudo chmod -R 777 /tmp
- run: python -m unittest discover tests
- run: pytest tests/test_real_production.py


workflows:
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ _nosqlapi_ is a library for building standard NOSQL python libraries.

Full documentation: [Read the docs](https://nosqlapi.rtfd.io/)

> ATTENTION: This is **WIP** in _RC_ version
## Introduction

This library is defined to encourage similarity between Python modules used to access NOSQL databases.
Expand Down Expand Up @@ -350,6 +348,12 @@ This read-only attribute that throw an `Exception` if it has been set.

This read-only attribute represents a dictionary transformation of Response object.

#### Response methods

`.throw()`

Raise exception stored in _error_ property.

### Batch Objects

`Batch` objects should respond to the following methods.
Expand Down Expand Up @@ -423,7 +427,7 @@ tests/test_kvdb.py:class MyDBSession(nosqlapi.kvdb.KVSession):
### Key-Value database
A _key–value_ database, or key–value store, is a data storage paradigm designed for storing, retrieving, and managing associative arrays,
and a data structure more commonly known today as a dictionary or hash table. Dictionaries contain a collection of objects, or records,
which in turn have many different fields within them, each containing data. These records are stored and retrieved using a key that
which in turn have many fields within them, each containing data. These records are stored and retrieved using a key that
uniquely identifies the record, and is used to find the data within the database.

```python
Expand Down
4 changes: 2 additions & 2 deletions __info__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# __info__ -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -22,7 +22,7 @@

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

__version__ = '0.0.9.rc'
__version__ = '1.0.0'
__author__ = 'Matteo Guadrini'
__email__ = 'matteo.guadrini@hotmail.it'
__homepage__ = 'https://github.com/MatteoGuadrini/nosqlapi'
7 changes: 7 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ This read-only attribute represents a ``str`` or ``Exception`` object error of a
This read-only attribute represents a ``dict`` transformation of ``Response`` object.

Response methods
----------------

.. function:: throw()

Raise exception stored in ``error`` property.

Batch Objects
*************

Expand Down
13 changes: 12 additions & 1 deletion docs/source/nosqlapi_column.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ These objects represent the respective *column* in databases.
name.append('Matteo Guadrini')
# Make table
table = nosqlapi.columndb.Table('peoples', id, name)
# Create Column object from column decorator
@nosqlapi.columndb.column
def salary(file, limit=5000):
return [line
for line in open(file, 'rt').readlines()
if int(line) < 5000]
# Add column to table
table.add_column(id, name, salary('/tmp/salary.log'))
# Add table to keyspace
keyspace.append(table)
# Create database and insert data
mycolumndb.conn.create_database(keyspace)
mycolumndb.sess.insert(keyspace.store[0])
mycolumndb.sess.create_table(table)
# Insert new data
mycolumndb.sess.insert('people', (None, 'Arthur Dent', 4000))
8 changes: 7 additions & 1 deletion docs/source/nosqlapi_doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ These objects represent the respective *document* in databases.
# Add documents to database
db.append(doc1)
db.append(doc2)
# Create Document object from document decorator
@nosqlapi.docdb.document
def user(name, age, salary):
return {'name': name, 'age': age, 'salary': salary}
# Create database with docs
mydocdb.conn.create_database(db)
mydocdb.conn.create_database(db)
# Add more doc
mydocdb.sess.insert(user('Matteo Guadrini', 36, 25000))
15 changes: 14 additions & 1 deletion docs/source/nosqlapi_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,18 @@ These objects represent the respective *graph* in databases.
db.append(node1)
db.append(node2)
# Create Node object from node decorator
@nosqlapi.graphdb.node
def Person(name, age):
return {'name': name, 'age': age}
# Create Property object from prop decorator
@nosqlapi.graphdb.prop
def user(name, age):
return {'name': name, 'age': age}
# Create database with nodes
mydocdb.conn.create_database(db)
mydocdb.conn.create_database(db)
# Add other nodes
mydocdb.sess.insert(label='Person', properties=user('Matteo Guadrini', 36))
mydocdb.sess.insert(Person('Julio Artes', 29)) # Labels = ['Person']
2 changes: 1 addition & 1 deletion nosqlapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# __init__.py -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions nosqlapi/columndb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# __init__.py -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -23,4 +23,4 @@
"""Package column NOSQL database."""

from nosqlapi.columndb.client import ColumnConnection, ColumnSelector, ColumnSession, ColumnResponse, ColumnBatch
from nosqlapi.columndb.orm import Keyspace, Table, Column, Index
from nosqlapi.columndb.orm import Keyspace, Table, Column, Index, column
10 changes: 5 additions & 5 deletions nosqlapi/columndb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# client -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,9 +49,9 @@ class ColumnSelector(Selector, ABC):

"""Column NOSQL database Selector class"""

def __init__(self):
super().__init__()
self.filtering = False
def __init__(self, *args, **kwargs):
Selector.__init__(self, *args, **kwargs)
self._filtering = False

@abstractmethod
def all(self):
Expand Down Expand Up @@ -79,7 +79,7 @@ def filtering(self):
return self._filtering

@filtering.setter
def filtering(self, value: bool):
def filtering(self, value):
"""Set filtering data
:param value: Boolean value
Expand Down
6 changes: 3 additions & 3 deletions nosqlapi/columndb/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# client stub -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -32,8 +32,8 @@ class ColumnConnection(KVConnection): ...
class ColumnSelector(Selector):
filtering: Any

def __init__(self) -> None:
self.filtering: bool = False
def __init__(self, *args, **kwargs):
self._filtering: bool = False

def all(self) -> Union[str, list, tuple]: ...

Expand Down
59 changes: 44 additions & 15 deletions nosqlapi/columndb/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# orm -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -24,14 +24,15 @@

# region Imports
from collections import namedtuple
from functools import wraps

from nosqlapi.common import Counter
from nosqlapi.kvdb.orm import Keyspace as Ks

# endregion

# region global variable
__all__ = ['Keyspace', 'Table', 'Column', 'Index']
__all__ = ['Keyspace', 'Table', 'Column', 'Index', 'column']


# endregion
Expand All @@ -40,6 +41,7 @@
class Keyspace(Ks):

"""Represents keyspace like database"""

pass


Expand All @@ -55,7 +57,7 @@ def __init__(self, name, *columns, **options):
:param options: Options
"""
self._name = name
self._columns = [column for column in columns]
self._columns = [col for col in columns]
self._options = options
self._index = []

Expand Down Expand Up @@ -86,18 +88,18 @@ def index(self):

@property
def header(self):
return tuple([column.name for column in self.columns])
return tuple([col.name for col in self.columns])

@property
def primary_key(self):
pk = [column.name for column in self.columns if column.primary_key]
pk = [col.name for col in self.columns if col.primary_key]
return pk[0]

@primary_key.setter
def primary_key(self, value: str):
for column in self.columns:
if column.name == value:
column.primary_key = True
for col in self.columns:
if col.name == value:
col.primary_key = True

def add_column(self, *columns):
"""Adding one or more column object to table
Expand Down Expand Up @@ -133,17 +135,17 @@ def add_row(self, *rows):
# Check length of columns and row
if len(row) != len(self.columns):
raise ValueError(f"length of row {row} is different of length of columns {len(self.columns)}")
for element, column in zip(row, self.columns):
column.append(element)
for element, col in zip(row, self.columns):
col.append(element)

def delete_row(self, row=-1):
"""Delete one row into columns
:param row: Index of row
:return: None
"""
for column in self.columns:
column.pop(row)
for col in self.columns:
col.pop(row)

def get_rows(self):
"""Getting all rows
Expand Down Expand Up @@ -178,7 +180,7 @@ def __delitem__(self, key=-1):
self._columns.pop(key)

def __iter__(self):
return (tuple([column[index] for column in self.columns])
return (tuple([col[index] for col in self.columns])
for index in range(len(self.columns[0])))

def __repr__(self):
Expand All @@ -192,10 +194,17 @@ 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):
def __init__(self, name,
data=None,
of_type=None,
max_len=None,
auto_increment=False,
primary_key=False,
default=None):
"""Column object
:param name: Name of column
:param data. Data list or tuple
:param of_type: Type of column
:param max_len: Max length of column
:param auto_increment: Boolean value (default False)
Expand All @@ -205,7 +214,7 @@ def __init__(self, name, of_type=None, max_len=None, auto_increment=False, prima
self.name = name
self._of_type = of_type if of_type is not None else object
self.max_len = max_len
self._data = []
self._data = [] if not data else list(data)
self._default = default
self._primary_key = primary_key
self._auto_increment = auto_increment
Expand Down Expand Up @@ -304,4 +313,24 @@ def __str__(self):
# region Other objects
Index = namedtuple('Index', ['name', 'table', 'column'])


# endregion


# region Functions
def column(func):
"""Decorator function to transform list or tuple object to Column object
:param func: function to decorate
:return: Column object
"""
@wraps(func)
def inner(*args, **kwargs):
data = func(*args, **kwargs)
if not isinstance(data, (list, tuple)):
raise ValueError(f"function {func.__name__} doesn't return a list or a tuple")
return Column(name=func.__name__, data=data)

return inner

# endregion
5 changes: 4 additions & 1 deletion nosqlapi/columndb/orm.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# orm stub -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -79,6 +79,7 @@ class Column:
default: Callable

def __init__(self, name: str,
data: Union[list, tuple] = None,
of_type: Any = None,
max_len: int = None,
auto_increment: bool = False,
Expand Down Expand Up @@ -112,3 +113,5 @@ class Column:


Index: Any

def column(func: Callable) -> Column: ...
2 changes: 1 addition & 1 deletion nosqlapi/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# created by: matteo.guadrini
# __init__.py -- nosqlapi
#
# Copyright (C) 2021 Matteo Guadrini <matteo.guadrini@hotmail.it>
# Copyright (C) 2022 Matteo Guadrini <matteo.guadrini@hotmail.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit b79ed94

Please sign in to comment.