MCPcopy Index your code
hub / github.com/TaskingAI/TaskingAI / create_object

Function create_object

backend/tkhelper/database/postgres/ops/create.py:8–43  ·  view source on GitHub ↗

Asynchronously insert a new object into the database. :param conn: An asynchronous database connection object. :param table_name: Name of the database table where the new object will be inserted. :param object_dict: Dictionary containing the data to insert, where keys are column na

(
    conn,
    table_name: str,
    object_dict: Dict,
    primary_keys: List[str],
)

Source from the content-addressed store, hash-verified

6
7
8async def create_object(
9 conn,
10 table_name: str,
11 object_dict: Dict,
12 primary_keys: List[str],
13) -> None:
14 """
15 Asynchronously insert a new object into the database.
16
17 :param conn: An asynchronous database connection object.
18 :param table_name: Name of the database table where the new object will be inserted.
19 :param object_dict: Dictionary containing the data to insert, where keys are column names.
20 :param primary_keys: List of primary key column names.
21 :return: None
22 """
23
24 if not object_dict:
25 raise ValueError("object_dict cannot be empty")
26
27 # Cast all the dict/list to str
28 upsert_dict = prepare_db_dict(object_dict)
29
30 # Construct the column names and placeholders for the values
31 columns = ", ".join(upsert_dict.keys())
32 placeholders = ", ".join(f"${i + 1}" for i in range(len(upsert_dict)))
33
34 # Construct the INSERT query
35 query = f"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})"
36
37 # Prepare the values from the pg_create_dict
38 values = list(upsert_dict.values())
39
40 logger.debug(f"create_object: query={query}, values={values}")
41
42 # Attempt to execute the insert query
43 await conn.execute(query, *values)

Callers

nothing calls this directly

Calls 2

prepare_db_dictFunction · 0.90
executeMethod · 0.45

Tested by

no test coverage detected