Documentation
Installation
pip install sajilo-orm
Table of Contents
- Connect Database
- Create Table
- QuerySet API
- Add Data
- Filter And Get Data
- Update Data
- Delete Data
- Check If Table Exists
- Types of Exception
Connect Database
Postgresql is the only supported Database for now(Feel free contribute to add new database)
from sajilo_orm.manager import BaseManager
MY_DB_SETTINGS = {
"database": "db_name",
"user": "db_user",
"password": "db_password",
"host": "db_host", #localhost for local connection
"port": "5432",
}
BaseManager.DB_SETTINGS = MY_DB_SETTINGS
Create Table
To create table , import DamiModel from sajilo_orm.models and use Column class to define column along with datatype which is in Nepali
Note: id serial primary key is added automatically when creating table
from sajilo_orm.models import DamiModel
from sajilo_orm.field import Column
class Country(DamiModel):
table_ko_naam = "country" # this will be the name of the table created in database
name = Column("string", max_length="50")
no_of_province = Column("anka") #number
new_year = Column("miti", default='2000-01-01') #date
today = Column("miti", default='aja_ko_date') #gives CURRENT_DATE
ramro = Column("ho_ki_haina" , default="ho") #boolean
data = Column("string", null=False,max_length="20") #by default null=True
Here's what data type type is behind the scene
sql_type = {
"anka":"INT ",
"string":"VARCHAR({max_length})
"miti":"DATE ",
"ho_ki_haina":"BOOLEAN ",
}
(string chai nepali ma k rakhne vanera sochirako)
Ths won't create table yet , To create table use table_banau method
Country.bata.table_banau()
QuerySet API
Here's the list of api that you can use for executing query
Get all data
country_list = Country.bata.sabaideu() # Returns List of Model Objects
print(country_list)
#output
#[] since there is no data yet
Add Data
For adding data in the table , use data_hala method.
Table.ma.data_hala(**dataharu)
Country.ma.data_hala(name="nepal",no_of_province= 8,data="nice country") # will update below
Country.ma.data_hala(name="japan",no_of_province= 37,data="nice country") #default value are added
# Now , if you call sabaideu
country_list = Country.bata.sabaideu()
#[<Country :1>,<Country :2>]
# To get single object
a = country_list[0]
print(a.name,a.no_of_province)
# nepal,8
Note: Country.bata.data_hala(name="japan",no_of_province= 37) also works
ma was adding cause it sounds gramatically correct than bata 😅
Filter and Get Data
For filter , use khojera method
filters = Team.bata.khojera(name="PSG")
For multiple column filter with 'AND' , add comma
filters = Country.bata.khojera(name="nepal" , no_of_province =20)
For 'OR' filter , add an argument with value "or" before writing filter condition
filters = Country.bata.khojera("or",name="japan" , no_of_province =20)
Update Data
To Update data, we need to add id before specifying updating column
If not id is provided IdXainaKanchha exception will be raised
Country.bata.data_fera(id=1, name="Nepal", no_of_province=7,new_year='1999-01-01')
# this will update Country with id 1 and rest will be updated with data provided
a = country_list[0]
print(a.name,a.no_of_province,a.new_year)
# Nepal,7,1999-01-01
Exceptions
If nothing is provided after id , then SyntaxBigryoKanchha exception will be raised
Refree.bata.data_fera(id=1) #raises SyntaxBigryoKanchha Exception
Refree.bata.data_fera(name="sinpachi") # raises IdXainaKanchha Exception
Delete Data
With this , this ORM will be able to perform simple CRUD OPERATIONS
To delete data_fala (lol) is used . Use this wisely .
Country.bata.data_fala(id=2)
Country.bata.data_fala(name='japan')`
Country.bata.data_fala(no_of_provinces=')
Check if table exists
Refree.bata.check_table_exists()
To get the use case of this orm , read the Test Case Here
Types of Exeptions
Below is the list of exception you might get using sajilo orm
-
TableVetayenaKanchha
Database ma nai table navayesi aaune error ! -
ColumnNaiXainaKanchha
Table ma nai navako column diyesi aaune error ! -
DatabaseConnectVayenaKanchha
Database connection config namilda aaune error ! -
IdXainaKanchha
Data ferda id diyena vane aaune error -
SyntaxBigryoKanchha
Syntax nai bigrexi aaune error ! -
DateFormatMilenaKanchha
Date Format nai bigrexi aaune error ! -
NotNullMaDataVayenaKanchha
Not Null ma Data navayesi aaune error !
Metadata
Release files for sajilo-orm 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sajilo-orm-0.0.6.tar.gz | 9.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sajilo_orm-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / sajilo-orm-0.0.6.tar.gz
| Download URL | sajilo-orm-0.0.6.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85425fbfd591c9866226c828054da1d886f8cbe38d7d032150f303cdf13f8f8b
|
|
BLAKE2b-256 checksum How to use checksums |
368175c0e0b68e8dc9ebeea524f47322ad126faac1b54ebd05d59b2a9fbb9d10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Release files / sajilo_orm-0.0.6-py3-none-any.whl
| Download URL | sajilo_orm-0.0.6-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
627ebf1619d1727b5b7afb860a058e432c321e0105f97200a9064a214c9619bd
|
|
BLAKE2b-256 checksum How to use checksums |
62065160653bf789e6c0ee8f05aef000572c18345db82fc57a400c50a6d0b281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|