Refactor data insertion via Drizzle
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { featuredAdventures } from "$lib/db/schema";
|
||||
import { adventureTable, featuredAdventures } from "$lib/db/schema";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const load = async () => {
|
||||
const result = await db
|
||||
.select()
|
||||
.from(featuredAdventures)
|
||||
.orderBy(featuredAdventures.id);
|
||||
.from(adventureTable)
|
||||
.where(eq(adventureTable.type, "featured"))
|
||||
.orderBy(adventureTable.id);
|
||||
return {
|
||||
result: result as Adventure[],
|
||||
};
|
||||
|
||||
@@ -8,7 +8,8 @@ import type { DatabaseUser } from "$lib/server/auth";
|
||||
|
||||
import type { Actions } from "./$types";
|
||||
import { userTable } from "$lib/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { insertData } from "$lib/db/insertData";
|
||||
|
||||
export const actions: Actions = {
|
||||
default: async (event) => {
|
||||
@@ -109,8 +110,11 @@ export const actions: Actions = {
|
||||
} as DatabaseUser)
|
||||
.execute();
|
||||
|
||||
const session = await lucia.createSession(userId, {});
|
||||
const sessionCookie = lucia.createSessionCookie(session.id);
|
||||
// inserts the data needed for all of the pre defined adventures and world travel regions
|
||||
await insertData();
|
||||
|
||||
const session: any = await lucia.createSession(userId, {});
|
||||
const sessionCookie: any = lucia.createSessionCookie(session.id);
|
||||
event.cookies.set(sessionCookie.name, sessionCookie.value, {
|
||||
path: ".",
|
||||
...sessionCookie.attributes,
|
||||
|
||||
Reference in New Issue
Block a user