On Sat, Oct 8, 2022 at 1:12 AM Thiebo <[email protected]> wrote:
> Hello,
>
> I currently do this:
>
> # create empty array to which result of dataset will be pushed
> results = []
>
> # get the Sequel dataset
> DB[:entrees]
> .join(:categories, id: :categorie_id)
> .select{[ entrees[:id], entrees[:date_de_valeur], entrees[:intitule],
> entrees[:montant], entrees[:recurrent], categories[:intitule].as(:
> categorie) ]}
> .where(Sequel.lit('entrees.account_id = ?', accountid))
> .where(Sequel.lit('extract(MONTH FROM date_de_valeur) = ?', month))
> .where(Sequel.lit('extract(YEAR FROM date_de_valeur) = ?', year))
> .order(:date_de_valeur)
> .each{ |ligne| results.push(ligne) }
>
> It works, although this is probably not the most concise way to doing
> this.
>
>
Sequel.extract(:month, :date_de_valuer)
Sequel.extract(:year, :date_de_valuer)
Note that it may be faster to use an approach such as:
date = Date.new(year,month)
DB[:entrees]
...
where(:date_de_valeur=>date...(date >> 1))
Also, note that you can do:
results = DB[:entrees]
...
.all # instead of .each with block
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/CADGZSSe%3DpnxH4edPLC1DembnS7aEfakk%3D1zzMWEmqU0guyH7Mw%40mail.gmail.com.