[flagged]
What you might find ugly, others find beautiful. I'm actually pretty proud of this lib, and i enjoy my style of coding. Your comment doesn't change that, it just kills a lot energy.
51–60 of 148 posts
[flagged]
What you might find ugly, others find beautiful. I'm actually pretty proud of this lib, and i enjoy my style of coding. Your comment doesn't change that, it just kills a lot energy.
Can anyone explain to me the purpose of tagged template strings? From what I understand it’s only a function that takes in a string, so this might have just been sql(‘…’).
Can anyone explain to me the purpose of tagged template strings? From what I understand it’s only a function that takes in a string, so this might have just been sql(‘…’).
[flagged]
Can anyone explain to me the purpose of tagged template strings? From what I understand it’s only a function that takes in a string, so this might have just been sql(‘…’).
You can use expressions inside template literals and those are auto-escaped for you by postgres.js
Edit: I think I understand now from the other comment, thanks!
Can anyone explain to me the purpose of tagged template strings? From what I understand it’s only a function that takes in a string, so this might have just been sql(‘…’).
Tags are functions that receive an array of strings and then a series of arguments corresponding to values passed in the interpolation slots, allowing you to use template literal syntax while the tag function does something much more complex under the hood, potentially including returning non-string values.
For people who would like a more safe and structured approach (but almost as powerful and with the option to resort to SQL strings if needed) I highly recommend checking out Prisma https://www.prisma.io/
We just use db push because prisma migrate fucked up in some unknown way that is impossible to recover from. The process in the docs for re-baselining doesn't work, and we're not about to reset our database.
The problem with ORMs is always that if something goes wrong you need to understand why, but then you need to also understand what the orm is doing. So it doesn't really abstract the database away, it just makes it easier to use. Or if you don't understand your database you're SOL. I mean, there was a big transaction isolation bug that you now have to deal with...which if you knew anything about databases you would have dealt with anyway.
Also, they pack a bunch of prebuilt binary handlers with their stuff, which makes using it awkward in serverless code.
I feel obliged to namedrop Zapatos here, another postgres JS client with a remarkably similar design (sql in template strings), but fully typesafe. If TypeScript is your thing, you might appreciate it: https://jawj.github.io/zapatos/ Personally I feel it’s one of the best designed (and documented) TS libraries out there and I’m sad it’s not very well known.
At first glance Zapatos doesn't appear to be Cloudflare workers compatible though I'd love to be corrected.
It also works with @neondatabase/serverless on platforms without TCP connections (though it’s on my TODO list to make this less fiddly): https://github.com/neondatabase/neon-vercel-zapatos
[flagged]
I think you should just keep a thing like this to yourself. It's attitudes like this that keeps people from daring to share their code with the world. What you might find ugly, others find beautiful. I'm actually pretty proud of this lib, and i enjoy my style of coding. Your comment doesn't change that, it just kills a lot energy.
You aren't writing this for public opinions, presumably.
I've also written a Postgres wire protocol implementation and a blog post on how to do so, which people are welcome to say "It's terrible" about if they wish.
I feel obliged to namedrop Zapatos here, another postgres JS client with a remarkably similar design (sql in template strings), but fully typesafe. If TypeScript is your thing, you might appreciate it: https://jawj.github.io/zapatos/ Personally I feel it’s one of the best designed (and documented) TS libraries out there and I’m sad it’s not very well known.
We had to abandon Zapatos because a) it doesn’t support multiple schemas; b) the types wouldn’t always be very readable. PgTyped was the alternative, and 2 years later I’m very glad we made the switch.