Closed statusunknown418 closed 11 months ago
Is this solved yet? I'm having the same issue
I managed to solve this by using the regular connection details - USERNAME, PASSWORD, HOST, and only using the connection_url to do db:push @juancamiloqhz
I managed to solve this by using the regular connection details - USERNAME, PASSWORD, HOST, and only using the connection_url to do db:push @juancamiloqhz
Thanks for your answer @statusunknown418. I solved this issue with a new database instance in planetscale. For some reason, my existing database was unable to connect with the new app I'm making.
great!, closing this then
The docs are outdated. Whe following the steps on planetsclale, they don't offer a connection string anymore. The example connection code in T3 should be updated with the new one PlanetScale provides.
this works for me
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import { env } from "~/env";
import * as schema from "./schema";
const connection = await mysql.createConnection({
uri: env.DATABASE_URL
});
export const db = drizzle(connection, { schema, mode: "default" });
Provide environment information
System: OS: macOS 14.0 CPU: (8) arm64 Apple M1 Pro Memory: 241.38 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node Yarn: 1.22.19 - ~/Library/pnpm/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm pnpm: 8.6.6 - /opt/homebrew/bin/pnpm Watchman: 2023.09.25.00 - /opt/homebrew/bin/watchman
Describe the bug
basically the way of connecting safely to planetscale with drizzle should be by using
PORT
,USERNAME
andPASSWORD
instead of adatabaseUrl
in thedb/index.ts
and the latter should only be used for thedrizzle.config.ts
db/index.ts
import { env } from "~/env.mjs"; import * as schema from "./schema";
export const db = drizzle( new Client({ url: env.DATABASE_URL, }).connection(), { schema } );
Note that .env is:
same error is thrown
import { connect } from "@planetscale/database"; import { drizzle } from "drizzle-orm/planetscale-serverless";
// create the connection const connection = connect({ host: env.DATABASE_HOST, username: env.DATABASE_USERNAME, password: env.DATABASE_PASSWORD, });
export const db = drizzle(connection, { schema });