Skip to main content

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


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 connection If 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

This version

1.0.1

Download files

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

Files for multy, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size multy-1.0.1-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size multy-1.0.1.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page