A sample python library for managing a SQLite database
Project description
NotAOrm
A sample python library for managing a SQLite database
Download and Install
pip install NotAOrm
or git clone https://github.com/ludel/NotAOrm.git
in your project
There are no hard dependencies other than the Python standard library. NotAOrm run with python 3.6+.
Examples
Create a new model
from NotAOrm.table import Table
Site = Table(table_name='site', table_row=('id', 'url', 'visitor', 'date'))
Make sure you have created the table site
before.
Show methods
Get one element
Site.show.get(Site.url == 'google.com')
or if we want specific columns
Site.show.get(Site.url == 'google.com', [Site.url, Site.date])
Get all elements
all_sites = Site.show.all()
for site in all_sites:
print('=>', site.id, site.url, site.visitor, site.date, sep='\t')
We can order and limit the request
last_sites = Site.show.all(order_by=Site.date, limit=3)
Filter by where clause
filter_sites = Site.show.filter(Site.visitor >= 10, Site.id)
for site in filter_sites:
print('=>', site.id, sep='\t')
Group by and math methods
- By SUM
sites_visitor = Site.show.all(Site.visitor.sum, group_by=Site.date)
- By COUNT
sites_count = Site.show.all(Site.visitor.count, group_by=Site.date)
Change methods
Insert
Site.change.insert(url='google.com')
Update
Site.change.update(Site.url.like('bing'), url='google.com')
Delete
Site.change.delete(Site.visitor == 0, commit=True)
By default in the delete method, commit is set to false
License
NotAOrm is MIT licensed.
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
NotAOrm-0.1.0.tar.gz
(3.5 kB
view hashes)