Back

Version 78

11/13/2024
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
// SWITCH await sqlite.execute(`DROP TABLE IF EXISTS SCHEDULE;`)
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS SCHEDULE (
id DATETIME PRIMARY KEY,
file TEXT,
p_index INTEGER
)
`);
export async function schedulePush(id: Date, file: string, index: number) {
console.log(id.toISOString(), file);
await sqlite.execute(
`INSERT INTO SCHEDULE (id,file,p_index) VALUES ('${id.toISOString()}','${file}',${index})`,
);
}
export async function schedulePurge(id: Date) {
await sqlite.execute(
`DELETE FROM SCHEDULE WHERE id < '${id.toISOString()}'`,
);
}
export async function scheduleRead() {
const current = new Date();
const normalized = new Date();
normalized.setSeconds(normalized.getSeconds() + 10);
const result = await sqlite.execute(`SELECT * FROM SCHEDULE WHERE id < '${normalized.toISOString()}' LIMIT 10`);
return result.rows;
}
export async function pushRandomData(index: number) {
await schedulePurge(new Date()); // Clear previous entries

const baseDate = new Date();
for (let i = 0; i < 100; i++) {
baseDate.setSeconds(baseDate.getSeconds() + 10); // 10 seconds in milliseconds
await schedulePush(baseDate, "/audio/hello.mp", index);
index += 1;
}
Updated: November 15, 2024