style(lib): standardize events-db file formatting
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { openDB, type IDBPDatabase } from 'idb';
|
import { openDB, type IDBPDatabase } from "idb";
|
||||||
import type { CalendarEvent } from '@/lib/types';
|
import type { CalendarEvent } from "@/lib/types";
|
||||||
|
|
||||||
const DB_NAME = 'LocalCalEvents';
|
const DB_NAME = "LocalCalEvents";
|
||||||
const DB_VERSION = 1;
|
const DB_VERSION = 1;
|
||||||
const EVENTS_STORE = 'events';
|
const EVENTS_STORE = "events";
|
||||||
|
|
||||||
let dbPromise: Promise<IDBPDatabase> | null = null;
|
let dbPromise: Promise<IDBPDatabase> | null = null;
|
||||||
|
|
||||||
@@ -12,9 +12,9 @@ function getDB() {
|
|||||||
dbPromise = openDB(DB_NAME, DB_VERSION, {
|
dbPromise = openDB(DB_NAME, DB_VERSION, {
|
||||||
upgrade(db) {
|
upgrade(db) {
|
||||||
if (!db.objectStoreNames.contains(EVENTS_STORE)) {
|
if (!db.objectStoreNames.contains(EVENTS_STORE)) {
|
||||||
const store = db.createObjectStore(EVENTS_STORE, { keyPath: 'id' });
|
const store = db.createObjectStore(EVENTS_STORE, { keyPath: "id" });
|
||||||
store.createIndex('start', 'start');
|
store.createIndex("start", "start");
|
||||||
store.createIndex('title', 'title');
|
store.createIndex("title", "title");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -47,10 +47,13 @@ export async function updateEvent(event: CalendarEvent): Promise<void> {
|
|||||||
await db.put(EVENTS_STORE, event);
|
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 db = await getDB();
|
||||||
const tx = db.transaction(EVENTS_STORE, 'readonly');
|
const tx = db.transaction(EVENTS_STORE, "readonly");
|
||||||
const index = tx.store.index('start');
|
const index = tx.store.index("start");
|
||||||
const events = await index.getAll(IDBKeyRange.bound(startDate, endDate));
|
const events = await index.getAll(IDBKeyRange.bound(startDate, endDate));
|
||||||
await tx.done;
|
await tx.done;
|
||||||
return events;
|
return events;
|
||||||
|
|||||||
Reference in New Issue
Block a user