Skip to main content

MySql ORM

A simple Object Relational Mapper for MySql. Works with existing tables and the schema of the tables are automatically inferred.

Install

pip install orm-mysql

Connect to MySql

from orm import Table

Table.connect(config_dict={
    'host': '<host_here>',
    'port': 3306,
    'user': '<user>',
    'password': '<password>',
    'database': '<database>'
})

Create a class for a table

Create a class that inherits from Table. Initialize the class variable table_name with the name of the table, here 'student'

from orm import Table
Table.connect(config_dict=CONFIG)

class Student(Table):
    table_name = 'student'

OR use get_table()

from orm import Table, get_table
Table.connect(config_dict=CONFIG)

Student = get_table('student')

Insert data

Using save()

new_student = Student(name='hrushi', age=19, gender='M')
new_student.age = 20
new_student.save()

Using create()

new_student = Student.create(name='hrushi', age=19, gender='M')

Query data

Using where()

students = Student.where(age=19, gender='F')

for stu in students:
    print(stu.name)

Using find()

Find a single record based on PRIMARY KEY.

# find student where id(PK) = 2
student = Student.find(2)

print(student.name)

Delete a record

student = Student.find(2)
student.destroy()

Relations

has_many and belongs_to can be used to show relationships between tables.

from orm import Table, has_many, belongs_to

class Article(Table):
    table_name = 'articles'

    relations = [
        belongs_to(name='author', _class='Author', foreign_key='author_id', primary_key='id')
    ]

class Author(Table):
    table_name = 'authors'

    relations = [
        has_many(name='articles', _class='Article', foreign_key='author_id')
    ]

Get all the books written a Author

auth = Author.find(2)
articles = auth.articles()
for art in articles:
    print(art.title)

Get Author of a book

art = Article.find(5)
author = art.author()
print(author.name)

Metadata

Release files for orm-mysql 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for orm-mysql 1.0.6
File Size Uploaded Provenance Actions
orm-mysql-1.0.6.tar.gz 5.3 kB Without provenance Details for orm-mysql-1.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for orm-mysql 1.0.6
File Interpreter ABI Platform Actions
orm_mysql-1.0.6-py3-none-any.whl Python 3 none any Details for orm_mysql-1.0.6-py3-none-any.whl

Total release size: 12.0 kB

Release files / orm-mysql-1.0.6.tar.gz

Download URL orm-mysql-1.0.6.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
81d3f7bf14db91b209ea715a47403d92d7801aa0f5809f43063aba4ea510c73e
BLAKE2b-256 checksum
How to use checksums
610602d035f5e876ee6a3b40e5ee9acccbef0de1add2c232d8b2289c3a06a9d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / orm_mysql-1.0.6-py3-none-any.whl

Download URL orm_mysql-1.0.6-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26d05cf003346b6f18724da19a29e27ef6d328a28d5d6087ec1204c1c2893999
BLAKE2b-256 checksum
How to use checksums
e2e0204c5cec1e4f3239445b98f28c001b8eb3336aee0064f9629151562778ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for orm-mysql 1.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page