Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$%7Bsuccess?q=database&page=224&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=database

Returns an array of strings in format "username" or "username/projectName"

Found 7026 results for "database"(1026ms)

offlineexamappExamResults.tsx1 match

@chrisboss•Updated 2 weeks ago
4import { useAuth } from "../../hooks/useAuth";
5import { useExamService } from "../../hooks/useExamService";
6import { Attempt, Exam, Question, Answer } from "../../../shared/database/schema";
7
8interface QuestionWithAnswer extends Question {

offlineexamappTakeExam.tsx2 matches

@chrisboss•Updated 2 weeks ago
4import { useAuth } from "../../hooks/useAuth";
5import { useExamService } from "../../hooks/useExamService";
6import { Exam, Question, Attempt } from "../../../shared/database/schema";
7
8const TakeExam: React.FC = () => {
128 }));
129
130 // Save answer to database
131 if (attempt) {
132 const currentQuestion = questions[currentQuestionIndex];

offlineexamappDashboard.tsx1 match

@chrisboss•Updated 2 weeks ago
4import { useAuth } from "../../hooks/useAuth";
5import { useExamService } from "../../hooks/useExamService";
6import { Exam, Attempt } from "../../../shared/database/schema";
7
8const StudentDashboard: React.FC = () => {

offlineexamappRegister.tsx1 match

@chrisboss•Updated 2 weeks ago
3import { useNavigate, Link } from "https://esm.sh/react-router-dom@6.20.1?deps=react@18.2.0";
4import { useAuth } from "../hooks/useAuth";
5import { UserRole } from "../../shared/database/schema";
6
7const Register: React.FC = () => {

offlineexamappuseExamService.ts2 matches

@chrisboss•Updated 2 weeks ago
1import { useMemo } from "https://esm.sh/react@18.2.0";
2import { useDatabase } from "./useDatabase";
3import { ExamService } from "../services/examService";
4
5export const useExamService = () => {
6 const { db, isInitialized } = useDatabase();
7
8 const examService = useMemo(() => {

offlineexamappexamService.ts3 matches

@chrisboss•Updated 2 weeks ago
5 Attempt,
6 Answer
7} from "../../shared/database/schema";
8
9/**
11 */
12export class ExamService {
13 private db: IDBDatabase;
14
15 constructor(db: IDBDatabase) {
16 this.db = db;
17 }

offlineexamappuseDatabase.ts3 matches

@chrisboss•Updated 2 weeks ago
1import { useContext } from "https://esm.sh/react@18.2.0";
2import { DatabaseContext } from "../contexts/DatabaseContext";
3
4export const useDatabase = () => {
5 return useContext(DatabaseContext);
6};

offlineexamappAuthContext.tsx8 matches

@chrisboss•Updated 2 weeks ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { createContext, useState, useEffect } from "https://esm.sh/react@18.2.0";
3import { useDatabase } from "../hooks/useDatabase";
4import { User } from "../../shared/database/schema";
5
6interface AuthContextType {
27
28export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
29 const { db, isInitialized } = useDatabase();
30 const [user, setUser] = useState<User | null>(null);
31 const [isLoading, setIsLoading] = useState(true);
43 const userData = JSON.parse(storedUser) as User;
44
45 // Verify that the user still exists in the database
46 if (db) {
47 const transaction = db.transaction(["users"], "readonly");
53 setUser(userData);
54 } else {
55 // User no longer exists in the database
56 localStorage.removeItem("currentUser");
57 }
79 // Login function
80 const login = async (username: string, password: string): Promise<void> => {
81 if (!db) throw new Error("Database not initialized");
82
83 setIsLoading(true);
150 // Register function
151 const register = async (userData: Omit<User, "id" | "createdAt" | "lastLogin">): Promise<void> => {
152 if (!db) throw new Error("Database not initialized");
153
154 setIsLoading(true);
242 // Update user function
243 const updateUser = async (userData: Partial<User>): Promise<void> => {
244 if (!db || !user) throw new Error("Database not initialized or user not logged in");
245
246 setIsLoading(true);

offlineexamappDatabaseContext.tsx26 matches

@chrisboss•Updated 2 weeks ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { createContext, useState, useEffect } from "https://esm.sh/react@18.2.0";
3import { initDatabase, seedData, DB_CONFIG } from "../../shared/database/schema";
4
5interface DatabaseContextType {
6 db: IDBDatabase | null;
7 isInitialized: boolean;
8 error: Error | null;
9}
10
11export const DatabaseContext = createContext<DatabaseContextType>({
12 db: null,
13 isInitialized: false,
15});
16
17export const DatabaseProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
18 const [db, setDb] = useState<IDBDatabase | null>(null);
19 const [isInitialized, setIsInitialized] = useState(false);
20 const [error, setError] = useState<Error | null>(null);
21
22 useEffect(() => {
23 const initializeDatabase = async () => {
24 try {
25 // Initialize the database
26 const database = await initDatabase();
27 setDb(database);
28
29 // Check if we need to seed the database
30 const needsSeed = await checkIfNeedsSeed(database);
31
32 if (needsSeed) {
33 await seedDatabase(database);
34 }
35
36 setIsInitialized(true);
37 } catch (err) {
38 console.error("Failed to initialize database:", err);
39 setError(err instanceof Error ? err : new Error(String(err)));
40 }
41 };
42
43 initializeDatabase();
44
45 return () => {
46 // Close the database connection when the component unmounts
47 if (db) {
48 db.close();
51 }, []);
52
53 // Check if the database needs to be seeded
54 const checkIfNeedsSeed = async (database: IDBDatabase): Promise<boolean> => {
55 return new Promise((resolve) => {
56 const transaction = database.transaction(["users"], "readonly");
57 const store = transaction.objectStore("users");
58 const countRequest = store.count();
59
60 countRequest.onsuccess = () => {
61 // If there are no users, we need to seed the database
62 resolve(countRequest.result === 0);
63 };
70 };
71
72 // Seed the database with initial data
73 const seedDatabase = async (database: IDBDatabase): Promise<void> => {
74 return new Promise((resolve, reject) => {
75 const transaction = database.transaction(
76 Object.keys(DB_CONFIG.stores),
77 "readwrite"
79
80 transaction.onerror = () => {
81 reject(new Error("Failed to seed database"));
82 };
83
113
114 return (
115 <DatabaseContext.Provider value={{ db, isInitialized, error }}>
116 {children}
117 </DatabaseContext.Provider>
118 );
119};

offlineexamappschema.ts5 matches

@chrisboss•Updated 2 weeks ago
1/**
2 * Database Schema for the Nigerian Mock Exam Application
3 *
4 * This file defines the IndexedDB schema and types for the application.
5 */
6
7// Database configuration
8export const DB_CONFIG = {
9 name: "NigerianMockExamDB",
102}
103
104// Database initialization function
105export async function initDatabase(): Promise<IDBDatabase> {
106 return new Promise((resolve, reject) => {
107 const request = indexedDB.open(DB_CONFIG.name, DB_CONFIG.version);
108
109 request.onerror = (event) => {
110 reject(new Error("Failed to open database"));
111 };
112

bookmarksDatabase

@s3thi•Updated 3 months ago

sqLiteDatabase1 file match

@ideofunk•Updated 6 months ago