Skip to main content

A Django model manager providing insert on conflict for PostgreSQL database tables.

Project description

Introduction

https://img.shields.io/pypi/v/django-postgres-ioc.svg

Django ORM manager for Postgresql Came from Rock@luojilab

Replace update_or_create Without transaction, when using update_or_create may raise IntegrityError Because thread 1 execute update affect 0 row and at the same time, thread 2 insert it then thread 1 do insert will trigger UniqueKey conflict.

This method will use INSERT ON CONFLICT feature to fix this.

Requirements

  • Python >= 2.6 (tested on 2.7 and 3.6)

  • Django >= 1.7

  • PostgreSQL >= 9.5

Installation

Running following command:

$ python setup.py install

Or using pip:

$ pip install -U django-postgres-ioc

Usage

Python code:

from django.db import models
from ioc import IOCManager

class Test(models.Model):
    code = models.CharField(max_length=50, unique=True))
    name = models.CharField(max_length=100

    objects = IOCManager()

Test.objects.create_or_update(
    conflict="code",
    code="luojilab",
    defaults={
        "name": "LuojiLab",
    },
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_postgres_ioc-0.0.2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file django_postgres_ioc-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_postgres_ioc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e127ccbbf6d475ba0eed8f209402e54ea897d060d79a4977cc652a00f44a26b
MD5 3fd75aef496341885bdd118e7167f101
BLAKE2b-256 275dc16d9f23311d1dd53561e49356596491769ec4649f5df1a3b43bbb6e6c27

See more details on using hashes here.

Supported by

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