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 \n
s 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
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
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.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?
I also tried:
both with the same result.
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