-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
many.js
38 lines (31 loc) · 772 Bytes
/
many.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// @flow
import {
createQueryId
} from '../utilities';
import {
NotFoundError
} from '../errors';
import type {
InternalQueryManyFunctionType
} from '../types';
import log from '../Logger';
import query from './query';
/**
* Makes a query and expects at least 1 result.
*
* @throws NotFoundError If query returns no rows.
*/
const many: InternalQueryManyFunctionType = async (connection, clientConfiguration, rawSql, values, inheritedQueryId) => {
const queryId = inheritedQueryId || createQueryId();
const {
rows
} = await query(connection, clientConfiguration, rawSql, values, queryId);
if (rows.length === 0) {
log.error({
queryId
}, 'NotFoundError');
throw new NotFoundError();
}
return rows;
};
export default many;