I have yaml file that contains the data that needs to go into the table, i need to convert each yaml object to sql. can anyone tell me what I can use to convert it to sql statement
for example,
- model: ss
pk: 2
fields: {created_by: xxx, created_date: !!timestamp '2018-09-13
17:50:30.821769+00:00',
modified_by: null, modified_date: null, record_version: 0, team_name:
privat, team_type: abc}
In python
data_loaded = None
with open("data.yaml", 'r') as stream:
data_loaded = yaml.load(stream)
if data_loaded:
cols, vals = data_loaded["fields"].items()
table = data_loaded["model"]
sql = "INSERT INTO %s %s VALUES %s;" % ( table, tuple(cols), tuple(vals))
Depending with SQL dialect you might need take additional care of literal, types (eg replacing double quotes with singles, timestamp format etc)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.