CSV to DB
install with: pip install csvtodb With this package you will be able to get info from a csv file like the column name, or specific row, and update your file with the possibility to add row or column.
The most important with this tool is you can easily transform your csv to, SQL scripts to build table or create seeder for your database (you can build them both in the same file).
Supported
DBMS
| DBMS | Engine | >= Ver. |
|---|---|---|
| Mysql |
|
8.0 |
Framework
| Framework | >= Ver. |
|---|---|
| Laravel | 8.x |
CSV
Features
- Get total columns in the file
- Get list of rows
- Get column content
- Get column name
- Get total rows in the file
- Update column name
- Set new row
- Update row
- Build json file
- Format column name to get right syntax (remove whitespace)
- Getter and setter for:
- filename
- filepath
- delimiter
- quotechar
How to build your csv
Your csv must respect some rules to be understandable correctly and for everything to works well
Column name
Column name whitespace needs to be replaced by underscore like => column_name method in this package can format them too
Date type
The syntax for the date must be one of those to be detected like date:
- dd/mm/yyyy 00:00:00
- dd/mm/yyyy
- yyyy
- 00:00:00
Number which have to be string
Example for a product reference if you want it to be string value you have to add non-numeric value like => '456789132'
Primary key
generate automatically don't worry
Foreign key
For the foreign key column name must be => tableReference_id
Usage
DBMS
Example with mysql:
Build new db
from csvtodb.Mysql import Mysql
Mysql.new_db(save_in='filepath', db_name='db_name', files={
'filepath1': (
('filename1', 'delimiter', 'quotechar'),
('filename2', 'delimiter', 'quotechar'),
),
'filepath2': (
('filename1', 'delimiter', 'quotechar'),
('filename2', 'delimiter', 'quotechar'),
),
# etc...
})
Build new table
from csvtodb.Csv import Csv
from csvtodb.Mysql import Mysql
csv = Csv(filename='filename', filepath='filepath')
# engine is optional the default value is InnoDB
# You can add temporary too which is optional default value is False
Mysql.new_table(csv=csv, filename='filename', filepath='filepath', engine='InnoDB')
Build multiple table
from csvtodb.Csv import Csv
from csvtodb.Mysql import Mysql
csv = Csv(filename='filename', filepath='filepath')
Mysql.new_tables(filepath='save_in', filename='sql_filename', files={
'filepath1': (
('filename1', 'delimiter', 'quotechar'),
('filename2', 'delimiter', 'quotechar'),
),
'filepath2': (
('filename1', 'delimiter', 'quotechar'),
('filename2', 'delimiter', 'quotechar'),
),
# etc...
}, engine='INNODB') # engine default value is INNODB
Build new seeder
from csvtodb.Csv import Csv
from csvtodb.Mysql import Mysql
csv = Csv(filename='filename', filepath='filepath')
Mysql.new_seeder(csv=csv, filename='filename', filepath='filepath')
Framework
example with Laravel (absolute path is recommended to avoid error):
Build new migration file
from csvtodb.Csv import Csv
from csvtodb.Laravel import Laravel
csv = Csv(filename='data_test', filepath='csv_file')
Laravel.new_migration(csv=csv,
filepath='laravel_migration_folder',
filename='laravel_migration_filename')
Build new seeder file
from csvtodb.Csv import Csv
from csvtodb.Laravel import Laravel
csv = Csv(filename='data_test', filepath='csv_file')
Laravel.new_seeder(csv=csv,
filepath='laravel_migration_folder',
filename='laravel_migration_filename')
Build new seeder file
from csvtodb.Csv import Csv
from csvtodb.Laravel import Laravel
csv = Csv(filename='data_test', filepath='csv_file')
Laravel.new_seeder(csv=csv,
filepath='laravel_migration_folder',
filename='laravel_migration_filename')
Release files for csvtodb 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| csvtodb-1.1.2.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| csvtodb-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.7 kB
Release files / csvtodb-1.1.2.tar.gz
| Download URL | csvtodb-1.1.2.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b2ef525f97f8293f5c65c4f3133f156a505168a163dd2d3a34aa83d7db470d6
|
|
BLAKE2b-256 checksum How to use checksums |
0c66b2bf7828fd40f4b14c93c6bad53abaffab8dac560c6bd164f8229bf9eb0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
|
Release files / csvtodb-1.1.2-py3-none-any.whl
| Download URL | csvtodb-1.1.2-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f29295c968c67fd3314eec7884e32801c6f8b60dce1770c85781c85f59c1a2de
|
|
BLAKE2b-256 checksum How to use checksums |
cb03918a0dabaef9792bd281f70e3eb59cd48dbc8127c46aa41788359b9c1d91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
|