1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-30 02:09:37 +02:00

Add featuredAdventures table and related code

This commit is contained in:
Sean Morley 2024-04-02 14:01:35 +00:00
parent c23ea0ce5e
commit 33122894c2
10 changed files with 1936 additions and 39 deletions

15
drizzle.config.ts Normal file
View file

@ -0,0 +1,15 @@
import type { Config } from 'drizzle-kit';
import * as dotenv from 'dotenv';
dotenv.config();
const { DATABASE_URL } = process.env;
if (!DATABASE_URL) {
throw new Error('No url');
}
export default {
schema: './src/lib/db/schema.ts',
out: './migrations',
driver: 'pg',
dbCredentials: {
connectionString: DATABASE_URL
}
} satisfies Config;

View file

@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS "featuredAdventures" (
"id" serial PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"location" text
);

View file

@ -0,0 +1,43 @@
{
"id": "1639b320-88dd-4af5-ae34-092ab26b4b85",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"tables": {
"featuredAdventures": {
"name": "featuredAdventures",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"location": {
"name": "location",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View file

@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1712061709595,
"tag": "0000_fancy_starjammers",
"breakpoints": true
}
]
}

1845
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -7,26 +7,35 @@
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"studio": "drizzle-kit studio --config drizzle.config.ts",
"generate": "drizzle-kit generate:pg --config drizzle.config.ts",
"migrate": "drizzle-kit push:pg --config drizzle.config.ts",
"seed": "node seed.js"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0", "@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/adapter-node": "^5.0.1", "@sveltejs/adapter-node": "^5.0.1",
"@sveltejs/adapter-vercel": "^5.2.0",
"@sveltejs/kit": "^2.0.0", "@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0",
"@tailwindcss/typography": "^0.5.12", "@tailwindcss/typography": "^0.5.12",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"daisyui": "^4.9.0", "daisyui": "^4.9.0",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.20.14",
"pg": "^8.11.4",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"svelte": "^4.2.7", "svelte": "^4.2.7",
"svelte-check": "^3.6.0", "svelte-check": "^3.6.0",
"tailwindcss": "^3.4.3", "tailwindcss": "^3.4.3",
"tslib": "^2.4.1", "tslib": "^2.4.1",
"typescript": "^5.0.0", "typescript": "^5.0.0",
"vite": "^5.0.3", "vite": "^5.0.3"
"@sveltejs/adapter-vercel": "^5.2.0"
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"drizzle-orm": "^0.30.6",
"postgres": "^3.4.4"
} }
} }

8
src/lib/db/db.server.ts Normal file
View file

@ -0,0 +1,8 @@
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import dotenv from 'dotenv';
dotenv.config();
const { DATABASE_URL } = process.env;
const client = postgres(DATABASE_URL)
export const db = drizzle(client, {});

9
src/lib/db/schema.ts Normal file
View file

@ -0,0 +1,9 @@
import { pgTable,serial,text } from "drizzle-orm/pg-core";
export const featuredAdventures = pgTable("featuredAdventures",{
id:serial("id").primaryKey(),
name:text("name").notNull(),
location:text("location"),
})

View file

@ -0,0 +1,11 @@
import { db } from '$lib/db/db.server';
import { featuredAdventures } from '$lib/db/schema';
import type { Adventure } from '$lib/utils/types';
export const load = (async () => {
const result = await db.select().from(featuredAdventures)
return {
result : result as Adventure[]
};
})

View file

@ -0,0 +1,11 @@
<script lang="ts">
export let data
console.log(data.result);
import AdventureCard from '$lib/components/AdventureCard.svelte';
</script>
<div class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6">
{#each data.result as adventure (adventure.id)}
<AdventureCard id={adventure.id} name={adventure.name} location={adventure.location} created={adventure.created} />
{/each}
</div>