Re: extract - there must be a better way

2022-10-09 Thread Thiebo
thanks a lot !


Le samedi 8 octobre 2022 à 20:39:43 UTC+2, Jeremy Evans a écrit :

> On Sat, Oct 8, 2022 at 1:12 AM Thiebo  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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/f972058d-8054-47e6-9107-462aa8f02b99n%40googlegroups.com.


Re: extract - there must be a better way

2022-10-08 Thread Jeremy Evans
On Sat, Oct 8, 2022 at 1:12 AM Thiebo  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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSe%3DpnxH4edPLC1DembnS7aEfakk%3D1zzMWEmqU0guyH7Mw%40mail.gmail.com.


extract - there must be a better way

2022-10-08 Thread Thiebo
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. 

Thanks !

-- 
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/beb66458-6abb-447c-9179-a4288187fbb1n%40googlegroups.com.