db-postgres
db-postgres copied to clipboard
Is this gem usable?
I want to update the benchmarks in the techempower benchmarks suite. I would like set up a falcon benchmark using database access so I want to make sure I am using something that will take advantage of the increased concurrency of falcon. This is not production use so maybe it's a good test?
Yes, it is usable.
Does this lib set up a connection pool or is that not even applicable in this case? Would setting up a connection pool help at all?
It uses a connection pool internally based on async-pool
IIRC.
I was just reading the readme in the pg gem and it says it's compatible with Fiber.scheduler. Have you looked at its implementation at all?
Yes it's compatible, but I'm not sure the performance, it's probably "good enough".
@ioquatix Is there a way to make this work with ActiveRecord?
Not yet but we are working on it, progress is being made in Rails 7.1 but it probably won’t be fully compatible until Rails 8+
Similar question: is there an alternative to this smiley-DSL:
.clause(")")
# or this
.clause("), (")
I think all this strings concatenation/methods call introduce the overhead we want to eliminate using beautiful async
gem :) (just kidding, it just looks strange)
Thanks!
You can use the #query
method as shown in the documentation: https://github.com/socketry/db-postgres?tab=readme-ov-file#11-a-simple-create-insert-and-select-with-raw-sql
@ioquatix sure, for 2% of queries, the rest 98% usually parametrized. I think i need to find lightweight query bulder lib. Probably pg gem provides some sort of, don’t want another dep in project Thanks!
The #query
method supports interpolation: https://socketry.github.io/db/guides/executing-queries/index.html#interpolation-method
FYI, you must use symbols for identifiers (table / column names) as otherwise there is no way to correctly quote values (strings, integers, etc).
The DB gem forces you to correctly quote all fields, otherwise you'll end up with injection attacks.