Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 46 lines (28 sloc) 1.602 kb
7a0e083 Foy Savas Create dm-aggregates (only has count method for now)
foysavas authored
1 dm-aggregates
2 =============
324d475 Alex Coles Cleaned up README, TODOs
myabc authored
3
53272c2 Abdul-Rahman Advany updated dm-aggregates/README and README
advany authored
4 DataMapper plugin providing support for aggregates, functions on collections and datasets.
5
6 It provides the following functions:
7
8 == count
9
10 Count results (given the conditions)
11
046328b Alex Coles Whitespace cleanup
myabc authored
12 Friend.count # returns count of all friends
13 Friend.count(:age.gt => 18) # returns count of all friends older then 18
14 Friend.count(:conditions => [ 'gender = ?', 'female' ]) # returns count of all your female friends
682ff7d Alex Coles Typo fix in docs
myabc authored
15 Friend.count(:address) # returns count of all friends with an address (NULL values are not included)
16 Friend.count(:address, :age.gt => 18) # returns count of all friends with an address that are older then 18
17 Friend.count(:address, :conditions => [ 'gender = ?', 'female' ]) # returns count of all your female friends with an address
53272c2 Abdul-Rahman Advany updated dm-aggregates/README and README
advany authored
18
19 == min
20
21 Get the lowest value of a property
22
046328b Alex Coles Whitespace cleanup
myabc authored
23 Friend.min(:age) # returns the age of the youngest friend
24 Friend.min(:age, :conditions => [ 'gender = ?', 'female' ]) # returns the age of the youngest female friends
53272c2 Abdul-Rahman Advany updated dm-aggregates/README and README
advany authored
25
26 == max
27
28 Get the highest value of a property
29
046328b Alex Coles Whitespace cleanup
myabc authored
30 Friend.max(:age) # returns the age of the oldest friend
31 Friend.max(:age, :conditions => [ 'gender = ?', 'female' ]) # returns the age of the oldest female friends
53272c2 Abdul-Rahman Advany updated dm-aggregates/README and README
advany authored
32
33 == avg
34
35 Get the average value of a property
36
046328b Alex Coles Whitespace cleanup
myabc authored
37 Friend.avg(:age) # returns the average age of friends
38 Friend.avg(:age, :conditions => [ 'gender = ?', 'female' ]) # returns the average age of the female friends
53272c2 Abdul-Rahman Advany updated dm-aggregates/README and README
advany authored
39
40 == sum
41
42 Get the total value of a property
43
046328b Alex Coles Whitespace cleanup
myabc authored
44 Friend.sum(:age) # returns total age of all friends
45 Friend.max(:age, :conditions => [ 'gender = ?', 'female' ]) # returns the total age of all female friends
Something went wrong with that request. Please try again.