A DynamoDB ORM inspired by Odoo
Project description
Odooless
An Odoo-like serverless ORM for AWS DynamoDB
Installation
pip install odooless
Getting Started
Define AWS credentials as environment variables
import os
os.environ['aws_access_key_id'] = 'aws_access_key_id'
os.environ['aws_secret_access_key'] = 'aws_secret_access_key'
os.environ['region_name'] = 'region_name'
Model Definition
To create a new model
from odooless import models
class Users(models.Model):
_name = 'Users' # dynamodb table name
_limit = 80 # define default limit number of records to get from db
_fields = [
{
'name': 'fieldName',
'type': 'S', # supported field types are Binary as B, Integer as N, String as S
'index': True, # create global secondary index for this attribute
}, ... # attribute definition
]
Methods
Currently available methods
create
from models import Users
someUser = Users().create({
'key': 'value',
}) # create single record
someUsers = Users().create([
{
'key': 'value',
},
{
'key': 'value',
}, ...
]) # or create multiple records
read
from models import Users
ids = [
'UUID4',
'UUID4',
'UUID4',
]
fields = [
'field1',
'field2',
....
]
someUsers = Users().read(ids, fields) # returns recordset
for user in someUsers:
print(user.name)
search
from models import Users
domain = [
('field1', '=', 'value0'),
('field2', '>=', 'value1'),
('field3', '<=', 'value2'),
('field4', 'IN', ['value0', 'value1', 'value2',]),
('field5', 'between', ['value0', 'value1',]),
....
] # currently simple query operators soon will add full polish-notation support
someUsers = users.search(field0=value, domain) # the search method takes index attribute name as a keyword parameter along with a domain that does not include this attribute and returns list of records
for user in someUsers:
print(user.name)
search_read
from models import Users
domain = [
('field1', '=', 'value0'),
('field2', '>=', 'value1'),
('field3', '<=', 'value2'),
('field4', 'IN', ['value0', 'value1', 'value2',]),
('field5', 'between', ['value0', 'value1',]),
....
] # currently simple query operators soon will add full polish-notation support
fields = [
'field1',
'field2',
....
]
someUsers = Users().search_read(field0=value, domain, fields) # the search method takes index attribute name as a keyword parameter along with a domain that does not include this attribute and returns list of records
for user in someUsers:
print(user.name)
write
from models import Users
users.write({
'id': 'UUIDv4'
'key': 'value',
}) # you can update single record by passing its id to model method
users.write([
{
'id': 'UUIDv4'
'key': 'value',
},
{
'id': 'UUIDv4'
'key': 'value',
},...
]) # you can update multiple records by passing id of record
someUser = Users().read(ids)
for user in someUsers:
user.write({
'key': 'value',
}) # no need to include id if you use update on the instance
delete
from models import Users
someUser = Users().delete(ids) # you can delete single or multiple records
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
odooless-0.1.16.tar.gz
(8.4 kB
view hashes)
Built Distribution
Close
Hashes for odooless-0.1.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 553f95974be513d3ce3e7b43308399a29451f3ec0aa2f5e13295fa407ec5158f |
|
MD5 | 1fbddd5b9db0ebe5445d9cd26ac95122 |
|
BLAKE2b-256 | 4ccb2df625872c5e6805988a09ff7c5fb0e6cba7899723ffaedec69af7d5b31e |