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
from odooless import Model, DB
DB._region_name = 'us-west-2' # AWS region
DB._endpoint_url = 'http://localhost:8000' # Omit for AWS cloud DynamoDB
DB._aws_access_key_id = 'test' # AWS access key id
DB._aws_secret_access_key = 'test' # AWS secret access key
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 = [
Field(
name='id',
index=True,
hidden=False,
string='ID',
type='S', # supported field types are Binary as B, Integer as N, String as S
index=True # create global secondary index for this attribute
),
]
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
someUsers = Users().read(id, fields) # returns recordset
search
from models import Users
domain = [
('field1', '=', 'value0'),
('field2', '>=', 'value1'),
('field3', '<=', 'value2'),
('field4', 'IN', ['value0', 'value1', 'value2',]),
('field5', 'between', ['value0', 'value1',]),
('field5', 'contains', 'value'),
('field5', 'begins_with', 'value'),
....
]
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']),
('field5', 'contains', 'value'),
('field5', 'begins_with', 'value'),
....
] # 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.2.5.tar.gz
(7.9 kB
view details)
Built Distribution
File details
Details for the file odooless-0.2.5.tar.gz
.
File metadata
- Download URL: odooless-0.2.5.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7256aaff3b36f7c41f7f18d0278d681292ddf0874a4b481254cda089ca92234 |
|
MD5 | 23ec2e2ba843d548e9a2a0f4c9f614d1 |
|
BLAKE2b-256 | 3210f9aa6cbca60cdb0de0695bc1173aa69f10d63aa2ef455226089ec0132af4 |
File details
Details for the file odooless-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: odooless-0.2.5-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d7379611d4587da24f310d14f3a35480dbd8dbd6761db8803415a3941273840 |
|
MD5 | 267a741e06c73f1ae441b2e306480241 |
|
BLAKE2b-256 | f1be60805792f786695c5582290dda0683fd4f7280aec59410f94f0368177bb8 |