Next14, Drizzle, Vercel Postgres
Unanswered
David L. Bowman posted this in #help-forum
I've done everything the documentation recommended https://vercel.com/docs/storage/vercel-postgres/using-an-orm#drizzle, but I'm getting the attached image's error.
Any idea why?
// envConfig.ts
import { loadEnvConfig } from "@next/env"
const projectDir = process.cwd()
loadEnvConfig(projectDir)// db.ts
import "@/drizzle/envConfig"
import { sql } from "@vercel/postgres"
import { drizzle } from "drizzle-orm/vercel-postgres"
import * as schema from "./schema"
import type { User } from "@/utilities/registerUser"
export const db = drizzle(sql, {
schema
})
export const getUsers = async () => {
return db.query.UsersTable.findMany()
}
export const insertUser = async ({
firstName,
lastName,
email,
password
}: User) => {
await db.insert(schema.UsersTable).values({
firstName,
lastName,
email,
password
})
}Any idea why?
2 Replies
I'm able to get this working by moving my
Although, it's confusing, because according to the documentation, we'd want them in the
Also, I have NO IDEA why
I'd love some clarity here if possible.
insertUser ( ... ) to a separate utility function and adding "use server" at the top.const insertUser = async () => {
await db.insert(schema.UsersTable).values({
firstName: "David",
lastName: "Bowman",
email: "david@theinnovationlab.dev",
password: "password"
})
}Although, it's confusing, because according to the documentation, we'd want them in the
db.ts file. Also, I have NO IDEA why
registerUser.ts isn't "use server" by default. I'd love some clarity here if possible.
Should my insertUser function be somewhere else?