Skip to main content

This is a Django wrapper to make it easier to write raw SQL queries.

Project description

dj-raw-sql

Dependencies Version Downloads Downloads

dj-raw-sql is just a wrapper over the standard Django query

This demo shows how to get the record(s) from the database

Example:

def get_music_by_id(id: int):
    return "SELECT * FROM dj_app_music WHERE id = %s", (id,)
from django.db import models

# Our demo model
class Music(models.Model):
    name = models.CharField(max_length=150)
    create_at = models.DateTimeField(auto_now_add=True)
    update_at = models.DateTimeField(auto_now=True)
    is_delete = models.BooleanField(default=False)
from django.http import JsonResponse
from django.views import View

from my_app.queries import get_music_by_id

from dj_raw_sql import QueryExecutor


class MyView(View):
    def get(self, request, *args, **kwargs):
        music: tuple[tuple] = QueryExecutor.fetchone(get_music_by_id, id=1)
        return JsonResponse({"name": music[0][1]})

Benchmarks

Q: How were performance tests conducted?

A: tests/test_collection/ performance tests are located here. A dataset of 5000 elements was generated and loaded into the database. Then the query "SELECT * FROM dj_app_music LIMIT %s" was called, where the value of LIMIT changed from 10 to 5000 in each test.


Test results

Number of items fetchall to_ordereddict=True
10 0.00006 0.00011
100 0.00017 0.00025
1000 0.00138 0.00207
5000 0.00658 0.01052

Improve project

If you want to improve the project then create "Issues" . If you want to help with writing tests or typing, create a "pull request".

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

dj_raw_sql-3.0.0.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

dj_raw_sql-3.0.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

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