Skip to content

Fixed query kwargs and options error #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/couchbase_streamlit_connector/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025-present Viraj Agarwal <virajagarwal15@gmail.com>
#
# SPDX-License-Identifier: MIT
__version__ = "0.2.5"
__version__ = "0.2.6"
26 changes: 22 additions & 4 deletions src/couchbase_streamlit_connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,27 @@ def remove_document(self, doc_id: str, opts: RemoveOptions = RemoveOptions(durab
raise Exception(f"ERROR: Failed to remove document with ID '{doc_id}'\n{e}")

# Query
def query(self, q, opts=QueryOptions(metrics=True, scan_consistency=QueryScanConsistency.REQUEST_PLUS)):
def query(self, q, opts=QueryOptions(metrics=True, scan_consistency=QueryScanConsistency.REQUEST_PLUS), **kwargs):
"""
Execute a SQL++ query against the Couchbase cluster. Works on the cluster level.

Args:
q (str): The SQL++ query to execute.
opts (couchbase.options.QueryOptions): Options for the query operation, defaulting to metrics and request plus scan consistency. To learn more about this please refer to [the docs](https://docs.couchbase.com/python-sdk/current/howtos/n1ql-queries-with-sdk.html)
**kwargs: Additional keyword arguments passed to the `query` method.

Returns:
Result: The result of the query operation.

Example:
```
query = "SELECT * FROM `travel-sample`.`inventory`.`airline` LIMIT 10"
result = connection.query(query)
output = [ row for row in result.rows() ]
```
"""
try:
result = self.cluster.query(q, QueryOptions(metrics=True))
result = self.cluster.query(q, opts, **kwargs)
return result
except CouchbaseException as ex:
raise Exception(f"ERROR: Couchbase encountered an error")
except Exception as ex:
raise Exception(f"ERROR: Couchbase encountered an error\n{ex}")