How to store/query multi-line text in database?

Hey there! I'm currently having some problems storing (or querying; actually not quite sure where the problem lies) multi-line texts in my MySQL database using Drizzle. When I use drizzle or drizzle studio to write a string like "Hello\nWorld!" to the database and then query it, it comes back with all \ns escaped. As a temporary workaround, I can do .replaceAll("\\n", "\n") on every string, but that doesn't seem like the ideal option.
5 Replies
Angelelz
Angelelz2w ago
How are you trying to view the string? It might be what you’re using to render it. I find it hard to believe that the replaceAll is actually doing anything
CRUGG
CRUGGOP2w ago
console.log and using the yaml library. When provided with Hello\nWorld! directly, console.log logs with the newlines and yaml works. When writing, then querying and using the same string through Drizzle, console.log logs \n literally and yaml library throws an exception (since yaml is dependant on newlines) And if I run the replaceAll on the result from Drizzle, it all behaves as before again.
Angelelz
Angelelz2w ago
Ohhh, sorry I didn’t notice the two back slashes in the first one Can I see how are you inserting the values on the db?
CRUGG
CRUGGOP2w ago
await db
.update(serversTable)
.set({
config: "Hello\nWorld"
})
.where(eq(serversTable.id, "123"))
.execute();
await db
.update(serversTable)
.set({
config: "Hello\nWorld"
})
.where(eq(serversTable.id, "123"))
.execute();
I also tried:
// ...
.set({
config: `Hello
World`
})
// ...
// ...
.set({
config: `Hello
World`
})
// ...
both with the same result.
Angelelz
Angelelz2w ago
Interesting, I looked into drizzle code and didn’t find anything in drizzle escaping the back slashes You should test the mysql2 driver directly and see if it has the same behavior
Want results from more Discord servers?
Add your server