Skip to main content

A python based ORM (Object relational mapping) to make flexible queries and saving new items in the database.

Project description

sql-orm

A simple python ORM (Object relational mapping) which can be used similar to Django ORM and can be easily integrated to any python project.

This ORM can be adapted easily to existing database as well (without even using any migrations). It can also be integrated with both MySQL and PostgreSQL in the same project.

Dependencies

  • Python3

Installation

$pip install sql-orm

Set up

Create a directory named db_models and a file named models.py.

Create models in models.py similar to the properties of the columns used in your database.

Create a config file for connecting to the database.

[POSTGRESQL]
DB_HOST = localhost
DB_PORT = 5432
DB_NAME = dbname
DB_USER = user
DB_PASSWORD = password
DEBUG = True

Set DEBUG = True only if you wish to see the SQL queries.

If you want to do create the tables as well, create a migrate.py file using: https://github.com/shubhamdipt/sql-orm/blob/master/migrate.py

Sample models can be found in the GitHub repository.

New features

  • Support for schema (can be added as an attribute in the models. "public" is the default schema.)

    _schema = "public"

  • Query: get_or_none (similar to get_or_create)

  • Negative indexing support for slicing queryset.

  • For setting any ForeignKey, either assign Model object or just the primary key (both works).

Differences

  • The primary key for every model needs to supplied explicitly.
  • All the models should be in one file called models.py in db_models directory.
  • verbose_name is optional for every field currently.

Missing features / Work in progress

  • JSONField for PostgreSQL.
  • ManyToMany relationship in models.
  • Support for MySQL.
  • Support for makemigrations.

Please feel free to contribute.

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

sql-orm-1.2.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

sql_orm-1.2.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sql-orm-1.2.2.tar.gz.

File metadata

  • Download URL: sql-orm-1.2.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for sql-orm-1.2.2.tar.gz
Algorithm Hash digest
SHA256 46d7b27200bdf6335505184394dd27938edb51107ad54f4dd59cbf79872e3e43
MD5 57748fd6382f3fb6e3be5620bdedd47b
BLAKE2b-256 1d52c0b9cbe81f714c6437205f3b69433b075b19f1ce548e93a6195fc8320b9d

See more details on using hashes here.

File details

Details for the file sql_orm-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: sql_orm-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for sql_orm-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 86e688cdb62e6a2dc14b2c8b988a2ed3519de131b61c689da30c0d413de8e6db
MD5 c0970cd31b8b520f35c4216c81d49a68
BLAKE2b-256 994745ac8a944a89aa13ad89a30231a38b59dc254ca65f6c66a425eb47a27040

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