db-postgres icon indicating copy to clipboard operation
db-postgres copied to clipboard

Is this gem usable?

Open timuckun opened this issue 1 year ago • 11 comments

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?

timuckun avatar Apr 27 '23 09:04 timuckun

Yes, it is usable.

ioquatix avatar Apr 27 '23 10:04 ioquatix

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?

timuckun avatar Apr 27 '23 10:04 timuckun

It uses a connection pool internally based on async-pool IIRC.

ioquatix avatar Apr 27 '23 11:04 ioquatix

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?

timuckun avatar Apr 27 '23 21:04 timuckun

Yes it's compatible, but I'm not sure the performance, it's probably "good enough".

ioquatix avatar Apr 27 '23 23:04 ioquatix

@ioquatix Is there a way to make this work with ActiveRecord?

usman-anwar-mindoula avatar May 04 '23 21:05 usman-anwar-mindoula

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+

ioquatix avatar May 06 '23 10:05 ioquatix

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!

qd3v avatar Feb 10 '24 15:02 qd3v

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 avatar Feb 10 '24 22:02 ioquatix

@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!

qd3v avatar Feb 11 '24 10:02 qd3v

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.

ioquatix avatar Feb 11 '24 21:02 ioquatix