query grade distributions working, and filtering by semesters working

This commit is contained in:
Sriram Hariharan
2023-03-09 16:11:42 -06:00
parent 5be0cbbbf1
commit e60242198a
19 changed files with 1123 additions and 73 deletions

View File

@@ -0,0 +1,35 @@
import initSqlJs from 'sql.js/dist/sql-wasm';
const WASM_FILE_URL = chrome.runtime.getURL('database/sql-wasm.wasm');
const DB_FILE_URL = chrome.runtime.getURL('database/grades.db');
/**
* A utility type for the SQL.js Database type
*/
export type Database = initSqlJs.Database;
/**
* We only want to load the database into memory once, so we store a reference to the database here.
*/
let db: Database;
/**
* This function loads the database into memory and returns a reference to the sql.js Database object.
* @returns a reference to the sql.js Database object
*/
export async function initializeDB(): Promise<Database> {
if (!WASM_FILE_URL || !DB_FILE_URL) {
throw new Error('WASM_FILE_URL or DB_FILE_URL is undefined');
}
if (db) {
return db;
}
const { Database } = await initSqlJs({
locateFile: file => WASM_FILE_URL,
});
const dbBuffer = await fetch(DB_FILE_URL).then(res => res.arrayBuffer());
db = new Database(new Uint8Array(dbBuffer));
return db;
}