Easily implement bulk insert and ON DUPLICATE KEY UPDATEstatements with MySQL and MariaDB
Project description
multy
Package that can be easily bulk inserted with MySQL / MariaDB of Python. You can also perform inserts and updates based on primary and unique keys.
Requirement
- Python3
- MySQL >= 5.5
- MariaDB >= 5.5
- Install PyMySQL or mysqlclient
Installation
pip install multy
Bulk Insert
Example of inserting into the following table
Table Name: sample
| Field | Type |
|---|---|
| id | int |
| age | int |
| name | varchar |
import multy
import pymysql
# pymysql or mysqlclient connection
con = pymysql.connect(user='', passwd='', host='localhost', db='')
# step1 The second argument is the table name
sample = multy.BulkQuery(con, 'sample')
for i in range(10):
# step2 {column name: value}
sample.add_record({
'id': 1,
'age': 28,
'name': 'test'
})
# step3 Insert execution
sample.insert().save()
Bulk Insert or Update
insert_or_update()If the primary key or unique key already exists, it will be updated, and if it does not exist, it will be inserted.
sample = multy.BulkQuery(con, 'sample')
for i in range(10):
sample.add_record({
'id': 1,
'age': 28,
'name': 'test'
})
sample.insert_or_update().save()
If you have Django
from django.db import connectionIf you are using mysqlclient or pymysql with Django, you can use the imported connection as is
from django.db import connection
import multy
sample = multy.BulkQuery(connection, 'sample')
License
multy is under MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multy-1.0.1.tar.gz.
File metadata
- Download URL: multy-1.0.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce8f20e37f7443bd49a146653d16bc238ee5de3bb38eafb25140f1a284710ac4
|
|
| MD5 |
3f18b2d5aa8e7a77585ec4c8f4eb36a1
|
|
| BLAKE2b-256 |
6fe8758e5d18a033288ab210ba57744d18373a693ae7528b31b99f32ccc89f66
|
File details
Details for the file multy-1.0.1-py3-none-any.whl.
File metadata
- Download URL: multy-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49ec3d35d73c9c0054459d525c8fe7702f6976b81ec6d81723698b15bf5f1596
|
|
| MD5 |
acd7dc84cd88c3d33b50c6a0725a2e5f
|
|
| BLAKE2b-256 |
640e58070bd52c01070a4390523febabfbbf16c211c3bf6f574412f83626c921
|