nosqlapi column¶
In this package we find abstract classes and ODM classes concerning the column database types.
client module¶
The client module contains the specific classes for column databases and they are based on the core classes.
Client module for column NOSQL database.
- class nosqlapi.columndb.client.ColumnBatch(batch, session=None)[source]¶
Bases:
nosqlapi.common.core.Batch
,abc.ABC
Column NOSQL database Batch class
- class nosqlapi.columndb.client.ColumnConnection(*args, **kwargs)[source]¶
Bases:
nosqlapi.common.core.Connection
,abc.ABC
Column NOSQL database Connection class
- __init__(*args, **kwargs)[source]¶
Instantiate Connection object
- Parameters
host – Name of host that contains database
user – Username for connect to the host
password – Password for connect to the host
database – Name of database
port – Tcp port
bind_address – Hostname or an IP address for multiple network interfaces
read_timeout – Timeout for reading from the connection in seconds
write_timeout – Timeout for writing from the connection in seconds
ssl – Ssl connection established
ssl_ca – Ssl CA file specified
ssl_cert – Ssl certificate file specified
tls – Tls connection established
ssl_key – Ssl private key file specified
ssl_verify_cert – Verify certificate file
max_allowed_packet – Max size of packet sent to server in bytes
- class nosqlapi.columndb.client.ColumnResponse(data, code=None, header=None, error=None)[source]¶
Bases:
nosqlapi.common.core.Response
,abc.ABC
Column NOSQL database Response class
- __weakref__¶
list of weak references to the object (if defined)
- class nosqlapi.columndb.client.ColumnSelector(*args, **kwargs)[source]¶
Bases:
nosqlapi.common.core.Selector
,abc.ABC
Column NOSQL database Selector class
- __init__(*args, **kwargs)[source]¶
Instantiate Selector object
- Parameters
selector – Selector part of the query string
fields – Return fields
partition – Partition or collection of data
condition – Condition of query
order – Order by specific selector
limit – Limit result
- property filtering¶
Filter data
- class nosqlapi.columndb.client.ColumnSession(connection, database=None)[source]¶
Bases:
nosqlapi.common.core.Session
,abc.ABC
Column NOSQL database Session class
client example¶
This is an example of a library for connecting to a cassandra server.
# mycolumndb.py
import nosqlapi
# this module is my library of NOSQL column database, like Cassandra database
class Connection(nosqlapi.columndb.ColumnConnection):
def __init__(host='localhost', port=7000, database=0, username=None, password=None, ssl=None, tls=None,
cert=None, ca_cert=None, ca_bundle=None): ...
def close(self): ...
def connect(self, *args, **kwargs): ...
def create_database(self, database): ...
def has_database(self, database): ...
def databases(self): ...
def delete_database(self): ...
def show_database(self, database): ...
class Session(nosqlapi.columndb.ColumnSession):
# define here all methods
pass
conn = Connection('mycassandra.local', 'testdb', username='admin', password='pa$$w0rd', tls=True)
print(conn.show_database('testdb') # ('testdb', 17983788, 123, False) -- name, size, rows, readonly
sess = conn.connect() # Session object
...
odm module¶
The odm module contains the specific object for column databases.
ODM module for column NOSQL database.
- class nosqlapi.columndb.odm.Column(name, data=None, of_type=None, max_len=None, auto_increment=False, primary_key=False, default=None)[source]¶
Bases:
object
Represents column as container of values
- __init__(name, data=None, of_type=None, max_len=None, auto_increment=False, primary_key=False, default=None)[source]¶
Column object
- Parameters
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) :param primary_key: Set this column like a primary key :param default: Default function for generate data
- __weakref__¶
list of weak references to the object (if defined)
- append(data=None)[source]¶
Appending data to column. If auto_increment is True, the value is incremented automatically.
- Parameters
data – Any type of data
- Returns
None
- property auto_increment¶
Auto-increment value
- property data¶
List of values
- property of_type¶
Type of column
- class nosqlapi.columndb.odm.Index(name, table, column)¶
Bases:
tuple
- __getnewargs__()¶
Return self as a plain tuple. Used by copy and pickle.
- static __new__(_cls, name, table, column)¶
Create new instance of Index(name, table, column)
- __repr__()¶
Return a nicely formatted representation string
- property column¶
Alias for field number 2
- property name¶
Alias for field number 0
- property table¶
Alias for field number 1
- class nosqlapi.columndb.odm.Keyspace(name, exists=False)[source]¶
Bases:
nosqlapi.kvdb.odm.Keyspace
Represents keyspace like database
- class nosqlapi.columndb.odm.Table(name, *columns, **options)[source]¶
Bases:
object
Represents table as container of columns
- __init__(name, *columns, **options)[source]¶
Table object
- Parameters
name – Name of table
columns – Columns
options – Options
- __weakref__¶
list of weak references to the object (if defined)
- add_column(*columns)[source]¶
Adding one or more column object to table
- Parameters
columns – Column objects
- Returns
None
- add_index(index)[source]¶
Adding index to index property
- Parameters
index – Name or Index object
- Returns
None
- add_row(*rows)[source]¶
Add one or more row into columns
- Parameters
rows – Tuple of objects
- Returns
None
- property columns¶
List of columns
- delete_column(index=- 1)[source]¶
Deleting one column to table
- Parameters
index – Number of index
- Returns
None
- delete_index(index=- 1)[source]¶
Deleting index to index property
- Parameters
index – Name or Index object
- Returns
None
- property index¶
List of indexes
- property name¶
Name of table
- property options¶
Options
- nosqlapi.columndb.odm.column(func)[source]¶
Decorator function to transform list or tuple object to Column object
- Parameters
func – function to decorate
- Returns
Column object
odm example¶
These objects represent the respective column in databases.
import nosqlapi
import mycolumndb
keyspace = nosqlapi.columndb.odm.Keyspace('new_db') # in short -> nosqlapi.columndb.Keyspace('new_db')
# Make columns
id = nosqlapi.columndb.Column('id', of_type=int)
id.auto_increment = True # increment automatically
name = nosqlapi.columndb.Column('name', of_type=str)
# Set data
id.append()
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.create_table(table)
# Insert new data
mycolumndb.sess.insert('people', (None, 'Arthur Dent', 4000))