Skip to content

Django ORM manager for Postgresql, packaging INSERT ON CONFLICT

License

Notifications You must be signed in to change notification settings

luojilab/django-postgres-ioc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

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",
    },
)

About

Django ORM manager for Postgresql, packaging INSERT ON CONFLICT

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages