Initial commit — AI-powered coding tutor (Professor)
Next.js 16, React 19, Monaco editor, Anthropic SDK, multi-provider AI, Wandbox Python execution, iframe HTML preview, SQLite auth + session persistence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
18
db/index.ts
Normal file
18
db/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
||||
import * as schema from './schema';
|
||||
|
||||
type DrizzleDb = ReturnType<typeof drizzle<typeof schema>>;
|
||||
const globalForDb = globalThis as unknown as { _professorDb?: DrizzleDb };
|
||||
|
||||
function createDb(): DrizzleDb {
|
||||
const sqlite = new Database('professor.db');
|
||||
sqlite.pragma('journal_mode = WAL');
|
||||
return drizzle(sqlite, { schema });
|
||||
}
|
||||
|
||||
export const db: DrizzleDb = globalForDb._professorDb ?? createDb();
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalForDb._professorDb = db;
|
||||
}
|
||||
21
db/schema.ts
Normal file
21
db/schema.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { text, sqliteTable } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
export const users = sqliteTable('users', {
|
||||
id: text('id').primaryKey(),
|
||||
email: text('email').notNull().unique(),
|
||||
passwordHash: text('password_hash').notNull(),
|
||||
createdAt: text('created_at').notNull(),
|
||||
});
|
||||
|
||||
export const savedSessions = sqliteTable('saved_sessions', {
|
||||
id: text('id').primaryKey(),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
topicId: text('topic_id'),
|
||||
taskJson: text('task_json'),
|
||||
code: text('code'),
|
||||
messagesJson: text('messages_json'),
|
||||
executionResultJson: text('execution_result_json'),
|
||||
updatedAt: text('updated_at').notNull(),
|
||||
});
|
||||
Reference in New Issue
Block a user