Couchbase queries
bondi.couchbase.CouchbaseQuery
dataclass
Describe SQL++ text and bindings without parsing or executing the statement.
Mutable and unhashable. Parameter containers are deep-copied at construction. Later edits are not intercepted; validation runs explicitly, at construction, and before serialization or fingerprinting. Statement and context text are preserved exactly, including whitespace. No Couchbase SDK is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statement
|
str
|
Nonblank SQL++ text. Syntax, placeholder bindings and read-only behaviour are not checked, so invalid LLM candidates can be represented. |
required |
named_parameters
|
dict[str, Any]
|
Named JSON values, conventionally keyed without the $ placeholder prefix. Names are preserved, not parsed or normalized. |
dict()
|
positional_parameters
|
list[Any]
|
Ordered JSON values for positional placeholders. Only one parameter style may be nonempty (a toolkit restriction). |
list()
|
query_context
|
str | None
|
Optional nonblank native context string for name resolution. Its syntax is not parsed. None means no explicit context. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
Fields have incorrect types or parameters contain non-JSON values. |
ValueError
|
Text is blank, both parameter styles are used, or parameters contain nonfinite floats or circular references. |
Examples:
>>> query = CouchbaseQuery("SELECT $minimum AS stars", named_parameters={"minimum": 4})
>>> restored = CouchbaseQuery.from_json(query.to_json())
>>> restored.fingerprint() == query.fingerprint()
True
Source code in src/bondi/couchbase/query.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
fingerprint() -> str
Compute SHA-256 of the current validated serialized representation.
Includes statement text, bindings, context, kind and version. Whitespace and comments inside SQL++ affect the digest, as does parameter dictionary order. No semantic normalization or deployment identity is implied. Recomputed on each call; raises the same errors as to_json().
Source code in src/bondi/couchbase/query.py
179 180 181 182 183 184 185 186 187 | |
from_json(text: str) -> Self
classmethod
Load a version-1 SQL++ envelope and validate its fields.
Rejects missing/extra fields, unknown versions or kinds, duplicate JSON keys, and nonfinite numeric values. Envelope order and formatting may vary; the exact statement string is retained.
Raises:
| Type | Description |
|---|---|
TypeError
|
Input or decoded fields have incorrect types. |
ValueError
|
Invalid JSON, envelope or query values. |
Source code in src/bondi/couchbase/query.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
to_json() -> str
Serialize a validated version-1 couchbase.sqlpp envelope as standard JSON.
Includes defaults; preserves exact statement/context text, array order and parameter dictionary insertion order. Does not use BSON Extended JSON. Raises the same validation errors as validate().
Source code in src/bondi/couchbase/query.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
validate() -> None
Check text and JSON bindings without modifying them or parsing SQL++.
Plain dict/list containers, string keys, strings, booleans, integers, finite floats and None are accepted. Tuples, BSON-specific values and dates are rejected rather than converted. JSON validity does not guarantee server acceptance, including numeric range or precision support.
Raises:
| Type | Description |
|---|---|
TypeError
|
A field or nested parameter has an incorrect type. |
ValueError
|
Blank text, mixed parameter styles, nonfinite numbers or cycles. |
Source code in src/bondi/couchbase/query.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |