part1
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { CREATE } from '../../sql/language.js';
|
||||
import request from '../request.js';
|
||||
|
||||
/**
|
||||
* Creates a new language by its ISO 639 code.
|
||||
*
|
||||
* @param {object} pool - The mssql connection pool.
|
||||
* @returns {Function} An async function that creates a language.
|
||||
*
|
||||
* @example
|
||||
* const fn = create(pool);
|
||||
* const id = await fn('de');
|
||||
* // => 1
|
||||
*/
|
||||
export default function create(pool) {
|
||||
/**
|
||||
* Creates a new language 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<number>} The id of the created language.
|
||||
*
|
||||
* @example
|
||||
* const id = await store.lang.create('de');
|
||||
* // => 1
|
||||
*/
|
||||
return async (iso639, tx) => {
|
||||
const result = await request(pool, tx)
|
||||
.input('iso639', iso639)
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { DELETE } from '../../sql/language.js';
|
||||
|
||||
/**
|
||||
* Deletes a language by its id.
|
||||
*
|
||||
* @param {object} pool - The mssql connection pool.
|
||||
* @returns {Function} An async function that deletes a language.
|
||||
*
|
||||
* @example
|
||||
* const fn = del(pool);
|
||||
* await fn(1);
|
||||
*/
|
||||
export default function del(pool) {
|
||||
/**
|
||||
* Deletes a language by its id.
|
||||
*
|
||||
* @param {number} id - The id of the language to delete.
|
||||
* @returns {Promise<void>}
|
||||
*
|
||||
* @example
|
||||
* await store.lang.delete(1);
|
||||
*/
|
||||
return async (id) => {
|
||||
await pool
|
||||
.request()
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import getByIso639 from './getByIso639.js';
|
||||
import create from './create.js';
|
||||
|
||||
/**
|
||||
* Returns the id of a language by ISO code, creating it if it does not exist.
|
||||
*
|
||||
* @param {object} pool - The mssql connection pool.
|
||||
* @returns {Function} An async function that ensures a language exists.
|
||||
*
|
||||
* @example
|
||||
* const fn = ensure(pool);
|
||||
* const id = await fn('de');
|
||||
* // => 1
|
||||
*/
|
||||
export default function ensure(pool) {
|
||||
const get = getByIso639(pool);
|
||||
const add = create(pool);
|
||||
/**
|
||||
* Returns the id of a language by ISO code, creating it if it does not exist.
|
||||
*
|
||||
* @param {string} iso639 - The ISO 639 language code (e.g. `'de'`).
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<number>} The id of the language.
|
||||
*
|
||||
* @example
|
||||
* const id = await store.lang.ensure('de');
|
||||
* // => 1
|
||||
*/
|
||||
return async (iso639, tx) => {
|
||||
const row = await get(iso639, tx);
|
||||
if (row) return row.id;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { GET_BY_ISO639 } from '../../sql/language.js';
|
||||
import request from '../request.js';
|
||||
|
||||
/**
|
||||
* Returns a language row by its ISO 639 code.
|
||||
*
|
||||
* @param {object} pool - The mssql connection pool.
|
||||
* @returns {Function} An async function that fetches a language by ISO code.
|
||||
*
|
||||
* @example
|
||||
* const fn = getByIso639(pool);
|
||||
* const lang = await fn('de');
|
||||
* // => { id, iso639 }
|
||||
*/
|
||||
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)
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import { LIST } from '../../sql/language.js';
|
||||
|
||||
/**
|
||||
* Lists all languages.
|
||||
*
|
||||
* @param {object} pool - The mssql connection pool.
|
||||
* @returns {Function} An async function that lists languages.
|
||||
*
|
||||
* @example
|
||||
* const fn = list(pool);
|
||||
* const languages = await fn();
|
||||
* // => [{ id, iso639 }]
|
||||
*/
|
||||
export default function list(pool) {
|
||||
/**
|
||||
* Lists all languages.
|
||||
*
|
||||
* @returns {Promise<Array<{id: number, iso639: string}>>} All language rows.
|
||||
*
|
||||
* @example
|
||||
* const languages = await store.lang.list();
|
||||
* // => [{ id: 1, iso639: 'de' }]
|
||||
*/
|
||||
return async () => {
|
||||
const result = await pool.request().query(LIST);
|
||||
return result.recordset;
|
||||
|
||||
Reference in New Issue
Block a user