backend/source/repositories/name_index.ts

75 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-04-29 22:40:52 +02:00
namespace _espe.repository.name_index
2024-04-29 20:48:20 +02:00
{
/**
*/
var _chest : (
null
|
lib_plankton.storage.type_chest<
Array<any>,
Record<string, any>,
lib_plankton.database.type_description_create_table,
2024-04-29 22:40:52 +02:00
lib_plankton.storage.sql_table_common.type_sql_table_common_search_term,
2024-04-29 20:48:20 +02:00
Record<string, any>
>
) = null;
/**
*/
function get_chest(
) : lib_plankton.storage.type_chest<
Array<any>,
Record<string, any>,
lib_plankton.database.type_description_create_table,
2024-04-29 22:40:52 +02:00
lib_plankton.storage.sql_table_common.type_sql_table_common_search_term,
2024-04-29 20:48:20 +02:00
Record<string, any>
>
{
if (_chest === null) {
2024-04-29 22:40:52 +02:00
_chest = lib_plankton.storage.sql_table_common.chest(
2024-04-29 20:48:20 +02:00
{
"database_implementation": _espe.helpers.database_implementation(),
"table_name": "name_indices",
"key_names": ["name_image"],
}
);
}
else {
// do nothing
}
return _chest;
}
/**
*/
export async function read(
name : string
) : Promise<int>
{
let row : Record<string, any>;
try {
2024-04-29 22:40:52 +02:00
row = await get_chest().read([name]);
2024-04-29 20:48:20 +02:00
return row["index"];
}
catch (error) {
return 0;
}
}
/**
*/
export async function write(
name : string,
index : int
) : Promise<void>
{
2024-04-29 22:40:52 +02:00
await get_chest().write([name], {"index": index});
2024-04-29 20:48:20 +02:00
}
}