mirror of
https://github.com/gevera/hot-cold-cities.git
synced 2025-12-06 07:08:20 +00:00
Added Sqlite DB
This commit is contained in:
parent
11a4c240e7
commit
c91b94b392
9
bun.lock
9
bun.lock
@ -12,6 +12,7 @@
|
||||
"@tailwindcss/forms": "^0.5.9",
|
||||
"@tailwindcss/typography": "^0.5.15",
|
||||
"@tailwindcss/vite": "^4.0.0",
|
||||
"bun-types": "^1.2.4",
|
||||
"daisyui": "^5.0.0",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
@ -218,8 +219,12 @@
|
||||
|
||||
"@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
|
||||
|
||||
"@types/node": ["@types/node@22.13.8", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-G3EfaZS+iOGYWLLRCEAXdWK9my08oHNZ+FHluRiggIYJPOXzhOiDgpVCUHaUvyIC5/fj7C/p637jdzC666AOKQ=="],
|
||||
|
||||
"@types/resolve": ["@types/resolve@1.20.2", "", {}, "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q=="],
|
||||
|
||||
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
|
||||
|
||||
"@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.25.0", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.25.0", "@typescript-eslint/type-utils": "8.25.0", "@typescript-eslint/utils": "8.25.0", "@typescript-eslint/visitor-keys": "8.25.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", "ts-api-utils": "^2.0.1" }, "peerDependencies": { "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.8.0" } }, "sha512-VM7bpzAe7JO/BFf40pIT1lJqS/z1F8OaSsUB3rpFJucQA4cOSuH2RVVVkFULN+En0Djgr29/jb4EQnedUo95KA=="],
|
||||
|
||||
"@typescript-eslint/parser": ["@typescript-eslint/parser@8.25.0", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.25.0", "@typescript-eslint/types": "8.25.0", "@typescript-eslint/typescript-estree": "8.25.0", "@typescript-eslint/visitor-keys": "8.25.0", "debug": "^4.3.4" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.8.0" } }, "sha512-4gbs64bnbSzu4FpgMiQ1A+D+urxkoJk/kqlDJ2W//5SygaEiAP2B4GoS7TEdxgwol2el03gckFV9lJ4QOMiiHg=="],
|
||||
@ -258,6 +263,8 @@
|
||||
|
||||
"braces": ["braces@3.0.3", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="],
|
||||
|
||||
"bun-types": ["bun-types@1.2.4", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-nDPymR207ZZEoWD4AavvEaa/KZe/qlrbMSchqpQwovPZCKc7pwMoENjEtHgMKaAjJhy+x6vfqSBA1QU3bJgs0Q=="],
|
||||
|
||||
"callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="],
|
||||
|
||||
"chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="],
|
||||
@ -552,6 +559,8 @@
|
||||
|
||||
"typescript-eslint": ["typescript-eslint@8.25.0", "", { "dependencies": { "@typescript-eslint/eslint-plugin": "8.25.0", "@typescript-eslint/parser": "8.25.0", "@typescript-eslint/utils": "8.25.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.8.0" } }, "sha512-TxRdQQLH4g7JkoFlYG3caW5v1S6kEkz8rqt80iQJZUYPq1zD1Ra7HfQBJJ88ABRaMvHAXnwRvRB4V+6sQ9xN5Q=="],
|
||||
|
||||
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
|
||||
|
||||
"uri-js": ["uri-js@4.4.1", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg=="],
|
||||
|
||||
"util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
|
||||
|
||||
BIN
database/data.db
Normal file
BIN
database/data.db
Normal file
Binary file not shown.
27
package.json
27
package.json
@ -1,18 +1,6 @@
|
||||
{
|
||||
"name": "hc-app",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"format": "prettier --write .",
|
||||
"lint": "prettier --check . && eslint ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.2.5",
|
||||
"@eslint/js": "^9.18.0",
|
||||
@ -22,6 +10,7 @@
|
||||
"@tailwindcss/forms": "^0.5.9",
|
||||
"@tailwindcss/typography": "^0.5.15",
|
||||
"@tailwindcss/vite": "^4.0.0",
|
||||
"bun-types": "^1.2.4",
|
||||
"daisyui": "^5.0.0",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
@ -36,5 +25,17 @@
|
||||
"typescript": "^5.0.0",
|
||||
"typescript-eslint": "^8.20.0",
|
||||
"vite": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev --host",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"format": "prettier --write .",
|
||||
"lint": "prettier --check . && eslint ."
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
6
src/lib/db/index.ts
Normal file
6
src/lib/db/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
//import Database from 'better-sqlite3';
|
||||
import { Database } from 'bun:sqlite';
|
||||
|
||||
const db = new Database('./database/data.db');
|
||||
|
||||
export default db;
|
||||
3
src/lib/db/queries.ts
Normal file
3
src/lib/db/queries.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import db from ".";
|
||||
|
||||
export const allCountries = db.prepare('SELECT id, name, native, emoji FROM countries')
|
||||
6
src/lib/types.ts
Normal file
6
src/lib/types.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export type CountryBasics = {
|
||||
id: number;
|
||||
name: string;
|
||||
native: string;
|
||||
emoji: string;
|
||||
}
|
||||
20
src/routes/+page.server.ts
Normal file
20
src/routes/+page.server.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { allCountries } from "$lib/db/queries";
|
||||
import type { CountryBasics } from "$lib/types";
|
||||
import type { PageServerData } from "./$types";
|
||||
|
||||
|
||||
export const load: PageServerData = () => {
|
||||
try {
|
||||
const countries = allCountries.all() as CountryBasics[]
|
||||
return {
|
||||
countries
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
countries: [] as CountryBasics[]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,27 @@
|
||||
<script lang="ts">
|
||||
import type { PageProps } from './$types';
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
// let dropdownElement: HTMLDivElement;
|
||||
// let searchTerm: string = $state('');
|
||||
// let value: option = $state();
|
||||
// let isOpen: boolean = $state(false);
|
||||
// let option: any = $state();
|
||||
// let filteredOptions = $derived(
|
||||
// searchTerm
|
||||
// ? data.countries.filter((c) => c.name.toLowerCase().startsWith(searchTerm.toLowerCase()))
|
||||
// : data.countries
|
||||
// );
|
||||
//
|
||||
// const handleInputChange = () => {};
|
||||
// const handleOptionSelect = (item: any) => {};
|
||||
// TODO: pick search library
|
||||
// fuse - 6.2
|
||||
// @nozbe/microfuzz 1.3
|
||||
// fast-fuzzy 8.6
|
||||
// fuzzy-search 1
|
||||
</script>
|
||||
|
||||
<main class="container mx-auto my-3 max-w-4xl p-4">
|
||||
<h1 class="my-5 text-center text-4xl font-light">HotColdCities</h1>
|
||||
<h2 class="mx-auto max-w-xl text-center text-xl leading-tight md:text-2xl">
|
||||
@ -6,4 +30,65 @@
|
||||
</h2>
|
||||
|
||||
<button class="btn btn-lg btn-soft btn-primary"> Hi </button>
|
||||
|
||||
<!-- <section> -->
|
||||
<!-- <div class="relative w-full" bind:this={dropdownElement}> -->
|
||||
<!-- <div class="form-control w-full"> -->
|
||||
<!-- <div class="input input-bordered flex items-center"> -->
|
||||
<!-- <input -->
|
||||
<!-- type="text" -->
|
||||
<!-- class="flex-grow bg-transparent focus:outline-none" -->
|
||||
<!-- placeholder="Type in to filter countries" -->
|
||||
<!-- bind:value={searchTerm} -->
|
||||
<!-- oninput={handleInputChange} -->
|
||||
<!-- onfocus={() => (isOpen = true)} -->
|
||||
<!-- /> -->
|
||||
<!-- <button class="btn btn-ghost btn-sm" onclick={() => (isOpen = !isOpen)} type="button"> -->
|
||||
<!-- <svg -->
|
||||
<!-- xmlns="http://www.w3.org/2000/svg" -->
|
||||
<!-- class="h-4 w-4" -->
|
||||
<!-- fill="none" -->
|
||||
<!-- viewBox="0 0 24 24" -->
|
||||
<!-- stroke="currentColor" -->
|
||||
<!-- > -->
|
||||
<!-- <path -->
|
||||
<!-- stroke-linecap="round" -->
|
||||
<!-- stroke-linejoin="round" -->
|
||||
<!-- stroke-width="2" -->
|
||||
<!-- d={isOpen ? 'M5 15l7-7 7 7' : 'M19 9l-7 7-7-7'} -->
|
||||
<!-- /> -->
|
||||
<!-- </svg> -->
|
||||
<!-- </button> -->
|
||||
<!-- </div> -->
|
||||
<!-- </div> -->
|
||||
<!---->
|
||||
<!-- {#if isOpen} -->
|
||||
<!-- <ul -->
|
||||
<!-- class="dropdown-content menu bg-base-100 rounded-box z-50 max-h-60 w-full overflow-auto p-2 shadow" -->
|
||||
<!-- > -->
|
||||
<!-- {#if filteredOptions.length > 0} -->
|
||||
<!-- {#each filteredOptions as option, i} -->
|
||||
<!-- <li> -->
|
||||
<!-- <button -->
|
||||
<!-- onclick={() => handleOptionSelect(option)} -->
|
||||
<!-- class={value === option ? 'active' : ''} -->
|
||||
<!-- > -->
|
||||
<!-- {option} -->
|
||||
<!-- </button> -->
|
||||
<!-- </li> -->
|
||||
<!-- {/each} -->
|
||||
<!-- {:else} -->
|
||||
<!-- <li class="p-2 text-gray-500">No options found</li> -->
|
||||
<!-- {/if} -->
|
||||
<!-- </ul> -->
|
||||
<!-- {/if} -->
|
||||
<!-- </div> -->
|
||||
<!-- </section> -->
|
||||
|
||||
<ul>
|
||||
{#each data.countries as country, idx (country.id)}
|
||||
<li>{country.name} - {country.emoji}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
<!-- <code>{JSON.stringify(data, null, 2)}</code> -->
|
||||
</main>
|
||||
|
||||
@ -9,7 +9,10 @@
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
"moduleResolution": "bundler",
|
||||
"types": [
|
||||
"bun-types"
|
||||
]
|
||||
}
|
||||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user