A nice database orm written in python
Project description
alpha-orm
An extraordinary python database orm
Features
- Automatically creates tables and columns.
- No configuration required, simply create database.
- Currently supported databases include mysql.
Examples
Setup (MySQL)
import alphaorm.AlphaORM as DB
DB.setup('mysql',{
'host' : 'localhost',
'user' : 'root',
'password' : '',
'database' : 'alphaorm'
})
CREATE
#--------------------------------------
# CREATE 1
#--------------------------------------
product = DB.create('product')
product.name = 'Running shoes'
product.price = 5000
DB.store(product)
#--------------------------------------
# CREATE 2
#--------------------------------------
author = DB.create('author')
author.name = 'Chimamanda Adichie'
book = DB.create('book')
book.title = 'Purple Hibiscus'
book.author = author
DB.store(book)
READ
#--------------------------------------
# READ 1 [get all records]
#--------------------------------------
books = DB.getAll('book')
for book in books:
print(f'{book.title} by {book.author.name}')
#--------------------------------------
# READ 2 [filter one]
#--------------------------------------
book = DB.find('book','id = :bid', { 'bid' : 1 })
print(f'{book.title} by {book.author.name}')
#--------------------------------------
# READ 3 [filter all]
#--------------------------------------
author = DB.find('author','name = :authorName',{ 'authorName': 'William Shakespare' })
booksByShakespare = DB.findAll('book', 'author_id = :authorId', { 'authorId': author.getID() })
print('Books by William Shakespare are :')
for book in booksByShakespare:
print(book.title)
UPDATE
#--------------------------------------
# UPDATE
#--------------------------------------
product = DB.find('product', 'id = :pid', { 'pid': 1 })
product.price = 500
book = DB.find('book','id = :bid', { 'bid' : 1 })
book.author.name = 'New author'
book.isbn = '3847302-SD'
book.title = 'New Title'
DB.store(book)
print(book)
DELETE
#--------------------------------------
# DELETE 1 [delete single record]
#--------------------------------------
book = DB.find('book','id = :bid', { 'bid' : 1 })
DB.drop(book)
#--------------------------------------
# DELETE 2 [delete all records]
#--------------------------------------
DB.dropAll('book')
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
alpha-orm-1.2.31.tar.gz
(7.3 kB
view details)
File details
Details for the file alpha-orm-1.2.31.tar.gz
.
File metadata
- Download URL: alpha-orm-1.2.31.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb077f4e27133ef33748f3b4dde69000502168e8033400676a954ae9f3dd18d |
|
MD5 | 6ac0146a800d54cdedeb049ac002d842 |
|
BLAKE2b-256 | 3a81421389d821e7c36b95963420f47a44ec2f3548935a7c1c43345d085dacb8 |