Simple ORM for sqlite.
pip3 install git+https://github.com/mitrofun/weakorm
An example of using work with ORM can be found in the file example.py
To create a database, run
from weekorm.db import DataBase
db = DataBase('example.sqlite')
Create a class inherited from Model
from weekorm import model
class User(model.Model):
name = model.CharField(max_length=20)
email = model.CharField(max_length=40, unique=True)
is_admin = model.BooleanField(default=False)
The following types of fields exist in ORM
- CharField - Text field, max_length parameters-maximum field size, default 255.The default value ".
- IntegerField - Numeric integer field, default value 0
- FloatField - Numeric floating-point field field, default 0.0
- BooleanField - Boolean field, default False
- DateTimeField - Field with date and time.Example of use.
from weekorm import model
from datetime import datetime
class Article(model.Model):
title = model.CharField(max_length=100)
....
created = model.DateTimeField(default=datetime.now())
- ForeignKey - Field with a foreign key.Example of use.
from weekorm import model
class User(model.Model):
name = model.CharField(max_length=20)
email = model.CharField(max_length=40, unique=True)
birthday = model.DateTimeField()
def __str__(self):
return self.name
class Staff(model.Model):
user = model.ForeignKey(User)
position = model.CharField(max_length=40)
def __str__(self):
return f'{self.position} - {self.user.name}'
user = User(
name='Mik',
email='mik@gmail.com',
birthday=datetime(year=1983, month=12, day=6)
)
user.save()
staff = Staff(user=user, position='Tester')
staff.save()
staff = Staff.query().filter(position='Tester').first()
staff.position = 'Developer'
staff.save()
You can also update the data for a set of features that meet the selection condition.
Staff.query().filter(position='Tester').update(position='QA')
To develop locally, install the dependencies
pip3 install -r requirements/develop.txt
Running tests
pytest
You don't need to install dependencies locally to run tests in Docker.Just run the command
make docker-build && make docker-test
- python 3.6+
weakorm is released under the MIT License. See the LICENSE file for more details.