Skip to content

Full Toolkit for Next-Level Domain Analysis

Use generic types for BigQuery queries 💪

Felix Wotschofskyd8baa53e5b67
diff --git a/lib/bigquery.ts b/lib/bigquery.ts
index e565ce1..b2c6792 100644
--- a/lib/bigquery.ts
+++ b/lib/bigquery.ts
@@ -52,13 +52,13 @@ export const insertRows = async ({
}
};
-export const query = async ({
+export const query = async <T extends Record<string, any>>({
query,
params,
}: {
query: string;
params?: Record<string, string>;
-}): Promise<any[]> => {
+}): Promise<T[]> => {
const accessToken = await getAccessToken({
// @ts-expect-error still works
credentials: credentials,
diff --git a/lib/search.ts b/lib/search.ts
index ee59493..c72db5a 100644
--- a/lib/search.ts
+++ b/lib/search.ts
@@ -48,7 +48,7 @@ export const getSearchSuggestions = async (query: string) => {
}
const tableName = `\`${bigquery.projectId}.${env.BIGQUERY_DATASET}.lookups\``;
- const results = await bigquery.query({
+ const results = await bigquery.query<{ baseDomain: string }>({
query: `
SELECT baseDomain
FROM ${tableName}
@@ -62,7 +62,7 @@ export const getSearchSuggestions = async (query: string) => {
},
});
- return results.map((row: any) => row.baseDomain) as string[];
+ return results.map((row) => row.baseDomain);
};
export const getTopDomains = async (count: number) => {
@@ -71,7 +71,7 @@ export const getTopDomains = async (count: number) => {
}
const tableName = `\`${bigquery.projectId}.${env.BIGQUERY_DATASET}.lookups\``;
- const results = await bigquery.query({
+ const results = await bigquery.query<{ baseDomain: string }>({
query: `
SELECT baseDomain
FROM ${tableName}
@@ -82,5 +82,5 @@ export const getTopDomains = async (count: number) => {
`,
});
- return results.map((row: any) => row.baseDomain) as string[];
+ return results.map((row) => row.baseDomain);
};