Skip to content

Commit 4588528

Browse files
author
Carlos Silva
committed
Update readmin rdoc
1 parent 490d95c commit 4588528

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

README.rdoc

+76-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A short rundown of some of the major features:
1616
It creates a separated class to hold each enum set that can be used by multiple
1717
models, it also keeps the database consistent. The enum type is known to have
1818
better performance against string- and integer-like enums.
19-
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.2/static/datatype-enum.html]
19+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/static/datatype-enum.html]
2020

2121
create_enum :roles, %i(visitor manager admin)
2222

@@ -28,11 +28,84 @@ better performance against string- and integer-like enums.
2828

2929
{Learn more}[link:classes/Torque/PostgreSQL/Attributes/Enum.html]
3030

31+
* Enum set type manager
32+
33+
The enum type is known to have a better performance against string- and integer-
34+
like enums. Now with the array option, which behaves like binary assignment,
35+
each record can have multiple enum values.
36+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/static/datatype-enum.html]
37+
38+
create_enum :permissions, %i(read write exec)
39+
40+
add_column :posts, :creator_permissions, :permissions, array: true
41+
42+
Enum::PermissionsSet.new(3) # [:read, :write]
43+
44+
post.creator_permissions.write?
45+
46+
{Learn more}[link:classes/Torque/PostgreSQL/Attributes/EnumSet.html]
47+
48+
* Period complex queries
49+
50+
This provides extended and complex calculations over date and time ranges. In a
51+
few words, you can now store `start_time` and `finish_time` in the same column
52+
and relies on the methods provided here to fo your magic.
53+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/functions-range.html]
54+
55+
add_column :events, :period, :tsrange
56+
add_column :events, :interval, :interval
57+
58+
Event.create(title: 'Test', period: ['2019-01-01 12:00:00', '2019-01-01 14:00:00'], interval: 15.minutes)
59+
60+
Event.overlapping('2019-01-01 13:00:00', '2019-01-01 15:00:00').count
61+
62+
Event.not_real_overlapping('2019-01-01 11:00:00', '2019-01-01 13:00:00').empty?
63+
64+
{Learn more}[link:classes/Torque/PostgreSQL/Attributes/Builder/Period.html]
65+
66+
* Has many array association
67+
68+
The idea is simple, one table stores all the ids and the other one says that
69+
`has many` records on that table because its records ids exist in the column of
70+
the array. Like: `Tag has many Videos connected through an array`.
71+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/arrays.html]
72+
73+
add_column :videos, :tag_ids, :bigint, array: true
74+
75+
Tag.has_many :videos, array: true
76+
77+
Tag.videos.size
78+
79+
Tag.videos << another_video
80+
81+
{Learn more}[link:classes/Torque/PostgreSQL/Reflection/AbstractReflection.html]
82+
83+
* Belongs to many association
84+
85+
The original `belongs_to` associations define a `SingularAssociation`, which
86+
means that it could be extended with `array: true`. In this case, I decided to
87+
create my own `CollectionAssociation` called `belongs_to_many`, which behaves
88+
similar to the single one, but storing and returning a list of records.
89+
90+
With this, now you can say things like `Project belongs to many employees`,
91+
which is more syntactically correct than `Project has many employees`
92+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/arrays.html]
93+
94+
add_column :videos, :tag_ids, :bigint, array: true
95+
96+
Video.belongs_to_many :tags
97+
98+
Video.tags.size
99+
100+
Video.tags << Tag.new(title: 'rails')
101+
102+
{Learn more}[link:classes/Torque/PostgreSQL/Reflection/BelongsToManyReflection.html]
103+
31104
* Distinct On
32105

33106
MySQL-like group by statement on queries. It keeps only the first row of each
34107
set of rows where the given expressions evaluate to equal.
35-
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.5/static/sql-select.html#SQL-DISTINCT]
108+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/static/sql-select.html#SQL-DISTINCT]
36109

37110
User.distinct_on(:name).all
38111

@@ -42,7 +115,7 @@ set of rows where the given expressions evaluate to equal.
42115

43116
Provides a way to write auxiliary statements for use in a larger query. It's
44117
reconfigured on the model, and then can be used during querying process.
45-
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.1/static/queries-with.html]
118+
{PostgreSQL Docs}[https://www.postgresql.org/docs/9.6/static/queries-with.html]
46119

47120
class User < ActiveRecord::Base
48121
auxiliary_statement :last_comment do |cte|

0 commit comments

Comments
 (0)