Furki4_4
Furki4_4
Explore posts from servers
DTDrizzle Team
Created by Furki4_4 on 6/25/2024 in #help
Keep getting "cannot read properties of undefined (reading 'referencedTable') error
word schema
1 replies
TTCTheo's Typesafe Cult
Created by Furki4_4 on 12/30/2023 in #questions
QueryClient type error using create-t3-app
Hi folks, I now get this type error somehow that never occured before. (see pic 1st) I just updated trpc and react query versions of my project to the identical versions of up-to-date create-t3-app (see pic 2nd) What I tried to solve is reinstalling deps and rollbacking the deps updates which didn't work at all. Can anyone help me ?
4 replies
KPCKevin Powell - Community
Created by Furki4_4 on 12/5/2023 in #back-end
Need Help for Database Structure
No description
3 replies
TTCTheo's Typesafe Cult
Created by Furki4_4 on 12/5/2023 in #questions
Need Help for Database Structure
No description
2 replies
TTCTheo's Typesafe Cult
Created by Furki4_4 on 11/26/2023 in #questions
can't find meta/_journal.json file on prod | DRIZZLE
No description
3 replies
TTCTheo's Typesafe Cult
Created by Furki4_4 on 11/24/2023 in #questions
next-auth drizzle adapter customization
Hi folks, I'm using t3 app dir stack with next-auth and drizzle. I wanna customize the drizzle adapter while creating a user. I inspected the source code and customized the createUser callback function of the adapter as the following:
// node_modules/@auth/drizzle-adapter/src/lib/pg.ts
async createUser(data){
console.log("createUser", data)
return await client
.insert(users)
.values({
...data,
id: crypto.randomUUID(),
username: data.email.split("@")[0] // added this by myself
}).returning().then((res) => res[0] ?? null)
},
// node_modules/@auth/drizzle-adapter/src/lib/pg.ts
async createUser(data){
console.log("createUser", data)
return await client
.insert(users)
.values({
...data,
id: crypto.randomUUID(),
username: data.email.split("@")[0] // added this by myself
}).returning().then((res) => res[0] ?? null)
},
I have extended my users table by adding password and email columns and need to set the username column with notNull restriction using the email without domain like you see above. the problem is that the username value still gets null somehow even though the email is not null so I can't add users since the notNull restriction error. It seems that my changes doesn't work at all, how do I customize this adapter as I need ?
7 replies
TTCTheo's Typesafe Cult
Created by Furki4_4 on 11/23/2023 in #questions
how to create relatedWords relation for each words using drizzle. | DRIZZLE | SQL |
Hi folks, I'm building an online Turkish dictionary using t3 stack with drizzle. I want every word can have related words so that I can show them in related words section when a word searched. What I tried is to create another table called relatedWords that includes an id and relatedWordId in order to create many-to-many relationship between word and relatedWords. Here's what I tried with drizzle schemas and relations:
//schema.ts

export const words = pgTable("words", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 255 }).notNull(),
phonetic: varchar("phonetic", { length: 255 }),
root: varchar("root", { length: 255 }),
attributes: varchar("attributes", { length: 255 }),
audio: varchar("audio", { length: 255 }),
createdAt: date("createdAt").notNull(),
updatedAt: date("updatedAt").notNull(),
});

export const wordsRelations = relations(words, ({ many }) => ({
wordMeanings: many(meanings),
wordsToRelatedWords: many(wordsToRelatedWords),
}));

export const relatedWords = pgTable("related_words", {
id: serial("id").primaryKey(),
relatedWordId: integer("related_word_id")
.notNull()
.references(() => words.id),
});

export const relatedWordsRelations = relations(relatedWords, ({ many }) => ({
wordsToRelatedWords: many(wordsToRelatedWords),
}));
export const wordsToRelatedWords = pgTable(
"words_to_related_words",
{
wordId: integer("word_id")
.notNull()
.references(() => words.id),
relatedWordId: integer("related_word_id")
.notNull()
.references(() => relatedWords.id),
},
(t) => ({
pk: primaryKey({ columns: [t.wordId, t.relatedWordId] }),
})
);

export const wordsToRelatedWordsRelations = relations(
wordsToRelatedWords,
({ one }) => ({
words: one(words, {
fields: [wordsToRelatedWords.wordId],
references: [words.id],
}),
relatedWords: one(words, {
fields: [wordsToRelatedWords.relatedWordId],
references: [words.id],
}),
})
);
//schema.ts

export const words = pgTable("words", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 255 }).notNull(),
phonetic: varchar("phonetic", { length: 255 }),
root: varchar("root", { length: 255 }),
attributes: varchar("attributes", { length: 255 }),
audio: varchar("audio", { length: 255 }),
createdAt: date("createdAt").notNull(),
updatedAt: date("updatedAt").notNull(),
});

export const wordsRelations = relations(words, ({ many }) => ({
wordMeanings: many(meanings),
wordsToRelatedWords: many(wordsToRelatedWords),
}));

export const relatedWords = pgTable("related_words", {
id: serial("id").primaryKey(),
relatedWordId: integer("related_word_id")
.notNull()
.references(() => words.id),
});

export const relatedWordsRelations = relations(relatedWords, ({ many }) => ({
wordsToRelatedWords: many(wordsToRelatedWords),
}));
export const wordsToRelatedWords = pgTable(
"words_to_related_words",
{
wordId: integer("word_id")
.notNull()
.references(() => words.id),
relatedWordId: integer("related_word_id")
.notNull()
.references(() => relatedWords.id),
},
(t) => ({
pk: primaryKey({ columns: [t.wordId, t.relatedWordId] }),
})
);

export const wordsToRelatedWordsRelations = relations(
wordsToRelatedWords,
({ one }) => ({
words: one(words, {
fields: [wordsToRelatedWords.wordId],
references: [words.id],
}),
relatedWords: one(words, {
fields: [wordsToRelatedWords.relatedWordId],
references: [words.id],
}),
})
);
Drizzle studio throws this error: Error: There is not enough information to infer relation "__public__.relatedWords.wordsToRelatedWords" It's been a while since I created SQL relationships last time and I've never done such a relationship like this. Thanks in advance for any help!
9 replies
TTCTheo's Typesafe Cult
Created by Furki4_4 on 10/14/2023 in #questions
Unexpected Auto Refreshing Page on Route Guard Redirect
Hello people! I'm building an online dictionary website with Next.js 13.5.2, and next-auth for the auth. I wanted to make users who are already signed in unable to see the sign-in, sign-up, or forgot-password page by showing a short message with React Toastify. However, the home page gets loaded twice when users are redirected. ( simulate it using the live link: https://turkish-dictionary-chi.vercel.app/tr ) Here's what I do in the sign-in, sign-up, and forgot password pages setting a query param to catch the error on the client side and render toastify cards. in the signup page, I render this (signup code: https://github.com/4Furki4/Turkish-Dictionary/blob/f84f49e726b9a0579917856dcc2ada5217a5e45f/src/app/%5Blocale%5D/(content)/signup/page.tsx#L29 see the signin and forgot password folders that renders this too)
const session = await getServerSession();
if (session) {
redirect("/?warning=alreadySignedIn");
}
const session = await getServerSession();
if (session) {
redirect("/?warning=alreadySignedIn");
}
Here's how I render the cards. (I tried not passing shallow in the replace func or using push func but did no difference.) in the layout.tsx, I render this ( https://github.com/4Furki4/Turkish-Dictionary/blob/f84f49e726b9a0579917856dcc2ada5217a5e45f/src/app/%5Blocale%5D/(content)/(search)/layout.tsx#L20 )
useEffect(() => {
const warningParam = params.get("warning");
if (warningParam === "alreadySignedIn") {
toast.warning(t(warningParam));
router.replace("/", { shallow: true });
}
}, [params, router, t]);
useEffect(() => {
const warningParam = params.get("warning");
if (warningParam === "alreadySignedIn") {
toast.warning(t(warningParam));
router.replace("/", { shallow: true });
}
}, [params, router, t]);
I also replaced the redirect function with router.push function in the client components of the auth pages but that didn't guard the pages properly and showed the cached auth page without triggering the if states with session.status somehow. One more thing that I just noticed is that the page doesn't get refreshed when users are navigated back to the signup page due to an invalid reset password link as you can see in the second video. ( The related code: https://github.com/4Furki4/Turkish-Dictionary/blob/c38560713b3f44f9561b823d6d86d8fe507ee92a/src/app/%5Blocale%5D/(content)/reset-password/%5Bid%5D/page.tsx#L43C1-L52C6 ) Let me know if something is not clear and thanks in advance for any help for solving the auto refreshing!
1 replies