Live data from Hacker News

PostgresJs: PostgreSQL client for Node.js and Deno

github.com

51–60 of 148 posts

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#51

[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.

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#52
post #49

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

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#53
post #49

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.

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#55
post #49

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

What do you mean? This is true for any template string, not specifically the tagged template strings, no?

Edit: I think I understand now from the other comment, thanks!

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#56
post #49

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.

Ohhh got it, thanks!

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#57
post #8

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/

Prisma is great for schema management, but it's migration stuff broke for us and their updateMany implementation is just plain dumb.

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.

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#58
post #5

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 should be, now that pg runs fine there. If it’s not, please file an issue!

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

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#59

[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.

If you find it beautiful, who cares what I think?

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.

Re: PostgresJs: PostgreSQL client for Node.js and Deno

#60
post #17
post #5

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.

It does now support multiple schemas: https://jawj.github.io/zapatos/#60
Post reply on HN