MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / _insert_item

Method _insert_item

functional/pipeline.py:1608–1632  ·  view source on GitHub ↗
(item)

Source from the content-addressed store, hash-verified

1606 """
1607
1608 def _insert_item(item):
1609 if isinstance(item, dict):
1610 cols = ", ".join(item.keys())
1611 placeholders = ", ".join("?" * len(item))
1612 sql = "INSERT INTO {} ({}) VALUES ({})".format(
1613 table_name, cols, placeholders
1614 )
1615 conn.execute(sql, tuple(item.values()))
1616 elif is_namedtuple(item):
1617 cols = ", ".join(item._fields)
1618 placeholders = ", ".join("?" * len(item))
1619 sql = "INSERT INTO {} ({}) VALUES ({})".format(
1620 table_name, cols, placeholders
1621 )
1622 conn.execute(sql, item)
1623 elif isinstance(item, (list, tuple)):
1624 placeholders = ", ".join("?" * len(item))
1625 sql = "INSERT INTO {} VALUES ({})".format(table_name, placeholders)
1626 conn.execute(sql, item)
1627 else:
1628 raise TypeError(
1629 "item must be one of dict, namedtuple, tuple or list got {}".format(
1630 type(item)
1631 )
1632 )
1633
1634 self.for_each(_insert_item)
1635

Callers

nothing calls this directly

Calls 2

is_namedtupleFunction · 0.90
joinMethod · 0.80

Tested by

no test coverage detected