LuukOriginal
LuukOriginal
DTDrizzle Team
Created by LuukOriginal on 7/12/2024 in #help
Drizzle-zod typeerror when passing in pgtable
I keep getting a type error when trying to get the zod schema from the pg schema with drizzle: public.ts
import { pgTable, timestamp, serial, text, pgEnum } from 'drizzle-orm/pg-core'

export const TeamSubscriptionTier = pgEnum('team_subscription_tier', ['basic', 'team', 'enterprise']);

export const teams = pgTable('teams', {
/**
* The auto-incrementing ID of the team.
*/
id: serial('team_id').primaryKey(),

/**
* The timestamp when the team was created.
*/
created_at: timestamp('created_at', { withTimezone: false }).defaultNow().notNull(),

/**
* The name of the team.
*/
name: text('name').notNull(),

/**
* The description of the team.
*/
description: text('description'),

/**
* The subscription tier of the team.
*/
subcription_tier: TeamSubscriptionTier('subscription_tier')
});
import { pgTable, timestamp, serial, text, pgEnum } from 'drizzle-orm/pg-core'

export const TeamSubscriptionTier = pgEnum('team_subscription_tier', ['basic', 'team', 'enterprise']);

export const teams = pgTable('teams', {
/**
* The auto-incrementing ID of the team.
*/
id: serial('team_id').primaryKey(),

/**
* The timestamp when the team was created.
*/
created_at: timestamp('created_at', { withTimezone: false }).defaultNow().notNull(),

/**
* The name of the team.
*/
name: text('name').notNull(),

/**
* The description of the team.
*/
description: text('description'),

/**
* The subscription tier of the team.
*/
subcription_tier: TeamSubscriptionTier('subscription_tier')
});
contract.ts
import { initContract } from '@ts-rest/core';
import { z } from 'zod';
import { ErrorResponseSchema } from '@bloxgrid/common/dist/schemas/error-response.schema'
import { teams } from '@bloxgrid/common/src/database/schema/public'
import { createSelectSchema } from 'drizzle-zod'

const c = initContract();

export const teamsContract = c.router({
getTeams: {
method: 'GET',
path: '/',
query: z.object({
name: z.string().optional(),
}),
responses: {
200: createSelectSchema(teams), //teams here is giving the type error
400: ErrorResponseSchema
},
summary: 'Get a list of teams',
}
}, {
pathPrefix: '/teams' as const
});
import { initContract } from '@ts-rest/core';
import { z } from 'zod';
import { ErrorResponseSchema } from '@bloxgrid/common/dist/schemas/error-response.schema'
import { teams } from '@bloxgrid/common/src/database/schema/public'
import { createSelectSchema } from 'drizzle-zod'

const c = initContract();

export const teamsContract = c.router({
getTeams: {
method: 'GET',
path: '/',
query: z.object({
name: z.string().optional(),
}),
responses: {
200: createSelectSchema(teams), //teams here is giving the type error
400: ErrorResponseSchema
},
summary: 'Get a list of teams',
}
}, {
pathPrefix: '/teams' as const
});
14 replies