Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luojilab/django-postgres-ioc
Django ORM manager for Postgresql, packaging INSERT ON CONFLICT
https://github.com/luojilab/django-postgres-ioc
django postgresql python
Last synced: 12 days ago
JSON representation
Django ORM manager for Postgresql, packaging INSERT ON CONFLICT
- Host: GitHub
- URL: https://github.com/luojilab/django-postgres-ioc
- Owner: luojilab
- License: mit
- Created: 2018-06-29T03:45:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-06T06:39:10.000Z (over 6 years ago)
- Last Synced: 2024-10-04T09:15:44.776Z (about 2 months ago)
- Topics: django, postgresql, python
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 5
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.md
Awesome Lists containing this project
README
Introduction
============.. image:: https://img.shields.io/pypi/v/django-postgres-ioc.svg
:target: https://pypi.python.org/pypi/django-postgres-iocDjango ORM manager for Postgresql
Came from Rock@luojilabReplace ``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.5Installation
============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 IOCManagerclass Test(models.Model):
code = models.CharField(max_length=50, unique=True))
name = models.CharField(max_length=100objects = IOCManager()
Test.objects.create_or_update(
conflict="code",
code="luojilab",
defaults={
"name": "LuojiLab",
},
)