diff --git a/CHANGE.txt b/CHANGE.txt index 08e2517..e18f551 100644 --- a/CHANGE.txt +++ b/CHANGE.txt @@ -10,6 +10,8 @@ What's New in the LabKey 3.0.0 package - WAF encoding of parameters is initially supported with LabKey Server v23.09 - WAF encoding can be opted out of on execute_sql calls by specifying waf_encode_sql=False - Query API - add optional parameters to insert_rows, update_rows, and delete_rows +- Query API - add move_rows() + - earliest compatible LabKey Server version: 24.1.0 What's New in the LabKey 2.6.1 package ============================== diff --git a/README.md b/README.md index e24a18f..82156d5 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Query API - [sample code](samples/query_examples.py) - **insert_rows()** - Insert rows into a table. - **select_rows()** - Query and get results sets. - **update_rows()** - Update rows in a table. +- **move_rows()()** - Move rows in a table. - **truncate_table()** - Delete all rows from a table. Domain API - [sample code](samples/domain_example.py) diff --git a/labkey/query.py b/labkey/query.py index d784490..d39e303 100644 --- a/labkey/query.py +++ b/labkey/query.py @@ -507,6 +507,52 @@ def update_rows( ) +def move_rows( + server_context: ServerContext, + target_container_path: str, + schema_name: str, + query_name: str, + rows: any, + container_path: str = None, + transacted: bool = True, + audit_behavior: AuditBehavior = None, + audit_user_comment: str = None, + timeout: int = _default_timeout, +): + """ + Move a set of rows from the schema.query + :param server_context: A LabKey server context. See utils.create_server_context. + :param target_container_path: target labkey container path for the move + :param schema_name: schema of table + :param query_name: table name to move from + :param rows: Set of rows to move + :param container_path: source labkey container path if not already set in context + :param transacted: whether all of the updates should be done in a single transaction + :param audit_behavior: used to override the audit behavior for the update. See class query.AuditBehavior + :param audit_user_comment: used to provide a comment that will be attached to certain detailed audit log records + :param timeout: timeout of request in seconds (defaults to 30s) + :return: + """ + url = server_context.build_url("query", "moveRows.api", container_path=container_path) + + payload = {"targetContainerPath": target_container_path, "schemaName": schema_name, "queryName": query_name, "rows": rows} + + if transacted is False: + payload["transacted"] = transacted + + if audit_behavior is not None: + payload["auditBehavior"] = audit_behavior + + if audit_user_comment is not None: + payload["auditUserComment"] = audit_user_comment + + return server_context.make_request( + url, + json=payload, + timeout=timeout, + ) + + class QueryWrapper: """ Wrapper for all of the API methods exposed in the query module. Used by the APIWrapper class. @@ -672,3 +718,29 @@ def update_rows( audit_user_comment, timeout ) + + @functools.wraps(move_rows) + def move_rows( + self, + target_container_path: str, + schema_name: str, + query_name: str, + rows: any, + container_path: str = None, + transacted: bool = True, + audit_behavior: AuditBehavior = None, + audit_user_comment: str = None, + timeout: int = _default_timeout, + ): + return move_rows( + self.server_context, + target_container_path, + schema_name, + query_name, + rows, + container_path, + transacted, + audit_behavior, + audit_user_comment, + timeout + )