Skip to main content

Django app that lets you define custom SQL functions

Project description

django-sqlfun

Django SQLFun allows you to define custom SQL functions in code which are then kept up to date in the database with every run of manage.py migrate.

Use

  1. Install using your favorite python package manager, eg. pip install django-sqlfun
  2. Add django_sqlfun to INSTALLED_APPS in your django settings.
  3. Define a custom function in a module that gets imported on project load (eg. models.py). See below for example.
  4. Run manage.py migrate

Example

from django_sqlfun import SqlFun

class BadSum(SqlFun):
    ""Almost returns the sum of two numbers."""
    
    sql = """
        CREATE OR REPLACE FUNCTION bad_sum(
            first integer,
            second integer
        ) RETURNS integer as $$
        SELECT first + second + 1;
        $$
        LANGUAGE sql
        stable;
    """

Planned Developments

This is alpha level software, and thus far only tested with Postgres.

  • Add support for usage in Python code by inheriting from django.db.models.expressions.Func.
  • Integrate into migrations system. Currently if you use functions that are defined through django-sqlfun in django migrations, you may experience errors since the latest version of that function will always be used. I believe this can be tackled with the same approach used by the django-pgtrigger project.
  • Handle deleted custom functions. Currently if you delete a django-sqlfun function, it is not automatically deleted in the database itself. This could likely also be solved by integrating into the migrations system.

Ideas for improvement are welcome. Breaking changes are possible.

Credits

This project is inspired by two great projects: django-pgtrigger and django-pgviews.

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

django-sqlfun-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

django_sqlfun-0.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file django-sqlfun-0.0.1.tar.gz.

File metadata

  • Download URL: django-sqlfun-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.4.3 CPython/3.9.16

File hashes

Hashes for django-sqlfun-0.0.1.tar.gz
Algorithm Hash digest
SHA256 813c871c8c0377299e0c1d050410c44d98f6d03432e5094242db4a83b23267d3
MD5 b7ec429d30000e4f5102951e2609d9c7
BLAKE2b-256 00617c1ac402a961aff44a46cecaee4f9d678747a3d4b55c99f4ad745260825a

See more details on using hashes here.

File details

Details for the file django_sqlfun-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_sqlfun-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.4.3 CPython/3.9.16

File hashes

Hashes for django_sqlfun-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d0946981dda805472dbc76bfe6a653fb8605d68417ea89b3c5d24a9e0d0df51
MD5 345fc4ec2409d38b247ed4a06a6aacfc
BLAKE2b-256 dcc4e2f8d1b9848d132d792131fb2a2950e95fa14f38063a2879014df2c4db38

See more details on using hashes here.

Supported by

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