Back

Version 70

11/13/2024
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS SCHEDULE (
id DATETIME PRIMARY KEY,
file TEXT
)
`);
export async function schedulePush(id: Date, file: string,index:number) {
console.log(id.toISOString(), file);
await sqlite.execute(
`INSERT INTO SCHEDULE (id,file,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() {
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.mp3");
}
}
let index = 1;
// await sqlite.execute(`DELETE FROM SCHEDULE`);
Updated: November 15, 2024