pecko0326
pecko0326
Explore posts from servers
DTDrizzle Team
Created by pecko0326 on 8/9/2024 in #help
MySQL Driver keeps asking for 'password' parameter
When trying to connect to my local MySQL database, to which I do not have any password setup, I get an error when running drizzle-kit migrate command. Here's my drizzle.config.ts file, I double checked the docs but I can't seem to figure out what I'm missing out:
import { defineConfig } from "drizzle-kit";

if (!process.env.DB_NAME) {
throw new Error("ERROR: 'DB_NAME' env is not setup correctly!");
}

if (!process.env.DB_HOST) {
throw new Error("ERROR: 'DB_HOST' env is not setup correctly!");
}

export default defineConfig({
schema: "./src/db/schema/*",
dialect: "mysql",
out: "./src/db/migrations",
migrations: {
prefix: "timestamp",
},
dbCredentials: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
strict: true,
verbose: true,
});
import { defineConfig } from "drizzle-kit";

if (!process.env.DB_NAME) {
throw new Error("ERROR: 'DB_NAME' env is not setup correctly!");
}

if (!process.env.DB_HOST) {
throw new Error("ERROR: 'DB_HOST' env is not setup correctly!");
}

export default defineConfig({
schema: "./src/db/schema/*",
dialect: "mysql",
out: "./src/db/migrations",
migrations: {
prefix: "timestamp",
},
dbCredentials: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
strict: true,
verbose: true,
});
In my .env file I have the fields setup, and the DB_PASSWORD variable has an empty string value as there's no password associated with the database user. The error that I get is Please provide required params for MySQL driver: and the password field is marked with an X and an empty string value.
2 replies
DTDrizzle Team
Created by pecko0326 on 3/14/2024 in #help
How to delete multiple rows whose value is contained in a list of values, at once?
If I want to delete multiple rows whose value (e.g. 'key') is included in a list of values, in raw SQL I can do something like this:
DELETE FROM example_table WHERE example_table.key IN (key1, key2, ...)
DELETE FROM example_table WHERE example_table.key IN (key1, key2, ...)
But, that seems to not be working correctly when using it in Drizzle, or I'm doing something completely wrong. Using MySQL. Here's my code:
const keysToDelete = ['key-1', 'key-2'];
await db
.delete(exampleTable)
.where(sql`${exampleTable.key} IN (${keysToDelete})`);
const keysToDelete = ['key-1', 'key-2'];
await db
.delete(exampleTable)
.where(sql`${exampleTable.key} IN (${keysToDelete})`);
I tried also joining the keys to delete as a single string using keysToDelete.join(",") but that also didn't work. The entries are not being removed from the database. However if I want to check against a single value within the IN (...) clause, it works fine.
2 replies