aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src/actions
diff options
context:
space:
mode:
authoryxshv <[email protected]>2024-04-11 16:37:46 +0530
committeryxshv <[email protected]>2024-04-11 16:37:46 +0530
commit539f50367d2964579dbb6aa62876fab973b17840 (patch)
treea071ab8c30d2448207bc68c92a57d5663dd73724 /apps/web/src/actions
parentmerge pls (diff)
parentMerge branch 'main' of https://github.com/Dhravya/supermemory (diff)
downloadsupermemory-539f50367d2964579dbb6aa62876fab973b17840.tar.xz
supermemory-539f50367d2964579dbb6aa62876fab973b17840.zip
Merge branch 'main' of https://github.com/dhravya/supermemory
Diffstat (limited to 'apps/web/src/actions')
-rw-r--r--apps/web/src/actions/db.ts52
1 files changed, 52 insertions, 0 deletions
diff --git a/apps/web/src/actions/db.ts b/apps/web/src/actions/db.ts
new file mode 100644
index 00000000..3b640c96
--- /dev/null
+++ b/apps/web/src/actions/db.ts
@@ -0,0 +1,52 @@
+"use server";
+import { db } from "@/server/db";
+import {
+ contentToSpace,
+ StoredContent,
+ storedContent,
+} from "@/server/db/schema";
+import { like, eq, and } from "drizzle-orm";
+import { auth as authOptions } from "@/server/auth";
+import { getSession } from "next-auth/react";
+
+export async function getMemory(title: string) {
+ const session = await getSession();
+
+ console.log(session?.user?.name);
+
+ if (!session || !session.user) {
+ return null;
+ }
+
+ return await db
+ .select()
+ .from(storedContent)
+ .where(
+ and(
+ eq(storedContent.user, session.user.id!),
+ like(storedContent.title, `%${title}%`),
+ ),
+ );
+}
+
+export async function addMemory(
+ content: typeof storedContent.$inferInsert,
+ spaces: number[],
+) {
+ const session = await getSession();
+
+ if (!session || !session.user) {
+ return null;
+ }
+ content.user = session.user.id;
+
+ const _content = (
+ await db.insert(storedContent).values(content).returning()
+ )[0];
+ await Promise.all(
+ spaces.map((spaceId) =>
+ db.insert(contentToSpace).values({ contentId: _content.id, spaceId }),
+ ),
+ );
+ return _content;
+}