simplify the app using typer
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from chromy.command_inputs import AddDataInput
|
||||
from chromy.utilities import ingest_file
|
||||
|
||||
|
||||
def handle_add_data(command: AddDataInput) -> int:
|
||||
records_added = ingest_file(command.collection, command.file)
|
||||
print(f"Added {records_added} records to collection '{command.collection}'.")
|
||||
def handle_add_data(collection: str, file: str) -> int:
|
||||
records_added = ingest_file(collection, file)
|
||||
print(f"Added {records_added} records to collection '{collection}'.")
|
||||
return 0
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from chromy.chroma_functions import count_collection
|
||||
from chromy.command_inputs import CountCollectionInput
|
||||
|
||||
|
||||
def handle_count_collection(command: CountCollectionInput) -> int:
|
||||
print(count_collection(command.collection))
|
||||
def handle_count_collection(collection: str) -> int:
|
||||
print(count_collection(collection))
|
||||
return 0
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from chromy.chroma_functions import create_collection
|
||||
from chromy.command_inputs import CreateCollectionInput
|
||||
|
||||
|
||||
def handle_create_collection(command: CreateCollectionInput) -> int:
|
||||
collection_name = create_collection(command.collection)
|
||||
def handle_create_collection(collection: str) -> int:
|
||||
collection_name = create_collection(collection)
|
||||
print(f"Created collection '{collection_name}'.")
|
||||
return 0
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from chromy.chroma_functions import delete_collection, delete_data
|
||||
from chromy.command_inputs import DeleteCollectionInput, DeleteRecordsInput
|
||||
|
||||
|
||||
def _parse_where_clause(where_clause: str) -> dict[str, str]:
|
||||
@@ -19,18 +18,18 @@ def _parse_where_clause(where_clause: str) -> dict[str, str]:
|
||||
return {condition: value}
|
||||
|
||||
|
||||
def handle_delete_collection(command: DeleteCollectionInput) -> int:
|
||||
delete_collection(command.collection)
|
||||
print(f"Deleted collection '{command.collection}'.")
|
||||
def handle_delete_collection(collection: str) -> int:
|
||||
delete_collection(collection)
|
||||
print(f"Deleted collection '{collection}'.")
|
||||
return 0
|
||||
|
||||
|
||||
def handle_delete_records(command: DeleteRecordsInput) -> int:
|
||||
where = _parse_where_clause(command.where)
|
||||
deleted = delete_data(command.collection, where)
|
||||
def handle_delete_records(collection: str, where_clause: str) -> int:
|
||||
where = _parse_where_clause(where_clause)
|
||||
deleted = delete_data(collection, where)
|
||||
condition, value = next(iter(where.items()))
|
||||
print(
|
||||
f"Deleted {deleted} record(s) from collection '{command.collection}' "
|
||||
f"Deleted {deleted} record(s) from collection '{collection}' "
|
||||
f"where {condition}={value}."
|
||||
)
|
||||
return 0
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from chromy.chroma_functions import list_collections
|
||||
from chromy.command_inputs import ListCollectionsInput
|
||||
from chromy.utilities import print_lines
|
||||
|
||||
|
||||
def handle_list_collections(_: ListCollectionsInput) -> int:
|
||||
def handle_list_collections() -> int:
|
||||
collections = list_collections()
|
||||
if not collections:
|
||||
print("No collections found.")
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from chromy.command_inputs import QueryInput
|
||||
from chromy.utilities import format_query_result, print_lines, run_query
|
||||
|
||||
|
||||
def handle_query(command: QueryInput) -> int:
|
||||
result = run_query(command.collection, command.query_text)
|
||||
def handle_query(collection: str, query_text: str) -> int:
|
||||
result = run_query(collection, query_text)
|
||||
print_lines(format_query_result(result))
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user