Skip to the content.

DB Builder Logo

dbBuilder.py v 1.0.0 - Beta

This project is my #oneweekchallenge project.

Start: 12 February 2021

End : 18 February 2021

This is a mini orm library for python. This library uses sqlite3. Therefore, the sqlite3 is necessary.

Features

Easy Model Registeration

from db_builder.fields import *
from db_builder.db_model import DB_Model

class MyPost(DB_Model):
    title = CharField(length=100)
    content = TextField()
    created_time = DateTimeField(auto_now=True)
    
    def __str__(self):
        return self.title
        
# for creating table
MyPost().create_table()

Easy Insert, Update and Delete Operation

# for inserting a new record
post = MyPost(title="My first post","Hello everyone. This is my first post!")
post.save()

# for updating a exist record
post = MyPost().objects().filter(title="My first post") # returns a queryset array
post[0].title = "New title of my first post"
post[0].save()

#for delete a exist record
post = MyPost().objects().filter(title="My first post") # returns a queryset array
post[0].delete()

Get record with id

MyPost().objects().get(post_id)

Filter records

post = MyPost().objects().filter(title="My first post") # using one column
post = MyPost().objects().filter(title="My first post",content="Hello everyone. This is my first post!") # using multiple columns

Built-in Validators and Parent Validator Class(for creating custom validator)

Built-in 17 Fields and Parent Field Class(for creating custom field)

Built-in 5 Errors and Parent Error Class(for creating custom error)

Utilities

Implementations

Flask

from flask.globals import g
# flask app contruction

def connect_db():
    Query = DB_Query("DB_URL")
    class ob():
        pass
    MyPost.__Query__ = Query
    ob.MyPost = MyPost

    return ob
    
@app.before_request
def before_request():
    g.db = connect_db()
    
# codes...
# Usage
g.db.Mypost(...) # classical usage