Kawthar
Kawthar
Explore posts from servers
DTDrizzle Team
Created by Kawthar on 9/30/2024 in #help
Types error with where filter
No description
2 replies
DTDrizzle Team
Created by Kawthar on 9/10/2024 in #help
Type mismatch between tables from schema and drizzle-orm functions
I am getting an error for type mismatch while trying a simple db.delete(table) query:
Argument of type 'PgTableWithColumns<{...columns}, {}, {}>; title: PgColumn<...>; desiredWeeklyFrequency...' is not assignable to parameter of type 'PgTable<TableConfig>'
Argument of type 'PgTableWithColumns<{...columns}, {}, {}>; title: PgColumn<...>; desiredWeeklyFrequency...' is not assignable to parameter of type 'PgTable<TableConfig>'
.How can I fix this? These are the related files:
// schema.ts
import { createId } from '@paralleldrive/cuid2';
import { integer, pgTable, text, timestamp } from 'drizzle-orm/pg-core';

export const goals = pgTable('goals', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
title: text('title').notNull(),
desiredWeeklyFrequency: integer('desired_weekly_frequency').notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
});

export const completedGoals = pgTable('completed_goals', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
goalId: text('goal_id')
.references(() => goals.id, { onDelete: 'cascade' })
.notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
});
// schema.ts
import { createId } from '@paralleldrive/cuid2';
import { integer, pgTable, text, timestamp } from 'drizzle-orm/pg-core';

export const goals = pgTable('goals', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
title: text('title').notNull(),
desiredWeeklyFrequency: integer('desired_weekly_frequency').notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
});

export const completedGoals = pgTable('completed_goals', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
goalId: text('goal_id')
.references(() => goals.id, { onDelete: 'cascade' })
.notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
});
// seed.ts
import dayjs from 'dayjs';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import env from '../env';
import * as schema from './schema';

export const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, { schema, logger: true });

async function seed() {
await db.delete(schema.goals);
}

seed().finally(() => {
client.end();
process.exit();
});
// seed.ts
import dayjs from 'dayjs';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import env from '../env';
import * as schema from './schema';

export const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, { schema, logger: true });

async function seed() {
await db.delete(schema.goals);
}

seed().finally(() => {
client.end();
process.exit();
});
1 replies