Skip to content

Commit 9ca4601

Browse files
authored
Add move_rows() to query.py (#73)
1 parent 78289b4 commit 9ca4601

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

CHANGE.txt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in the LabKey 3.0.0 package
1010
- WAF encoding of parameters is initially supported with LabKey Server v23.09
1111
- WAF encoding can be opted out of on execute_sql calls by specifying waf_encode_sql=False
1212
- Query API - add optional parameters to insert_rows, update_rows, and delete_rows
13+
- Query API - add move_rows()
14+
- earliest compatible LabKey Server version: 24.1.0
1315

1416
What's New in the LabKey 2.6.1 package
1517
==============================

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Query API - [sample code](samples/query_examples.py)
1616
- **insert_rows()** - Insert rows into a table.
1717
- **select_rows()** - Query and get results sets.
1818
- **update_rows()** - Update rows in a table.
19+
- **move_rows()()** - Move rows in a table.
1920
- **truncate_table()** - Delete all rows from a table.
2021

2122
Domain API - [sample code](samples/domain_example.py)

labkey/query.py

+72
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,52 @@ def update_rows(
507507
)
508508

509509

510+
def move_rows(
511+
server_context: ServerContext,
512+
target_container_path: str,
513+
schema_name: str,
514+
query_name: str,
515+
rows: any,
516+
container_path: str = None,
517+
transacted: bool = True,
518+
audit_behavior: AuditBehavior = None,
519+
audit_user_comment: str = None,
520+
timeout: int = _default_timeout,
521+
):
522+
"""
523+
Move a set of rows from the schema.query
524+
:param server_context: A LabKey server context. See utils.create_server_context.
525+
:param target_container_path: target labkey container path for the move
526+
:param schema_name: schema of table
527+
:param query_name: table name to move from
528+
:param rows: Set of rows to move
529+
:param container_path: source labkey container path if not already set in context
530+
:param transacted: whether all of the updates should be done in a single transaction
531+
:param audit_behavior: used to override the audit behavior for the update. See class query.AuditBehavior
532+
:param audit_user_comment: used to provide a comment that will be attached to certain detailed audit log records
533+
:param timeout: timeout of request in seconds (defaults to 30s)
534+
:return:
535+
"""
536+
url = server_context.build_url("query", "moveRows.api", container_path=container_path)
537+
538+
payload = {"targetContainerPath": target_container_path, "schemaName": schema_name, "queryName": query_name, "rows": rows}
539+
540+
if transacted is False:
541+
payload["transacted"] = transacted
542+
543+
if audit_behavior is not None:
544+
payload["auditBehavior"] = audit_behavior
545+
546+
if audit_user_comment is not None:
547+
payload["auditUserComment"] = audit_user_comment
548+
549+
return server_context.make_request(
550+
url,
551+
json=payload,
552+
timeout=timeout,
553+
)
554+
555+
510556
class QueryWrapper:
511557
"""
512558
Wrapper for all of the API methods exposed in the query module. Used by the APIWrapper class.
@@ -672,3 +718,29 @@ def update_rows(
672718
audit_user_comment,
673719
timeout
674720
)
721+
722+
@functools.wraps(move_rows)
723+
def move_rows(
724+
self,
725+
target_container_path: str,
726+
schema_name: str,
727+
query_name: str,
728+
rows: any,
729+
container_path: str = None,
730+
transacted: bool = True,
731+
audit_behavior: AuditBehavior = None,
732+
audit_user_comment: str = None,
733+
timeout: int = _default_timeout,
734+
):
735+
return move_rows(
736+
self.server_context,
737+
target_container_path,
738+
schema_name,
739+
query_name,
740+
rows,
741+
container_path,
742+
transacted,
743+
audit_behavior,
744+
audit_user_comment,
745+
timeout
746+
)

0 commit comments

Comments
 (0)