Skip to content

Commit

Permalink
Increase db client count
Browse files Browse the repository at this point in the history
  • Loading branch information
omfj committed Sep 24, 2024
1 parent 7125764 commit a928317
Show file tree
Hide file tree
Showing 55 changed files with 130 additions and 110 deletions.
4 changes: 4 additions & 0 deletions apps/api/src/lib/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createDatabase, createPool } from "@echo-webkom/db/create";

const pool = createPool();
export const db = createDatabase(pool);
2 changes: 1 addition & 1 deletion apps/api/src/services/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { and, eq, gte, lte, or, sql } from "drizzle-orm";
import { Hono } from "hono";
import { z } from "zod";

import { db } from "@echo-webkom/db";
import { AnswerInsert, answers, comments, registrations, users } from "@echo-webkom/db/schemas";

import { db } from "../lib/db";
import { admin } from "../middleware/admin";
import { getCorrectSpotrange } from "../utils/correct-spot-range";
import { parseJson } from "../utils/json";
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/services/degrees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { eq } from "drizzle-orm";
import { Hono } from "hono";
import { z } from "zod";

import { db } from "@echo-webkom/db";
import { degrees, insertDegreeSchema } from "@echo-webkom/db/schemas";

import { db } from "../lib/db";
import { admin } from "../middleware/admin";
import { parseJson } from "../utils/json";

Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/services/feedback.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Hono } from "hono";

import { db } from "@echo-webkom/db";

import { db } from "../lib/db";
import { admin } from "../middleware/admin";

const app = new Hono();
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/services/happening.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Hono } from "hono";

import { db } from "@echo-webkom/db";

import { db } from "../lib/db";
import { admin } from "../middleware/admin";

const app = new Hono();
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/services/shopping-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Hono } from "hono";

import { db } from "@echo-webkom/db";

import { db } from "../lib/db";
import { admin } from "../middleware/admin";

const app = new Hono();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/delete-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { and, eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { comments } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { revalidateComments } from "@/data/comments/revalidate";
import { getUser } from "@/lib/get-user";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/deregister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { and, eq } from "drizzle-orm";
import { z } from "zod";

import { db } from "@echo-webkom/db";
import { answers, registrations } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";
import { DeregistrationNotificationEmail } from "@echo-webkom/email";
import { emailClient } from "@echo-webkom/email/client";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { File } from "node:buffer";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { users } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { ppFor } from "@/lib/echogram";
import { getUser } from "@/lib/get-user";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/remove-all-registrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { revalidateTag } from "next/cache";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { registrations } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { cacheKeyFactory } from "@/data/registrations/revalidate";
import { getUser } from "@/lib/get-user";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/strikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { and, eq } from "drizzle-orm";
import { z } from "zod";

import { db } from "@echo-webkom/db";
import { type StrikeInfoInsert } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";
import { StrikeNotificationEmail } from "@echo-webkom/email";
import { emailClient } from "@echo-webkom/email/client";
import { type StrikeType } from "@echo-webkom/lib/src/constants";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/update-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { and, eq } from "drizzle-orm";
import { z } from "zod";

import { db } from "@echo-webkom/db";
import { registrations, registrationStatusEnum } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";
import { GotSpotNotificationEmail } from "@echo-webkom/email";
import { emailClient } from "@echo-webkom/email/client";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { eq } from "drizzle-orm";
import { z } from "zod";

import { db } from "@echo-webkom/db";
import { insertUserSchema, users, usersToGroups } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { getUser } from "@/lib/get-user";
import { isWebkom } from "@/lib/memberships";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { insertWhitelistSchema, whitelist } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { getUser } from "@/lib/get-user";
import { isMemberOf } from "@/lib/memberships";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(default)/admin/brukere/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RxDotsHorizontal as Dots } from "react-icons/rx";

import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { Container } from "@/components/container";
import { Heading } from "@/components/typography/heading";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { accessRequests } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { getUser } from "@/lib/get-user";
import { isMemberOf } from "@/lib/memberships";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import { eq } from "drizzle-orm";

import { db, isPostgresIshError } from "@echo-webkom/db";
import { isPostgresIshError } from "@echo-webkom/db/error";
import { accessRequests, whitelist } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";
import { AccessGrantedEmail } from "@echo-webkom/email";
import { emailClient } from "@echo-webkom/email/client";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(default)/auth/profil/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from "next/link";
import { redirect } from "next/navigation";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { Chip } from "@/components/typography/chip";
import { Heading } from "@/components/typography/heading";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import { nanoid } from "nanoid";
import { z } from "zod";

import { db, isPostgresIshError } from "@echo-webkom/db";
import { isPostgresIshError } from "@echo-webkom/db/error";
import { accessRequests } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";
import { AccessRequestNotificationEmail } from "@echo-webkom/email";
import { emailClient } from "@echo-webkom/email/client";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(default)/dashbord/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Image from "next/image";
import Link from "next/link";
import { notFound } from "next/navigation";

import { db } from "@echo-webkom/db";
import { type RegistrationStatus } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { Container } from "@/components/container";
import { HappeningInfoBox } from "@/components/happening-info-box";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(default)/gruppe/[id]/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { and, eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { usersToGroups } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { getUser } from "@/lib/get-user";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(default)/gruppe/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { notFound } from "next/navigation";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { Container } from "@/components/container";
import { Heading } from "@/components/typography/heading";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(default)/prikker/[userId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from "next/link";
import { notFound } from "next/navigation";
import { and, desc, eq, lt } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { Container } from "@/components/container";
import { Heading } from "@/components/typography/heading";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/groups/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { withBearerAuth } from "@/lib/checks/with-bearer-auth";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/sanity/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextResponse } from "next/server";
import { and, eq, inArray } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import {
happenings,
happeningsToGroups,
Expand All @@ -10,6 +9,7 @@ import {
type HappeningInsert,
type QuestionInsert,
} from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";
import { isBoard } from "@echo-webkom/lib";

import { withBasicAuth } from "@/lib/checks/with-basic-auth";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/access-requests/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

export const getAccessRequests = async () => {
return await db.query.accessRequests.findMany();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/groups/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { groups, type Group, type GroupInsert } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { revalidateGroups } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/groups/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { unstable_cache as cache } from "next/cache";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { type User } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { cacheKeyFactory } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/happenings/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { and, asc, eq, gt, lt } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { type Happening, type HappeningType } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { isErrorMessage } from "@/utils/error";

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/data/kv/kv-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { eq } from "drizzle-orm";

import { isPostgresIshError, type Database } from "@echo-webkom/db";
import { type Database } from "@echo-webkom/db/create";
import { isPostgresIshError } from "@echo-webkom/db/error";
import { kv } from "@echo-webkom/db/schemas";

import { isExpired } from "./utils";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/kv/namespaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import z from "zod";

import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { KVDrizzleAdapter } from "./kv-adapter";
import { KVNamespace } from "./kv-namespace";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/reactions/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { and, eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { reactions, type ReactionInsert } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { revalidateReactions } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/reactions/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { unstable_cache as cache } from "next/cache";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { db } from "@echo-webkom/db/serverless";

import { cacheKeyFactory } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/registrations/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from "@echo-webkom/db";
import { registrations, type RegistrationInsert } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { revalidateRegistrations } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/registrations/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { unstable_cache as cache } from "next/cache";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { type Registration, type User } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { apiServer } from "@/api/server";
import { cacheKeyFactory } from "./revalidate";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/shopping-list-item/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { and, eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import {
shoppingListItems,
usersToShoppingListItems,
Expand All @@ -9,6 +8,7 @@ import {
type UsersToShoppingListItems,
type UsersToShoppingListItemsInsert,
} from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

export const createShoppinglistItem = async (newItem: ShoppingListItemsInsert) => {
const [insertedShoppingListItem] = await db
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/site-feedbacks/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { siteFeedback, type SiteFeedbackInsert } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

export const createFeedback = async (feedback: SiteFeedbackInsert) => {
const [insertedFeedback] = await db
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/strikes/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import {
strikeInfos,
strikes,
users,
type StrikeInfoInsert,
type StrikeInsert,
} from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { revalidateStrikes } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/strikes/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { unstable_cache as cache } from "next/cache";
import { and, count, eq, gt, isNull, or } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { strikes, users } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

import { cacheKeyFactory } from "./revalidate";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/users/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { users } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

export const unbanUser = async (userId: string) => {
const user = await db
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/data/users/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { unstable_cache as cache } from "next/cache";
import { eq } from "drizzle-orm";

import { db } from "@echo-webkom/db";
import { type User } from "@echo-webkom/db/schemas";
import { db } from "@echo-webkom/db/serverless";

export const getUserById = async (id: User["id"]) => {
return await db.query.users.findFirst({
Expand Down
Loading

0 comments on commit a928317

Please sign in to comment.