Skip to content

Commit

Permalink
comments out prepared functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xwilson03 committed Sep 10, 2024
1 parent b7393b4 commit fc51ac1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 52 deletions.
85 changes: 48 additions & 37 deletions packages/db/functions/hacker.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,74 @@
import { db, eq, sql } from "..";
import { db, eq } from "..";
import { userCommonData } from "../schema";
import { Hacker } from "../types";

const _getAllHackers = db.query.userCommonData
.findMany({
with: { hackerData: true },
})
.prepare("getAllHackers");
// const _getAllHackers = db.query.userCommonData
// .findMany({
// with: { hackerData: true },
// })
// .prepare("getAllHackers");

export function getAllHackers(): Promise<Hacker[] | undefined> {
return _getAllHackers.execute();
// return _getAllHackers.execute();
return db.query.userCommonData.findMany({
with: { hackerData: true },
});
}

// ID

const _getHackerByIDWithTeam = db.query.userCommonData
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
with: { hackerData: { with: { team: true } } },
})
.prepare("getHackerByIDWithTeam");
// const _getHackerByIDWithTeam = db.query.userCommonData
// .findFirst({
// where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
// with: { hackerData: { with: { team: true } } },
// })
// .prepare("getHackerByIDWithTeam");

const _getHackerByIDAlone = db.query.userCommonData
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
with: { hackerData: true },
})
.prepare("getHackerByID");
// const _getHackerByIDAlone = db.query.userCommonData
// .findFirst({
// where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
// with: { hackerData: true },
// })
// .prepare("getHackerByID");

export function getHacker(
clerkID: string,
withTeam: boolean,
): Promise<Hacker | undefined> {
return withTeam
? _getHackerByIDWithTeam.execute({ _clerkID: clerkID })
: _getHackerByIDAlone.execute({ _clerkID: clerkID });
// return withTeam
// ? _getHackerByIDWithTeam.execute({ _clerkID: clerkID })
// : _getHackerByIDAlone.execute({ _clerkID: clerkID });
return db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, clerkID),
with: { hackerData: (withTeam) ? { with: { team: true } } : true }
});
}

// Tag

const _getHackerByTagWithTeam = db.query.userCommonData
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
with: { hackerData: { with: { team: true } } },
})
.prepare("getHackerByTagWithTeam");
// const _getHackerByTagWithTeam = db.query.userCommonData
// .findFirst({
// where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
// with: { hackerData: { with: { team: true } } },
// })
// .prepare("getHackerByTagWithTeam");

const _getHackerByTagAlone = db.query.userCommonData
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
with: { hackerData: true },
})
.prepare("getHackerByTag");
// const _getHackerByTagAlone = db.query.userCommonData
// .findFirst({
// where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
// with: { hackerData: true },
// })
// .prepare("getHackerByTag");

export function getHackerByTag(
hackerTag: string,
withTeam: boolean,
): Promise<Hacker | undefined> {
return withTeam
? _getHackerByTagWithTeam.execute({ _hackerTag: hackerTag })
: _getHackerByTagAlone.execute({ _hackerTag: hackerTag });
// return withTeam
// ? _getHackerByTagWithTeam.execute({ _hackerTag: hackerTag })
// : _getHackerByTagAlone.execute({ _hackerTag: hackerTag });
return db.query.userCommonData.findFirst({
where: eq(userCommonData.hackerTag, hackerTag),
with: { hackerData: (withTeam) ? { with: { team: true } } : true },
});
}
37 changes: 22 additions & 15 deletions packages/db/functions/user.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
import { db, eq, sql } from "..";
import { db, eq } from "..";
import { userCommonData } from "../schema";
import { User } from "../types";

const _getAllUsers = db.query.userCommonData.findMany().prepare("getAllUsers");
// const _getAllUsers = db.query.userCommonData.findMany().prepare("getAllUsers");

export function getAllUsers(): Promise<User[] | undefined> {
return _getAllUsers.execute();
// return _getAllUsers.execute();
return db.query.userCommonData.findMany();
}

// ID

const _getUser = db.query.userCommonData
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
})
.prepare("getUser");
// const _getUser = db.query.userCommonData
// .findFirst({
// where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
// })
// .prepare("getUser");

export function getUser(clerkID: string): Promise<User | undefined> {
return _getUser.execute({ _clerkID: clerkID });
// return _getUser.execute({ _clerkID: clerkID });
return db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, clerkID),
});
}

// Tag

const _getUserByTag = db.query.userCommonData
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
})
.prepare("getUserByTag");
// const _getUserByTag = db.query.userCommonData
// .findFirst({
// where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
// })
// .prepare("getUserByTag");

export function getUserByTag(hackerTag: string): Promise<User | undefined> {
return _getUserByTag.execute({ _hackerTag: hackerTag });
// return _getUserByTag.execute({ _hackerTag: hackerTag });
return db.query.userCommonData.findFirst({
where: eq(userCommonData.hackerTag, hackerTag),
})
}

0 comments on commit fc51ac1

Please sign in to comment.