Skip to content

Commit

Permalink
enh: databases API nits (#2666)
Browse files Browse the repository at this point in the history
Co-authored-by: Henry Fontanier <henry@dust.tt>
  • Loading branch information
fontanierh and Henry Fontanier authored Nov 24, 2023
1 parent 8b4ef32 commit 669f535
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/bin/dust_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,13 +2150,13 @@ async fn databases_query_run(
"Failed to run query",
Some(e),
),
Ok((rows, schema)) => (
Ok((results, schema)) => (
StatusCode::OK,
Json(APIResponse {
error: None,
response: Some(json!({
"schema": schema,
"rows": rows,
"results": results,
})),
}),
),
Expand Down
4 changes: 2 additions & 2 deletions core/src/blocks/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Block for Database {
))?,
};

let (rows, schema) = match database.query(env.store.clone(), &query).await {
let (results, schema) = match database.query(env.store.clone(), &query).await {
Ok(r) => r,
Err(e) => Err(anyhow!(
"Error querying database `{}` in data source `{}`: {}",
Expand All @@ -124,7 +124,7 @@ impl Block for Database {

Ok(BlockResult {
value: json!({
"rows": rows,
"results": results,
"schema": schema,
}),
meta: None,
Expand Down
6 changes: 5 additions & 1 deletion front/lib/core_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export type CoreAPIDatabaseRow = {
value: Record<string, unknown>;
};

export type CoreAPIDatabaseResult = {
value: Record<string, unknown>;
};

export type CoreAPIDatabaseSchema = Record<
string,
{
Expand Down Expand Up @@ -1118,7 +1122,7 @@ export const CoreAPI = {
}): Promise<
CoreAPIResponse<{
schema: CoreAPIDatabaseSchema;
rows: CoreAPIDatabaseRow[];
results: CoreAPIDatabaseResult[];
}>
> {
const response = await fetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getDataSource } from "@app/lib/api/data_sources";
import { Authenticator, getAPIKey } from "@app/lib/auth";
import {
CoreAPI,
CoreAPIDatabaseRow,
CoreAPIDatabaseResult,
CoreAPIDatabaseSchema,
} from "@app/lib/core_api";
import { isDevelopmentOrDustWorkspace } from "@app/lib/development";
Expand All @@ -20,7 +20,7 @@ const GetDatabaseSchemaReqBodySchema = t.type({

type QueryDatabaseSchemaResponseBody = {
schema: CoreAPIDatabaseSchema;
rows: CoreAPIDatabaseRow[];
results: CoreAPIDatabaseResult[];
};

async function handler(
Expand Down Expand Up @@ -117,9 +117,9 @@ async function handler(
});
}

const { schema, rows } = queryRes.value;
const { schema, results } = queryRes.value;

return res.status(200).json({ schema, rows });
return res.status(200).json({ schema, results });

default:
return apiError(req, res, {
Expand Down

0 comments on commit 669f535

Please sign in to comment.