On Thu, Oct 7, 2021 at 12:46 AM armin <ar...@wurzweb.com> wrote:

> Hello Mr. Evans! Thank you for your Feedback!
>
> >> Most SQL can be put into Sequel's DSL.  You might need to use literal
> strings for part of it, but the only time you really cannot use Sequel's
> DSL if you are using database-specific clauses that Sequel doesn't
> support.  If you post the parts of the SQL you are using that you don't
> know how to translate to Sequel's DSL, I could probably help with that.
>
> Ok, yes I agree with you, but in my case it's a sql which is managed by
> BI-men and the query is adapted all the time. I don't want to translate
> their sql's all the time to great Sequel-DSL.
>

That definitely makes sense.


> >> It is almost always going to be a bad idea to provide custom SQL for a
> dataset when creating the model.  That would mean all access through the
> model would use the same SQL, regardless of what operation you were
> performing.
> In my case this is no big issue, because there will be only one access to
> the Model-Module (get bookings and their services paged). But I will go
> with the manual plain-hash-version, because I suspect that the
> performance is even a bit better, than the model approach (Please correct
> me if I'm wrong). Performance is very important for me. I have to load
> ten-thousands of bookings with their services.
>

Even though model object creation is very optimized, using plain hashes
will almost always result in better performance.  However, it's possible
the better performance will not be detectable as most of the time will be
spent in query execution.


> >> A couple problems here.  First, calling to_a on a eager dataset does
> not do eager loading, you have to call all (or use the eager_each
> extension).  Second, I couldn't reproduce the error you were getting.  Can
> you create a self contained example showing the problem
> Thank you for the hints. Here's the self contained example, where I
> observe the error:
>
> class Service < Sequel::Model(DAVINCI_DB["select 2 \"id\", '1' \"
> booking_id\", 'Service Hotel' \"name\""])
> end
>
> class Booking < Sequel::Model(DAVINCI_DB["select 1 \"id\", 'Booking
> Package Mallorca' \"name\""])
> one_to_many :services, class: Service, key: :booking_id
> end
>
> puts Booking.where(id: 1).all # this works, but only with
> implicit_subquery enabled
>
> puts Booking.eager(:services).all # this fails with Sequel::Error: No
> source specified for query
>
> >> If this is the only reason you are using models, I would probably do it
> manually.  You may find to_hash_groups useful for part 2.
> Thank you for the useful to_hash_groups-method. I will definitely use it
> to load the services, because then the allocation to the bookings is
> easier. I'm just a little concerned about the extra iteration over the
> bookings during the distribution, but the eager attempt will have that too,
> right?
>

Yes.  Almost definitely using to_hash_groups will be faster than using the
model association eager loading code.  Again, it's possible you wouldn't
notice the performance being better as most of the time is spent in query
execution.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSeKZyiO00gqabT%2BOhk94gZ3sipNPO4JUmJK_4dd548JnA%40mail.gmail.com.

Reply via email to