-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}) | ||
} |