mh
mh
Explore posts from servers
DTDrizzle Team
Created by mh on 5/5/2025 in #help
How to type a table with common column names ?
Hey, I have a couple tables that have some common column names, ex.
export const appointments = coreSchema.table(
"appointments",
{
id: primaryKey(),
accountId: foreignKey("account_id")
.references(() => accounts.id)
.notNull(),
}
);

export const clients = coreSchema.table(
"clients",
{
id: primaryKey(),
accountId: foreignKey("account_id")
.references(() => accounts.id)
.notNull(),
}
)
export const appointments = coreSchema.table(
"appointments",
{
id: primaryKey(),
accountId: foreignKey("account_id")
.references(() => accounts.id)
.notNull(),
}
);

export const clients = coreSchema.table(
"clients",
{
id: primaryKey(),
accountId: foreignKey("account_id")
.references(() => accounts.id)
.notNull(),
}
)
I want to be able to write a shared function that can be used to build queries with the account_id where condition already added to it, something like this
export const getQuery = (table: Table, accountId: string) => {
const qb = new QueryBuilder();
return qb.select().from(table).where(eq(table.accountId, accountId));
};
export const getQuery = (table: Table, accountId: string) => {
const qb = new QueryBuilder();
return qb.select().from(table).where(eq(table.accountId, accountId));
};
How should the type Table be defined here? I've tried something like this
interface Table extends PgTable {
accountId: PgColumn;
}
interface Table extends PgTable {
accountId: PgColumn;
}
Is this a good/acceptable way to do it, or is there a more built-in drizzle type that can cover such scenarios?
1 replies
TtRPC
Created by mh on 10/18/2024 in #❓-help
Types issues upgrading to v11, `never` when using t.router
Hi, we have a mono repo project that we are trying to upgrade from v10.45.2 to v11(next). However, we are running into a weird types issue. This codebase was/is working completely fine with v10.45.2 but upgrading package versions seems to be causing types issues. Maybe we have missed something. We have a base trpc defined in a shared package trpc-shared.
import { initTRPC } from "@trpc/server";
import { setupHttpLogging } from "../http/log.js";
import type { Context } from "./context.js";

const t = initTRPC.context<Context>().create();

const { router, middleware, mergeRouters } = t;
const procedure = t.procedure.use(async (opts) => {
const { ctx, next } = opts;
const { request, response } = ctx;
setupHttpLogging(request, response);
// some additional setup...
const result = await next(...);

return result;
});

export { router, middleware, mergeRouters, procedure };
import { initTRPC } from "@trpc/server";
import { setupHttpLogging } from "../http/log.js";
import type { Context } from "./context.js";

const t = initTRPC.context<Context>().create();

const { router, middleware, mergeRouters } = t;
const procedure = t.procedure.use(async (opts) => {
const { ctx, next } = opts;
const { request, response } = ctx;
setupHttpLogging(request, response);
// some additional setup...
const result = await next(...);

return result;
});

export { router, middleware, mergeRouters, procedure };
Now, over in our api project, we consume the router to create some endpoints.
import { Context, procedure, router } from "trpc-server-shared"; // our shared project
import { type inferRouterInputs } from "@trpc/server";

export const appRouter = router({
health: router({ check: procedure.query(() => ({ healthy: "ok" })) })
});

type AppRouter = typeof appRouter;
type AppRouterInputs = inferRouterInputs<AppRouter>;
import { Context, procedure, router } from "trpc-server-shared"; // our shared project
import { type inferRouterInputs } from "@trpc/server";

export const appRouter = router({
health: router({ check: procedure.query(() => ({ healthy: "ok" })) })
});

type AppRouter = typeof appRouter;
type AppRouterInputs = inferRouterInputs<AppRouter>;
However, the type of AppRouterInputs is
type AppRouterInputs = {
health: never;
}
type AppRouterInputs = {
health: never;
}
The types were working fine with v10.45.2 and the only change is the package updates, no other code changes (and based on the migration guide and our current existing code base, no breaking changes were affecting our codebase). Clearing node_modules and reinstalling/rebuilding does not help.
"@trpc/client": "next",
"@trpc/server": "next",
"@trpc/client": "next",
"@trpc/server": "next",
5 replies