Skip to main content

Flask Database Manager by Problem Fighter Library

Project description

In the name of God, the Most Gracious, the Most Merciful.

PF-Flask-DB

Problem Fighter PF Flask DB (PF-Flask-DB) basically started with a Wrapper of Flask SQLAlchemy, When we try to create a project using Flask that moment we have to think about many area, such as Database, ORM, Migration etc. It's make developer life difficult, this project aim to integrate various library and provide a single but useful solution.




Example Codes

from flask import Flask
from pf_flask_db.pf_app_model import AppModel
from pf_flask_db.pf_app_database import app_db

app = Flask(__name__)

app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///pf-flask-db-quick-start.sqlite"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app_db.init_app(app)


class Person(AppModel):
    first_name = app_db.Column(app_db.String(150), nullable=False)
    last_name = app_db.Column(app_db.String(150))
    email = app_db.Column(app_db.String(120), nullable=False)
    age = app_db.Column(app_db.Integer)
    income = app_db.Column(app_db.Float, default=0)


with app.app_context():
    app_db.create_all()


@app.route('/')
def bismillah():
    return "PF Flask DB Tutorial"


@app.route('/create')
def create():
    person = Person(first_name="First Name", last_name="Last Name", email="hmtmcse.com@gmail.com", age=22, income=500)
    person.save()
    response = "Data successfully Inserted"
    return response


@app.route('/update')
def update():
    person = Person.query.filter_by(id=1).first()
    if person:
        person.first_name = "FName Update"
        person.last_name = "LName Update"
        person.save()
    return "Data has been updated."


@app.route('/delete')
def delete():
    person = Person.query.filter_by(id=1).first()
    if person:
        person.delete()
    return "Record has been deleted"


@app.route('/list')
def list():
    response = ""
    persons = Person.query.all()
    for person in persons:
        response += person.first_name + " " + person.last_name + " " + person.email + "<br>"
    return response


if __name__ == '__main__':
    app.run(debug=True)




Documentation

Install and update using pip:

pip install -U PF-Flask-DB

Please find the Documentation with example from hmtmcse.com




Donate

Problem Fighter develops and supports PF-Flask-DB and the libraries it uses. In order to grow the community of contributors and users, and allow the maintainers to devote more time to the projects.




Contributing

For guidance on setting up a development environment and how to make a contribution to PF-Flask-DB, see the contributing guidelines.




Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PF-Flask-DB-1.0.1.tar.gz (9.8 kB view hashes)

Uploaded Source

Built Distribution

PF_Flask_DB-1.0.1-py3-none-any.whl (14.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page