core/source/logic/state_repository.ts

38 lines
831 B
TypeScript
Raw Normal View History

2023-06-19 13:05:17 +02:00
namespace _heimdall.state_repository
{
/**
*/
export async function setup(
database_path : string,
) : Promise<void>
{
const result = await _heimdall.helpers.sqlite.query_set(
database_path,
"CREATE TABLE IF NOT EXISTS results(check_name TEXT NOT NULL, timestamp INTEGER NOT NULL, condition TEXT NOT NULL, notification_sent BOOLEAN NOT NULL, info TEXT NOT NULL);",
{}
);
}
/**
*/
export async function clean(
database_path : string,
time_to_live : int,
erase_state : boolean,
) : Promise<int>
{
const result = await _heimdall.helpers.sqlite.query_put(
database_path,
"DELETE FROM results WHERE ((timestamp < :timestamp_min) OR :erase_state);",
{
"timestamp_min": ((Date.now() / 1000) - time_to_live),
"erase_state": erase_state,
}
);
return result.rowcount;
}
}