sql insert bulk list of dictionaries

Solutions on MaxInterview for sql insert bulk list of dictionaries by the best coders in the world

showing results for - "sql insert bulk list of dictionaries"
Yannick
09 Oct 2016
1for item_code, companywise_item_data in items_default_data.items():
2			for company, item_default_data in companywise_item_data.items():
3				to_insert_data.append((
4					frappe.generate_hash("", 10),
5					item_code,
6					'Item',
7					'item_defaults',
8					company,
9					item_default_data.get('default_warehouse'),
10					item_default_data.get('expense_account'),
11					item_default_data.get('income_account'),
12					item_default_data.get('buying_cost_center'),
13					item_default_data.get('selling_cost_center'),
14				))
15
16		if to_insert_data:
17			frappe.db.sql('''
18				INSERT INTO `tabItem Default`
19				(
20					`name`, `parent`, `parenttype`, `parentfield`, `company`, `default_warehouse`,
21					`expense_account`, `income_account`, `buying_cost_center`, `selling_cost_center`
22				)
23				VALUES {}
24			'''.format(', '.join(['%s'] * len(to_insert_data))), tuple(to_insert_data))