A stupid MySQL insert helper
Project description
lazyins
A stupid database insert helper
This tool makes MySQL/SQLite table with the values, then insert the values.
Install
python -m pip install lazyins
Usage
Set environment variables to connect your mysql database.
export LAZYINS_HOST="localhost"
export LAZYINS_PORT=3306
export LAZYINS_USER="root"
export LAZYINS_PASSWD="password"
You don't need this setting for SQLite database.
Then make cursor.
from lazyins import Cursor
cur = Cursor() # default : mysql
# cur = Cursor(db='sqlite', db_name='your_db.db', table_name='your_table') # sqlite option
This Cursor()
function also recieves db
, host
, port
, user
, passwd
, db_name
, and table_name
as arguments.
Case 1
If you have two list to insert database.
names = ['value1', 'value2', 'value3']
values = [1, 2, 3.3]
You can make table and insert with cur.register(values, names)
.
The column types will be assumed.
Case 2
You have a list of tuple like that.
data = [('value1', 1), ('value2', 2), ('value3', 3.3)]
This simple cur.register(data)
works.
Case 3
If you want to let it assume almost all values, but you want set explicit types for some values.
For example, you need to set tinyint
instead of int
(assumed) for value2
,
explicit_types = [('values', 'tinyint')]
cur.register(values, names, explicit_types=explicit_types)
Detail options
For string, default length is 40.
If you need more, cur.default_char_length = 100
.
Project details
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
File details
Details for the file lazyins-0.1.1.tar.gz
.
File metadata
- Download URL: lazyins-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b0e6c790d14f1811dc467775a489aec682127566b311406eafc3b542bb12e74 |
|
MD5 | ec38d5ac518f4f413987f226a53df186 |
|
BLAKE2b-256 | 5ecd0f50c99990b6b0e21f001bc977dfa54264f266baabea8b73b85c9c0f3889 |
File details
Details for the file lazyins-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: lazyins-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ecc90200ab6c07b18117b9d33769f5df9097937ef6226a3636a4b067e216ed6 |
|
MD5 | 5e162387c24da88f4c481199d6288507 |
|
BLAKE2b-256 | dacd5b2df5a2ba5efa31056bb8a8abd05a9346d54d0df36bf158bf4e0cfa0f3d |