list_of_dictionaries_to_mysql_inserts (function)

list_of_dictionaries_to_mysql_inserts(log, datalist, tableName)[source]

Convert a python list of dictionaries to pretty csv output

Key Arguments

  • log – logger

  • datalist – a list of dictionaries

  • tableName – the name of the table to create the insert statements for

Return

  • output – the mysql insert statements (as a string)

Usage

from fundamentals.files import list_of_dictionaries_to_mysql_inserts
mysqlInserts = list_of_dictionaries_to_mysql_inserts(
    log=log,
    datalist=dataList,
    tableName="my_new_table"
)
print mysqlInserts

this output the following:

INSERT INTO `testing_table` (a_newKey,and_another,dateCreated,uniqueKey2,uniquekey1) VALUES ("cool" ,"super cool" ,"2016-09-14T13:17:26" ,"burgers" ,"cheese")  ON DUPLICATE KEY UPDATE  a_newKey="cool", and_another="super cool", dateCreated="2016-09-14T13:17:26", uniqueKey2="burgers", uniquekey1="cheese" ;
...
...