diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index 7c7da5c7..57a1e99d 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -167,7 +167,7 @@ const subroutine = async ( return results; }; -const query = (script: string) => +const query = (script: string) => access.interact('r', formatSql(script)); const write = async (script: string) => { diff --git a/striker-ui-api/src/lib/buildQueryResultModifier.ts b/striker-ui-api/src/lib/buildQueryResultModifier.ts index 9f32c641..7f4b24be 100644 --- a/striker-ui-api/src/lib/buildQueryResultModifier.ts +++ b/striker-ui-api/src/lib/buildQueryResultModifier.ts @@ -1,12 +1,10 @@ -type QueryField = string; - export const buildQueryResultModifier = - (mod: (output: QueryField[][]) => T): QueryResultModifierFunction => + (mod: (output: string[][]) => T): QueryResultModifierFunction => (output) => output instanceof Array ? mod(output) : output; export const buildQueryResultReducer = ( - reduce: (previous: T, row: QueryField[]) => T, + reduce: (previous: T, row: string[]) => T, initialValue: T, ) => buildQueryResultModifier((output) => diff --git a/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts b/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts index fcb65376..e2cf4b61 100644 --- a/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts +++ b/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts @@ -14,7 +14,7 @@ const buildGetRequestHandler = const buildQueryOptions: BuildQueryOptions = {}; - let result: (number | null | string)[][]; + let result: unknown; try { const sqlscript: string = @@ -26,9 +26,7 @@ const buildGetRequestHandler = } catch (queryError) { stderr(`Failed to execute query; CAUSE: ${queryError}`); - response.status(500).send(); - - return; + return response.status(500).send(); } stdoutVar(result, `Query stdout pre-hooks (type=[${typeof result}]): `); diff --git a/striker-ui-api/src/types/BuildQueryFunction.d.ts b/striker-ui-api/src/types/BuildQueryFunction.d.ts index ead3207d..c59e1a34 100644 --- a/striker-ui-api/src/types/BuildQueryFunction.d.ts +++ b/striker-ui-api/src/types/BuildQueryFunction.d.ts @@ -1,5 +1,3 @@ -type QueryResultModifierFunction = (output: unknown) => unknown; - type BuildQueryOptions = { afterQueryReturn?: QueryResultModifierFunction; }; diff --git a/striker-ui-api/src/types/QueryResult.d.ts b/striker-ui-api/src/types/QueryResult.d.ts new file mode 100644 index 00000000..0996cc51 --- /dev/null +++ b/striker-ui-api/src/types/QueryResult.d.ts @@ -0,0 +1,5 @@ +type QueryField = number | null | string; + +type QueryRow = QueryField[]; + +type QueryResult = QueryRow[]; diff --git a/striker-ui-api/src/types/QueryResultModifierFunction.d.ts b/striker-ui-api/src/types/QueryResultModifierFunction.d.ts new file mode 100644 index 00000000..b97744ac --- /dev/null +++ b/striker-ui-api/src/types/QueryResultModifierFunction.d.ts @@ -0,0 +1 @@ +type QueryResultModifierFunction = (output: unknown) => unknown;