On Tue, Apr 20, 2021 at 7:58 AM Thibaut Barrère <[email protected]> wrote:
> Hello! > > In a company I'm working with, there is a coding department (typically > working with Ruby & Sequel), and then there is another department for > data-oriented/analytics work (no code, leveraging tools like SQL, Tableau > etc). > > In a number of cases, the data department has created some large SQL > queries for analytics, which are then handed over to the coding department. > > I have two Sequel-specific questions related to this: > > 1/ Is there an easy way to enrich an existing SQL query, without rewriting > the query itself into the Sequel DSL? > > To be more specific, I would like to reuse the query, but add an extra > "AND order_id between X AND Y" or similar small stuff, to allow gradual > data capture (N small queries with resumable synchronisation, instead of 1 > big query which tend to time out). > > One way would be to issue a subquery (SELECT * from (... the raw sql) > WHERE ...). > You can do this via: DB[sql_string].from_self.where(...) > Another way would be to parse the query, and append stuff programmatically. > Sequel does not do this and will never do this. One of Sequel's primary philosophies is that it never attempts to parse SQL. > We are already using some form of "placeholders" and/or ERB templating for > that purpose, but I wonder if something cleaner is possible with Sequel ? > If you can modify the SQL queries to use placeholders, or use ERB to change the SQL string before passing it to Sequel, those are certainly additional options. > 2/ I love to have Sequel logging activated, but for these specific > queries, the log is just huge. Is there a way to disable the logging on a > per-query basis only? > There's no built in way. You could use a custom logger that skips logging if the log messages contain a certain comment (which you could add via the sql_comments extension). Or you could do something like this (not really per query, but can be localized): def DB.log_connection_yield(*) super unless Thread.current[:skip_sequel_logging] end def DB.skip_logging skip_logging = Thread.current[:skip_sequel_logging] Thread.current[:skip_sequel_logging] = true ensure Thread .current[:skip_sequel_logging] = skip_logging end DB.skip_logging do # run whatever queries you don't want to log end 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSScN_03VJaHqF_onG_8_aH8EHuLmzJgk%3DPYFUunPpD%3DumQ%40mail.gmail.com.
