File tree Expand file tree Collapse file tree 6 files changed +54
-29
lines changed
routes/api/archive-metadata Expand file tree Collapse file tree 6 files changed +54
-29
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import axios from "axios";
88 * @return
99 */
1010const querySql = async < T > ( queryString : string ) => {
11- return axios . post < T > ( "/query /sql" , { queryString} ) ;
11+ return axios . post < T > ( "/api/archive-metadata /sql" , { queryString} ) ;
1212} ;
1313
1414export { querySql } ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ const EslintConfig = [
2222 {
2323 // TypeBox imports
2424 capIsNewExceptions : [
25+ "Type.Any" ,
2526 "Type.Enum" ,
2627 "Type.Integer" ,
2728 "Type.Literal" ,
Original file line number Diff line number Diff line change 1+ import {
2+ FastifyPluginAsyncTypebox ,
3+ Type ,
4+ } from "@fastify/type-provider-typebox" ;
5+ import { StatusCodes } from "http-status-codes" ;
6+
7+ import { SqlSchema } from "../../../schemas/archive-metadata.js" ;
8+
9+
10+ /**
11+ * Archive metadata API routes.
12+ *
13+ * @param fastify
14+ */
15+ const plugin : FastifyPluginAsyncTypebox = async ( fastify ) => {
16+ const mysqlConnectionPool = fastify . mysql . pool ;
17+
18+ fastify . post (
19+ "/sql" ,
20+ {
21+ schema : {
22+ body : SqlSchema ,
23+ response : {
24+ [ StatusCodes . OK ] : Type . Any ( ) ,
25+ } ,
26+ tags : [ "Archive Metadata" ] ,
27+ } ,
28+ } ,
29+ async ( req , reply ) => {
30+ const { queryString} = req . body ;
31+ const [ result ] = await mysqlConnectionPool . query ( queryString ) ;
32+ reply . code ( StatusCodes . OK ) ;
33+
34+ return result ;
35+ } ,
36+ ) ;
37+ } ;
38+
39+ export default plugin ;
Original file line number Diff line number Diff line change 1+ import { Type } from "@sinclair/typebox" ;
2+
3+ import { StringSchema } from "./common.js" ;
4+
5+
6+ /**
7+ * Schema for SQL query request.
8+ */
9+ const SqlSchema = Type . Object ( {
10+ queryString : StringSchema ,
11+ } ) ;
12+
13+ export { SqlSchema } ;
Original file line number Diff line number Diff line change @@ -82,18 +82,6 @@ class DbManager {
8282 } ) ;
8383 }
8484
85- /**
86- * Submits a query to MySQL.
87- *
88- * @param queryString
89- * @return The result from MySQL.
90- */
91- async queryMySql ( queryString : string ) {
92- const [ result ] = await this . #mysqlConnectionPool. query ( queryString ) ;
93- return result ;
94- }
95-
96-
9785 /**
9886 * Submits a stream extraction job to the scheduler and waits for it to finish.
9987 *
Original file line number Diff line number Diff line change @@ -16,25 +16,9 @@ import {
1616 * @param app
1717 * @return
1818 */
19- // eslint-disable-next-line max-lines-per-function
2019const routes : FastifyPluginAsync = async ( app ) => {
2120 const fastify = app . withTypeProvider < TypeBoxTypeProvider > ( ) ;
2221
23- fastify . post (
24- "/query/sql" ,
25- {
26- schema : {
27- body : Type . Object ( {
28- queryString : Type . String ( { minLength : 1 } ) ,
29- } ) ,
30- } ,
31- } ,
32- async ( req ) => {
33- const { queryString} = req . body ;
34- return await fastify . dbManager . queryMySql ( queryString ) ;
35- } ,
36- ) ;
37-
3822 fastify . post ( "/query/extract-stream" , {
3923 schema : {
4024 body : Type . Object ( {
You can’t perform that action at this time.
0 commit comments