Liam
Liam
Explore posts from servers
DTDrizzle Team
Created by Liam on 7/31/2024 in #help
There is not enough information to infer relation
Hello, I am running into a issue where drizzle studio is stating that there is not enought information to infer relation "__public__.tickets.chat". Any idea why this might be? I have the following schema:
export const tickets = pgTable("tickets", {
id: text("id").primaryKey(),
title: varchar("title", { length: 255 }).notNull(),
description: text("description").notNull(),
status: ticketStatus("status").notNull().default("awaiting"),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const ticketRelations = relations(tickets, ({ one, many }) => ({
chat: one(chats),
tickets: many(ticketsToUsers),
}));

export const chats = pgTable("chats", {
id: text("id").primaryKey(),
type: chatType("type").notNull(),
ticketID: text("ticket_id").references(() => tickets.id),
author: text("author").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const chatRelations = relations(chats, ({ many }) => ({
messages: many(chatMessages),
members: many(chatsToUsers),
}));
export const tickets = pgTable("tickets", {
id: text("id").primaryKey(),
title: varchar("title", { length: 255 }).notNull(),
description: text("description").notNull(),
status: ticketStatus("status").notNull().default("awaiting"),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const ticketRelations = relations(tickets, ({ one, many }) => ({
chat: one(chats),
tickets: many(ticketsToUsers),
}));

export const chats = pgTable("chats", {
id: text("id").primaryKey(),
type: chatType("type").notNull(),
ticketID: text("ticket_id").references(() => tickets.id),
author: text("author").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const chatRelations = relations(chats, ({ many }) => ({
messages: many(chatMessages),
members: many(chatsToUsers),
}));
5 replies
DTDrizzle Team
Created by Liam on 7/28/2024 in #help
Drizzle Query Returns Different Result Than Select
Made a issue over on github for this, and wanted to see if anyone has ran into anything similar. Thanks! https://github.com/drizzle-team/drizzle-orm/issues/2703
1 replies
DTDrizzle Team
Created by Liam on 5/25/2024 in #help
Error When Using isNull Filter
No description
1 replies
DTDrizzle Team
Created by Liam on 5/22/2024 in #help
Drizzle-Zod Set Default Minimum Length For Text / No Empty Strings
Hello! I am using drizzle zod to validate some input, at the moment the schema for any text columns allows empty strings. I would like to require that all strings cannnot be empty. Is there any way to do this without having to manually define each column as z.string().min(1)? Thanks!
1 replies
RRailway
Created by Liam on 5/8/2024 in #✋|help
Nixpacks Ignoring Engines.Node
Hi! For some reason, nixpacks seems to be ignoring my engines.node in my package.json. I have set it to use v12 (This is a legacy project) however it just uses v18 anyways. Any idea why this might be? Thanks!
5 replies
DTDrizzle Team
Created by Liam on 5/4/2024 in #help
Issue With Defining References
Hello! I am attempting to define a reference to another table. I have the following users table:
export const users = pgTable("users", {
userID: serial("user_id").primaryKey(),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey(),
// some other data in here
});
export const users = pgTable("users", {
userID: serial("user_id").primaryKey(),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey(),
// some other data in here
});
however when update the tables to have the references like so
export const users = pgTable("users", {
userID: serial("user_id").primaryKey().references(() => data.userID),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey().references(() => users.userID),
// some other data here
});
export const users = pgTable("users", {
userID: serial("user_id").primaryKey().references(() => data.userID),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey().references(() => users.userID),
// some other data here
});
it gives me a type error on both tables:
'data' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(
'data' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(
Any idea why this might be? Thanks for the help!
1 replies
DTDrizzle Team
Created by Liam on 3/6/2024 in #help
Using Drizzle w/ Postgrest
Hi! I was wondering if there is a way to use drizzle w/ postgrest so I can use drizzle on edge. I could not find anything about this in the docs so I thought I'd ask here. Thanks!
1 replies
RRailway
Created by Liam on 2/19/2024 in #✋|help
Install Newer Version of Node JS in Dockerfile
Howdy! I was wondering if anyone can help me modify this dockerfile to install a newer version of node. Thanks! Current Dockerfile
FROM alpine:3.14 AS build

WORKDIR /root

RUN apk add --update --no-cache nodejs npm

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

RUN npm install
RUN npm run build
RUN npm prune --production

FROM alpine:3.14

WORKDIR /root

COPY --from=build /root/node_modules ./node_modules
COPY --from=build /root/dist ./dist

RUN apk add --update --no-cache postgresql-client nodejs npm

ENTRYPOINT ["node", "dist/index.js"]
FROM alpine:3.14 AS build

WORKDIR /root

RUN apk add --update --no-cache nodejs npm

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

RUN npm install
RUN npm run build
RUN npm prune --production

FROM alpine:3.14

WORKDIR /root

COPY --from=build /root/node_modules ./node_modules
COPY --from=build /root/dist ./dist

RUN apk add --update --no-cache postgresql-client nodejs npm

ENTRYPOINT ["node", "dist/index.js"]
11 replies
RRailway
Created by Liam on 2/13/2024 in #✋|help
Running a Bun + pnpm Application on Railway
Hi! I have a monorepo where I use pnpm + turborepo for repo & package managment. One of the apps in the repository, a discord bot, uses bun as its runtime, but still uses pnpm for the actual package installation. Any idea how I can go about getting this working w/ nixpacks / railway? Thanks!
63 replies
DTDrizzle Team
Created by Liam on 2/5/2024 in #help
Invalid Input Value for Enum
Hello! I am using a enum but running into a weird issue when trying to set the value as one of options in enum. The following is the sections from my schema: Error: Error: invalid input value for enum status: "expired" Drizzle Schema Table:
export const discordVerification = pgTable("discord_verification", {
code: varchar("code", { length: 255 }).notNull().primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
clerkID: varchar("clerk_id", { length: 255 }),
discordUserID: varchar("discord_user_id", { length: 255 }),
discordUserTag: varchar("discord_user_tag", { length: 255 }),
discordProfilePhoto: varchar("discord_profile_photo", { length: 255 }),
discordName: varchar("discord_name", { length: 255 }),
status: discordVerificationStatus("status").notNull().default("pending"),
});
export const discordVerification = pgTable("discord_verification", {
code: varchar("code", { length: 255 }).notNull().primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
clerkID: varchar("clerk_id", { length: 255 }),
discordUserID: varchar("discord_user_id", { length: 255 }),
discordUserTag: varchar("discord_user_tag", { length: 255 }),
discordProfilePhoto: varchar("discord_profile_photo", { length: 255 }),
discordName: varchar("discord_name", { length: 255 }),
status: discordVerificationStatus("status").notNull().default("pending"),
});
Drizzle Schema Enum:
export const discordVerificationStatus = pgEnum("status", [
"pending",
"expired",
"accepted",
"rejected",
]);
export const discordVerificationStatus = pgEnum("status", [
"pending",
"expired",
"accepted",
"rejected",
]);
Any idea why this might be? Thanks!
5 replies
TTCTheo's Typesafe Cult
Created by Liam on 1/16/2024 in #questions
Run Both Node and Bun Apps In a Turborepo
Hello, I was wondering if it possible to run both bun and node apps within the same turbo repo. I tried following the following guide, but it leads to alot of weird issues, including one where bun seems to be trying to install weird dependencies from other packages the bun app does not rely on. Any idea how I can do this? Thanks! Guide: https://dev.to/0xahmad/running-both-nodejs-and-bun-apps-in-turborepo-33id
2 replies
DTDrizzle Team
Created by Liam on 12/27/2023 in #help
Drizzle query with where clause and primary composite key
Hello, I have defined a composite key and am now trying to run a drizzle query to lookup the event where that key exists. I have defined the following query, is this the fastest way to go about doing this lookup? Thanks! Drizzle Schema Table:
export const scans = pgTable(
"scans",
{
createdAt: timestamp("created_at").notNull().defaultNow(),
userID: varchar("user_id", { length: 255 }).notNull(),
eventID: integer("event_id").notNull(),
count: integer("count").notNull(),
},
(table) => ({
id: primaryKey({ columns: [table.userID, table.eventID] }),
})
);
export const scans = pgTable(
"scans",
{
createdAt: timestamp("created_at").notNull().defaultNow(),
userID: varchar("user_id", { length: 255 }).notNull(),
eventID: integer("event_id").notNull(),
count: integer("count").notNull(),
},
(table) => ({
id: primaryKey({ columns: [table.userID, table.eventID] }),
})
);
Lookup:
const scan = await db.query.scans.findFirst({
where: and(eq(scans.eventID, eventID), eq(scans.userID, userID)),
});
const scan = await db.query.scans.findFirst({
where: and(eq(scans.eventID, eventID), eq(scans.userID, userID)),
});
Thanks for the help!
2 replies
TTCTheo's Typesafe Cult
Created by Liam on 12/21/2023 in #questions
Any idea if @vercel/kv supports piping?
Question is pretty much in title. Docs for the SDK are pretty poor sadly :/
4 replies
RRailway
Created by Liam on 8/31/2023 in #✋|help
Errors Installing Cal.com Template
Hello, I am running into issues installing the cal template. Error: ERROR: failed to solve: process "/bin/bash -ol pipefail -c yarn install --check-cache" did not complete
5 replies
TTCTheo's Typesafe Cult
Created by Liam on 8/1/2023 in #questions
Type Errors When Using File Input w/ react-hook-form & shadcn/ui
Hello! I was wondering if anyone has an example of them using react-hook-form and shadcn/ui for a file upload. I have been attempting to add this to a <Form /> but I am running into various type errors. I made a issue which goes a little more into depth about the issues I am running into: https://github.com/shadcn-ui/ui/issues/1085 Thanks for the help!
2 replies
TTCTheo's Typesafe Cult
Created by Liam on 7/29/2023 in #questions
Question About Drizzle Composite Keys
I posted this over on the drizzle server and wanted to crosspost it here in case anyone can take a look at it. Thanks! https://discord.com/channels/1043890932593987624/1134887847271346186/1134887847271346186
2 replies
DTDrizzle Team
Created by Liam on 7/29/2023 in #help
Cannot Access Primary Key on Table
Hello, I am trying to access the primary key named id on the following table:
export const invites = mysqlTable(
"invites",
{
inviteeID: varchar("invitee_id", { length: 255 }).notNull(),
teamID: varchar("team_id", { length: 50 }).notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
status: mysqlEnum("status", ["pending", "accepted", "declined"]).notNull().default("pending"),
},
(table) => ({
id: primaryKey(table.inviteeID, table.teamID),
})
);
export const invites = mysqlTable(
"invites",
{
inviteeID: varchar("invitee_id", { length: 255 }).notNull(),
teamID: varchar("team_id", { length: 50 }).notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
status: mysqlEnum("status", ["pending", "accepted", "declined"]).notNull().default("pending"),
},
(table) => ({
id: primaryKey(table.inviteeID, table.teamID),
})
);
I am using the following command to try to update a row but I am getting an error and the id field does not show on the invite. Any idea why this might be? Thanks!
await db.update(invites).set({ status: "accepted" }).where(eq(invites.id, user.invites[0].id));
await db.update(invites).set({ status: "accepted" }).where(eq(invites.id, user.invites[0].id));
4 replies
TTCTheo's Typesafe Cult
Created by Liam on 7/28/2023 in #questions
TS Allow Certain Response Bodies
Hello, I would like to add a type I can use on my applications for checking the type of responses based on a zod validator. I have wrote the following type:
import { z, type ZodType } from "zod";
import type { NextResponse } from "next/server";

const unauthedRes = new Response("Unauthorized", { status: 401 });
export type serverZodResponse<T extends ZodType<any, any, any>> = Promise<
undefined | NextResponse<z.infer<T>>
>;
import { z, type ZodType } from "zod";
import type { NextResponse } from "next/server";

const unauthedRes = new Response("Unauthorized", { status: 401 });
export type serverZodResponse<T extends ZodType<any, any, any>> = Promise<
undefined | NextResponse<z.infer<T>>
>;
I would like to add a Response with a body of Unauthorized and a status of 401 to the type inside the Promise. Is there anyway to do this? Thanks!
2 replies
TTCTheo's Typesafe Cult
Created by Liam on 7/27/2023 in #questions
Add Generic To Response in Next
Hi, I am trying to type my return with NextResponse.json() in a next js API route. Any idea how I can do this? Thanks!
7 replies
TTCTheo's Typesafe Cult
Created by Liam on 7/23/2023 in #questions
Config RSC on Edge
Hi, If I want to run RSC on edge do I need to put export const runtime = edge in the components too or just the page and then it will waterfall that down to the components? Thanks!
2 replies