@@ -55,51 +55,18 @@ export default async (fastify: FastifyInstance) => {
55
55
return data
56
56
} )
57
57
58
- fastify . get < {
59
- Headers : { pg : string }
60
- Body : any
61
- } > ( '/batch' , async ( request , reply ) => {
62
- const connectionString = request . headers . pg
63
- const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
64
- const { data, error } = await pgMeta . columns . batchRetrieve ( { ids : request . body } )
65
- await pgMeta . end ( )
66
- if ( error ) {
67
- request . log . error ( { error, request : extractRequestForLogging ( request ) } )
68
- reply . code ( 400 )
69
- if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
70
- return { error : error . message }
71
- }
72
-
73
- return data
74
- } )
75
-
76
58
// deprecated: use POST /batch instead
77
59
// TODO (darora): specifying a schema on the routes would both allow for validation, and enable us to mark methods as deprecated
78
60
fastify . post < {
79
61
Headers : { pg : string }
80
62
Body : any
81
63
} > ( '/' , async ( request , reply ) => {
82
64
const connectionString = request . headers . pg
83
-
84
65
const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
85
- const { data, error } = await pgMeta . columns . create ( request . body )
86
- await pgMeta . end ( )
87
- if ( error ) {
88
- request . log . error ( { error, request : extractRequestForLogging ( request ) } )
89
- reply . code ( 400 )
90
- if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
91
- return { error : error . message }
66
+ if ( ! Array . isArray ( request . body ) ) {
67
+ request . body = [ request . body ]
92
68
}
93
- return data
94
- } )
95
69
96
- fastify . post < {
97
- Headers : { pg : string }
98
- Body : any
99
- } > ( '/batch' , async ( request , reply ) => {
100
- const connectionString = request . headers . pg
101
-
102
- const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
103
70
const { data, error } = await pgMeta . columns . batchCreate ( request . body )
104
71
await pgMeta . end ( )
105
72
if ( error ) {
@@ -108,7 +75,11 @@ export default async (fastify: FastifyInstance) => {
108
75
if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
109
76
return { error : error . message }
110
77
}
111
- return data
78
+
79
+ if ( Array . isArray ( request . body ) ) {
80
+ return data
81
+ }
82
+ return data [ 0 ]
112
83
} )
113
84
114
85
fastify . patch < {
0 commit comments