style(lib): standardize events-db file formatting

This commit is contained in:
2026-04-07 08:09:36 -04:00
parent dab77befc2
commit 5be55cec7c

View File

@@ -1,9 +1,9 @@
import { openDB, type IDBPDatabase } from 'idb';
import type { CalendarEvent } from '@/lib/types';
import { openDB, type IDBPDatabase } from "idb";
import type { CalendarEvent } from "@/lib/types";
const DB_NAME = 'LocalCalEvents';
const DB_NAME = "LocalCalEvents";
const DB_VERSION = 1;
const EVENTS_STORE = 'events';
const EVENTS_STORE = "events";
let dbPromise: Promise<IDBPDatabase> | null = null;
@@ -12,9 +12,9 @@ function getDB() {
dbPromise = openDB(DB_NAME, DB_VERSION, {
upgrade(db) {
if (!db.objectStoreNames.contains(EVENTS_STORE)) {
const store = db.createObjectStore(EVENTS_STORE, { keyPath: 'id' });
store.createIndex('start', 'start');
store.createIndex('title', 'title');
const store = db.createObjectStore(EVENTS_STORE, { keyPath: "id" });
store.createIndex("start", "start");
store.createIndex("title", "title");
}
},
});
@@ -47,10 +47,13 @@ export async function updateEvent(event: CalendarEvent): Promise<void> {
await db.put(EVENTS_STORE, event);
}
export async function getEventsByDateRange(startDate: string, endDate: string): Promise<CalendarEvent[]> {
export async function getEventsByDateRange(
startDate: string,
endDate: string,
): Promise<CalendarEvent[]> {
const db = await getDB();
const tx = db.transaction(EVENTS_STORE, 'readonly');
const index = tx.store.index('start');
const tx = db.transaction(EVENTS_STORE, "readonly");
const index = tx.store.index("start");
const events = await index.getAll(IDBKeyRange.bound(startDate, endDate));
await tx.done;
return events;