Initial commit: CV website with ElysiaJS, SQLite, and TailwindCSS

This commit is contained in:
Tuan-Dat Tran
2025-11-21 20:07:05 +01:00
parent 378487efc8
commit 88aeaa9002
14 changed files with 759 additions and 109 deletions

118
src/db/queries.ts Normal file
View File

@@ -0,0 +1,118 @@
import { db } from "./schema";
interface ProfileTranslation {
name: string;
job_title: string;
summary: string | null;
location: string | null;
}
interface Profile extends ProfileTranslation {
email: string;
phone: string | null;
website: string | null;
github_url: string | null;
linkedin_url: string | null;
avatar_url: string | null;
}
interface ExperienceTranslation {
company_name: string;
role: string;
description: string | null;
location: string | null;
}
interface Experience extends ExperienceTranslation {
start_date: string;
end_date: string | null;
company_url: string | null;
}
interface SkillTranslation {
name: string;
category_display: string | null;
}
interface Skill extends SkillTranslation {
category: string;
icon: string | null;
display_order: number;
}
export function getProfile(lang: string): Profile | null {
const profile = db.query(`
SELECT p.email, p.phone, p.website, p.github_url, p.linkedin_url, p.avatar_url,
pt.name, pt.job_title, pt.summary, pt.location
FROM profile p
JOIN profile_translations pt ON p.id = pt.profile_id
WHERE pt.language_code = $lang
`).get({ $lang: lang }) as Profile | null;
return profile;
}
export function getExperience(lang: string): Experience[] {
const experience = db.query(`
SELECT e.start_date, e.end_date, e.company_url, e.display_order,
et.company_name, et.role, et.description, et.location
FROM experience e
JOIN experience_translations et ON e.id = et.experience_id
WHERE et.language_code = $lang
ORDER BY e.display_order ASC, e.start_date DESC
`).all({ $lang: lang }) as Experience[];
return experience;
}
export function getSkills(lang: string): Skill[] {
const skills = db.query(`
SELECT s.category, s.icon, s.display_order,
st.name, st.category_display
FROM skills s
JOIN skill_translations st ON s.id = st.skill_id
WHERE st.language_code = $lang
ORDER BY s.display_order ASC, s.category ASC, st.name ASC
`).all({ $lang: lang }) as Skill[];
return skills;
}
export function getEducation(lang: string): Education[] {
const education = db.query(`
SELECT e.start_date, e.end_date, e.institution_url, e.display_order,
et.institution, et.degree, et.description
FROM education e
JOIN education_translations et ON e.id = et.education_id
WHERE et.language_code = $lang
ORDER BY e.display_order ASC, e.start_date DESC
`).all({ $lang: lang }) as Education[];
return education;
}
export function getAllData(lang: string) {
return {
profile: getProfile(lang),
experience: getExperience(lang),
education: getEducation(lang),
skills: getSkills(lang),
};
}