Skip to content
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 crates/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ Executes a SQL query against a cluster and returns the result set. Paginate by w

**Parameters**: `QueryParams` with `query` (String, required) and `cluster_id` (String, required).

**Returns**: `QueryResponse` — `meta` (`Vec<ColumnMeta>`, each with `name` and `column_type`), `data` (`Vec<serde_json::Value>`, rows as JSON objects keyed by column name), `rows`, `rows_before_limit_at_least`, `statistics` (`QueryStatistics` with `elapsed`, `rows_read`, `bytes_read`), and `credits`.
**Returns**: `QueryResponse` — `meta` (`Vec<ColumnMeta>`, each with `name` and `column_type`), `data` (`Vec<serde_json::Value>`, rows as JSON objects keyed by column name), `rows`, `rows_before_limit_at_least`, `statistics` (`QueryStatistics` with `elapsed`, `rows_read`, `bytes_read`), and `credits` (`Option<i64>`, absent when not reported).

```rust
// Rust
Expand Down
5 changes: 4 additions & 1 deletion crates/core/examples/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ async fn main() {
Ok(resp) => {
println!(
"query: {} rows ({} before limit), {} credits, {:.4}s",
resp.rows, resp.rows_before_limit_at_least, resp.credits, resp.statistics.elapsed
resp.rows,
resp.rows_before_limit_at_least,
resp.credits.unwrap_or_default(),
resp.statistics.elapsed
);
println!(
"columns: {:?}",
Expand Down
24 changes: 22 additions & 2 deletions crates/core/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub struct QueryResponse {
/// Query execution statistics.
pub statistics: QueryStatistics,
/// Credits consumed by the query.
pub credits: i64,
pub credits: Option<i64>,
}

// ── Schema response types ──────────────────────────────────────────────────
Expand Down Expand Up @@ -441,7 +441,7 @@ mod tests {
let resp = sdk.sql.query(&query_params()).await.unwrap();
assert_eq!(resp.rows, 2);
assert_eq!(resp.rows_before_limit_at_least, 18251);
assert_eq!(resp.credits, 135);
assert_eq!(resp.credits, Some(135));
assert_eq!(resp.meta.len(), 2);
assert_eq!(resp.meta[0].name, "time");
assert_eq!(resp.statistics.rows_read, 31341);
Expand Down Expand Up @@ -475,6 +475,26 @@ mod tests {
sdk.sql.query(&query_params()).await.unwrap();
}

#[tokio::test]
async fn query_without_credits() {
let server = MockServer::start().await;
Mock::given(method("POST"))
.and(path("/query"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"meta": [{"name": "1", "type": "UInt8"}],
"data": [{"1": 1}],
"rows": 1,
"rows_before_limit_at_least": 1,
"statistics": {"elapsed": 0.001, "rows_read": 1, "bytes_read": 1}
})))
.mount(&server)
.await;
let sdk = make_sdk(format!("{}/", server.uri()));
let resp = sdk.sql.query(&query_params()).await.unwrap();
assert_eq!(resp.rows, 1);
assert_eq!(resp.credits, None);
}

#[tokio::test]
async fn query_api_error() {
let server = MockServer::start().await;
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct QueryResponseNode {
/// Query execution statistics.
pub statistics: QueryStatisticsNode,
/// Credits consumed by the query.
pub credits: i64,
pub credits: Option<i64>,
}

impl From<core::sql::QueryResponse> for QueryResponseNode {
Expand Down
2 changes: 1 addition & 1 deletion crates/python/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct PyQueryResponse {
#[pyo3(get)]
pub statistics: QueryStatistics,
#[pyo3(get)]
pub credits: i64,
pub credits: Option<i64>,
}

impl PyQueryResponse {
Expand Down
2 changes: 1 addition & 1 deletion npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ Executes a SQL query against a cluster and returns the result set. Paginate by w

**Parameters**: `query` (string, required), `cluster_id` / `clusterId` (string, required).

**Returns**: a query result — `meta` (column metadata, each with `name` and `type`), `data` (rows as objects keyed by column name), `rows`, `rows_before_limit_at_least` / `rowsBeforeLimitAtLeast`, `statistics` (`elapsed`, `rows_read`/`rowsRead`, `bytes_read`/`bytesRead`), and `credits`.
**Returns**: a query result — `meta` (column metadata, each with `name` and `type`), `data` (rows as objects keyed by column name), `rows`, `rows_before_limit_at_least` / `rowsBeforeLimitAtLeast`, `statistics` (`elapsed`, `rows_read`/`rowsRead`, `bytes_read`/`bytesRead`), and `credits` (optional).

```typescript
// Node.js
Expand Down
2 changes: 1 addition & 1 deletion npm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3945,7 +3945,7 @@ export interface QueryResponseNode {
/** Query execution statistics. */
statistics: QueryStatisticsNode
/** Credits consumed by the query. */
credits: number
credits?: number
}

export interface QueryStatisticsNode {
Expand Down
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ Executes a SQL query against a cluster and returns the result set. Paginate by w

**Parameters**: `query` (str, required), `cluster_id` (str, required).

**Returns**: `QueryResponse` — `meta` (list of `ColumnMeta`, each with `name` and `column_type`), `data` (`list[dict]`, rows keyed by column name), `rows`, `rows_before_limit_at_least`, `statistics` (`QueryStatistics` with `elapsed`, `rows_read`, `bytes_read`), and `credits`.
**Returns**: `QueryResponse` — `meta` (list of `ColumnMeta`, each with `name` and `column_type`), `data` (`list[dict]`, rows keyed by column name), `rows`, `rows_before_limit_at_least`, `statistics` (`QueryStatistics` with `elapsed`, `rows_read`, `bytes_read`), and `credits` (optional).

```python
# Python
Expand Down
2 changes: 1 addition & 1 deletion python/quicknode_sdk/_core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7364,7 +7364,7 @@ class QueryResponse:
@property
def statistics(self) -> QueryStatistics: ...
@property
def credits(self) -> builtins.int: ...
def credits(self) -> typing.Optional[builtins.int]: ...
@property
def data(self) -> list[dict[str, typing.Any]]: ...

Expand Down
2 changes: 1 addition & 1 deletion ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ Executes a SQL query against a cluster and returns the result set. Paginate by w

**Parameters** (Hash): `query:` (String, required), `cluster_id:` (String, required).

**Returns** a Hash with `meta` (column metadata, each with `name` and `type`), `data` (rows as Hashes keyed by column name), `rows`, `rows_before_limit_at_least`, `statistics` (`elapsed`, `rows_read`, `bytes_read`), and `credits`. Access with `[]` or `dig`.
**Returns** a Hash with `meta` (column metadata, each with `name` and `type`), `data` (rows as Hashes keyed by column name), `rows`, `rows_before_limit_at_least`, `statistics` (`elapsed`, `rows_read`, `bytes_read`), and `credits` (may be `nil`). Access with `[]` or `dig`.

```ruby
# Ruby
Expand Down
Loading