Package: csvtodb
CSV to DBinstall with: pip install csvtodbWith 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).SupportedDBMSDBMSEngine>= Ver.MysqlInnodbMyISAMMemoryCSV8.0FrameworkFramework>= Ver.Laravel8.xCSVFeaturesGet total columns in the fileGet list of rowsGet column contentGet column nameGet total rows in the fileUpdate column nameSet new rowUpdate rowBuild json fileFormat column name to get right syntax (remove whitespace)Getter and setter for:filenamefilepathdelimiterquotecharHow to build your csvYour csv must respect some rules to be understandable correctly and for everything to works wellColumn nameColumn name whitespace needs to be replaced byunderscorelike => column_name
method in this package can format them tooDate typeThe syntax for the date must be one of those to be detected like date:dd/mm/yyyy 00:00:00dd/mm/yyyyyyyy00:00:00Number which have to be stringExample for a product reference if you want it to be string value you have to add
non-numeric value like => '456789132'Primary keygenerate automatically don't worryForeign keyFor the foreign key column name must be => tableReference_idUsageDBMSExample with mysql:Build new dbfromcsvtodb.MysqlimportMysqlMysql.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 tablefromcsvtodb.CsvimportCsvfromcsvtodb.MysqlimportMysqlcsv=Csv(filename='filename',filepath='filepath')# engine is optional the default value is InnoDB# You can add temporary too which is optional default value is FalseMysql.new_table(csv=csv,filename='filename',filepath='filepath',engine='InnoDB')Build multiple tablefromcsvtodb.CsvimportCsvfromcsvtodb.MysqlimportMysqlcsv=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 INNODBBuild new seederfromcsvtodb.CsvimportCsvfromcsvtodb.MysqlimportMysqlcsv=Csv(filename='filename',filepath='filepath')Mysql.new_seeder(csv=csv,filename='filename',filepath='filepath')Frameworkexample with Laravel (absolute path is recommended to avoid error):Build new migration filefromcsvtodb.CsvimportCsvfromcsvtodb.LaravelimportLaravelcsv=Csv(filename='data_test',filepath='csv_file')Laravel.new_migration(csv=csv,filepath='laravel_migration_folder',filename='laravel_migration_filename')Build new seeder filefromcsvtodb.CsvimportCsvfromcsvtodb.LaravelimportLaravelcsv=Csv(filename='data_test',filepath='csv_file')Laravel.new_seeder(csv=csv,filepath='laravel_migration_folder',filename='laravel_migration_filename')Build new seeder filefromcsvtodb.CsvimportCsvfromcsvtodb.LaravelimportLaravelcsv=Csv(filename='data_test',filepath='csv_file')Laravel.new_seeder(csv=csv,filepath='laravel_migration_folder',filename='laravel_migration_filename')