On Mon, Dec 13, 2021 at 5:58 AM Tiago Cardoso <honeyryderch...@gmail.com> wrote:
> Hi, > > I'd like to know if there's a "public API" way of merging two datasets. > Something like, having the following: > > ``` > ds1 = db[table1].where(a: 1) > ds2 = db[table2].where(b: 2) > > # I'd like > ds1.merge(ds2) #=> would merge as where(a: 1, b: 2) > # I'm working around it by: > ds1.where(ds2.opts[:where]) > ``` > That's the expected way to go if you want to merge the WHERE conditions. >From your code, it looks like you take merging to mean returning rows that are in both datasets. At the relational level you are asking for a intersection, which Sequel also supports: ds1.intersect(ds2) Sequel will never support a generic Dataset#merge, because there is no guarantee that the two datasets are in any way compatible (could be different databases, tables, selections, orders, etc.). Potentially, something like: Dataset#merge_where could be added, where it explicitly only merged WHERE conditions without caring about other conditions. However, considering that it is already very easy to get that behavior using the following code: ds1.where(ds2.opts.fetch(:where, true)) I don't see the point in adding it. Note that fetch here is used instead of the code in your example, because your example doesn't correctly handle the case where ds2 has no WHERE clause 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/CADGZSSfTGnhFMV%2B3w6xWzNaSHKRk%2BRQWbagY43k-QukdCzygYw%40mail.gmail.com.