potato
Explore posts from serversDTDrizzle Team
•Created by potato on 11/11/2023 in #help
Can't figure out this simple one-to-many relationship
Hey, so i have two tables, a patient one and a village one.
I just want to define a simple one-to-many, one village for many patients, what am I missing here? My villageRelations is throwing type errors
export const patient = mysqlTable("patient", {
id: serial("id").primaryKey(),
firstName: varchar("firstName", { length: 256 }).notNull(),
middleName: varchar("middleName", { length: 256 }),
lastName: varchar("lastName", { length: 256 }).notNull(),
dob: date("dob", { mode: "date" }).notNull(),
sex: varchar("sex", { length: 32 }),
villageId: int("villageId"),
createdAt: datetime("createdAt", { mode: "date", fsp: 3 })
.default(sql
CURRENT_TIMESTAMP(3))
.notNull(),
updatedAt: datetime("updatedAt", { mode: "date", fsp: 3 })
.default(sql
CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3))
.notNull(),
});
export const patientRelations = relations(patient, ({ one }) => ({
village: one(village, {
fields: [patient.villageId], // Referencing villageId in patient table
references: [village.id], // Referencing id in village table
}),
}));
and
export const village = mysqlTable("village", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
region: varchar("region", { length: 256 }),
population: int("population"),
createdAt: datetime("createdAt", { mode: "date", fsp: 3 })
.default(sql
CURRENT_TIMESTAMP(3))
.notNull(),
updatedAt: datetime("updatedAt", { mode: "date", fsp: 3 })
.default(sql
CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3))
.notNull(),
});
export const villageRelations = relations(village, ({ many }) => ({
patients: many(patient, {
fields: [patient.villageId], // Referencing villageId in patient table
references: [village.id], // Referencing id in village table
}),
}));
2 replies
DTDrizzle Team
•Created by potato on 4/10/2023 in #help
[BUG] drizzle-kit doesn't like imports outside of a module
npx drizzle-kit generate:pg
drizzle-kit: v0.17.4
drizzle-orm: v0.23.10
C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\src\env.mjs:2
import { z } from "zod";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1088:15)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._compile (C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\drizzle-kit\index.js:20706:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Object.newLoader [as .mjs] (C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\drizzle-kit\index.js:20710:13)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
24 replies
DTDrizzle Team
•Created by potato on 4/10/2023 in #help
drizzle-kit throwing await is not available in the configured target environment
Hi, when using the generate:pg command i am getting this error: 'Top-level await is not available in the configured target environment ("node14")'
5 replies