Skip to main content

ORM to databases for FLASK API

Project description

FlaskoSQL

PyPI version

GitHub code source

License



oracle



oracle

NEW : Support MySQL DBMS.

Description


The Package Name is a Python package that provides an Object-Relational Mapping (ORM) solution for relational databases (Oracle and MySQL), specifically designed for use in Flask APIs. It simplifies the interaction with an Oracle and MySQL database by providing an intuitive interface for querying, inserting, updating, and deleting data.

Features


  • Easy integration with Flask: Seamlessly integrate the ORM into your Flask application for database operations.

  • Simplified querying: Perform complex queries using an expressive API, allowing you to focus on your application logic rather than database intricacies.

  • Model-based approach: Define your database schema using Python classes, reducing the need for manual SQL queries and keeping your code organized.

  • Transaction support: Manage database transactions easily, ensuring data consistency and integrity.

Installation


You can install the Package Name package using pip:

pip install flaskosql

Usage


  1. Import the necessary classes and functions from the package:

from flaskosql.db import Connect

from flaskosql.field import Field

from flaskosql.model import Model

  1. Create a model class that represents a table in your Oracle database. Define the table schema using the Field class:
from flaskosql.model import Model

from flaskosql.field import Field



class Roles(Model):

    ID = Field("id", "NUMBER", primary_key=True)

    NAME = Field("name", "VARCHAR2(100)", nullable=False)

We can use also other table to create a realtion one to many :

from flaskosql.model import Model

from flaskosql.field import Field



class Users(Model):

    ID = Field("id", "NUMBER", primary_key=True)

    NAME = Field("name", "VARCHAR2(100)", nullable=False)

    ROLE_ID = Field("role_id", "NUMBER", foreign_key=("roles", "id"))

We should always put the names of fileds in upercase (it's obligatory)

  1. Create a database connection :
from flaskosql.db import Connect



connection = Connect('orm', 'ormpw', 'localhost', '1521', 'orcl').get_connection()
  1. Initialize the database connection:
from flaskosql.db import Connect

from flaskosql.model import Model



# Setup the connection : 

connection = Connect('orm', 'ormpw', 'localhost', '1521', 'orcl').get_connection()

# CReate the connection for the model  :

Model.set_connection(connection=connection)
  1. Perform database operations using the model:

Creation of tables (migrations) :

def migrate():

    Roles.create_table()

    Users.create_table()



migrate()

We must create Roles table before Users because we already defined a foreing_key constraint .

Filter users by a condition

role = Roles.get(id=1, name="ASHRAF")

and we can display the value :

if role:

    print(f"The id :{role.ID}")

    print(f"The name : {role.NAME})

Insert a new user

# Creating a user:

role = Roles(id=1, name="ASHRAF")

role.save()

Update a user's email

role.name = "SAMI"

role.update()

Delete a user

role.delete()

For more details on using the Package Name package, please refer to the documentation.

License


This package is licensed under the MIT License. See the LICENSE file for more information.


Feel free to modify this template according to your needs. Remember to replace "Package Name" with the actual name of your package and update the relevant sections with the appropriate details about your ORM and its usage with Flask and Oracle databases.

Make sure to also include the actual installation instructions, usage examples, and any other relevant information in your README file to provide a comprehensive guide for users of your package.

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

flaskosql-2.1.4.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

flaskosql-2.1.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file flaskosql-2.1.4.tar.gz.

File metadata

  • Download URL: flaskosql-2.1.4.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for flaskosql-2.1.4.tar.gz
Algorithm Hash digest
SHA256 53be3b6cfa5065975c9614366e12daaa7ef3d31d4f58cf23ddad1f546ba4e07f
MD5 fbf792ebabd942cd1d5614afa46f6b3f
BLAKE2b-256 47b4531ec491b42b4a7e27630364e975cd60da03703dada3b86d523b9bb11f63

See more details on using hashes here.

File details

Details for the file flaskosql-2.1.4-py3-none-any.whl.

File metadata

  • Download URL: flaskosql-2.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for flaskosql-2.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9f2ef430711e680f08a483005946e84a7bfdeffb4ae16912374f1794a924b23e
MD5 a50736ed0ea7ee2455bfc8ac67b71de2
BLAKE2b-256 13007d7f8a88b35cb33384a0800251ef27be928cbd12d42a2464121907fd2049

See more details on using hashes here.

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