Skip to main content

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

Project description

Copyright (c) 2019 Dr. Shubham Dipt

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.

  • select_related, prefetch_related, Q look ups in queries.

  • Support for MySQL.

  • Support for makemigrations.

Please feel free to contribute.

Platform: any Classifier: Programming Language :: Python :: 3 Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Description-Content-Type: text/markdown

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.0.4.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

sql_orm-1.0.4-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sql-orm-1.0.4.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for sql-orm-1.0.4.tar.gz
Algorithm Hash digest
SHA256 646507bdf8d7e79e9346b16a65f5dab002cce5237cc8b110316d6dbb88eb0a18
MD5 8e2c6171ffd869989ffb6c38c2314ba0
BLAKE2b-256 85d76f2dafc598395e4eebb69d4986f45e36cbe6f8ff53656f02a93b0ae99a0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sql_orm-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for sql_orm-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca577df2ecd13d04486f3b96d75d6719da2f7b599a36446302a0bf9fd966665a
MD5 c7ee3406a8f946ac89a744fdd3ff8df6
BLAKE2b-256 e0388343b9ca67529c1874a70125abf758d75f8e7d91cc91383eed52da877ee8

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