24 lines
723 B
JavaScript
24 lines
723 B
JavaScript
import { GET_BY_ISO639 } from '../../sql/language.js';
|
|
import request from '../request.js';
|
|
|
|
export default function getByIso639(pool) {
|
|
/**
|
|
* Returns a language row by its ISO 639 code.
|
|
*
|
|
* @param {string} iso639 - The ISO 639 language code (e.g. `'de'`).
|
|
* @param {object} [tx] - Optional transaction to run within.
|
|
* @returns {Promise<{id: number, iso639: string}>} The language row, or `undefined` if not found.
|
|
*
|
|
* @example
|
|
* const lang = await store.lang.getByIso639('de');
|
|
* // => { id: 1, iso639: 'de' }
|
|
*/
|
|
return async (iso639, tx) => {
|
|
const result = await request(pool, tx)
|
|
.input('iso639', iso639)
|
|
.query(GET_BY_ISO639);
|
|
|
|
return result.recordset[0];
|
|
};
|
|
}
|