metka 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +61 -1
- data/lib/generators/metka/strategies/view/templates/migration.rb.erb +1 -1
- data/lib/metka/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf64e63f73da3ffb7c87e5d3806a13e4c7d09356e63b8d52ffefd27bf7dda8df
|
4
|
+
data.tar.gz: 98c5808ea5d3426a15b9eb7084b6b07f7c3242ee8f6b96ca53f20cb5f9987208
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24ac1c6bc72b5a98a879897f7cdddd721df052cb84841a0e3adaefff003d9414a0adf1c40cc663a5ed468f5e320a83af09ea76461fb66ce7625cfe7c2f8b376a
|
7
|
+
data.tar.gz: cf3750a9f2dccedd27afac2f967187e6e5655483fc7bd696b0da9d63308bc79279cb90c141db0e25d333dde79ce54235b674f2495f4fe904fccdeb6591419927
|
data/README.md
CHANGED
@@ -57,18 +57,78 @@ There are several strategies to get tag statistics
|
|
57
57
|
|
58
58
|
### View Strategy
|
59
59
|
|
60
|
-
The easiest way to implement but the most slow on SELECT.
|
60
|
+
Data about taggings will be agregated in SQL View. The easiest way to implement but the most slow on SELECT.
|
61
61
|
|
62
62
|
```bash
|
63
63
|
rails g metka:strategies:view --source-table-name=NAME_OF_TABLE_WITH_TAGS
|
64
64
|
```
|
65
65
|
|
66
|
+
The code above will generate a migration that creates view to store aggregated data about tag in `NAME_OF_TABLE_WITH_TAGS` table.
|
67
|
+
|
68
|
+
Lets take a look at real example. We have a `notes` table with `tags` column.
|
69
|
+
|
70
|
+
| Column | Type | Default |
|
71
|
+
|--------|---------------------|-----------------------------------|
|
72
|
+
| id | integer | nextval('notes_id_seq'::regclass) |
|
73
|
+
| body | text | |
|
74
|
+
| tags | character varying[] | '{}'::character varying[] |
|
75
|
+
|
76
|
+
Now lets generate a migration.
|
77
|
+
|
78
|
+
```bash
|
79
|
+
RAILS_ENV=test rails g metka:strategies:view --source-table-name=notes
|
80
|
+
```
|
81
|
+
|
82
|
+
The result would be:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
# frozen_string_literal: true
|
86
|
+
|
87
|
+
class CreateTaggedNotesView < ActiveRecord::Migration[5.0]
|
88
|
+
def up
|
89
|
+
execute <<-SQL
|
90
|
+
CREATE OR REPLACE VIEW tagged_notes AS
|
91
|
+
|
92
|
+
SELECT UNNEST
|
93
|
+
( tags ) AS tag_name,
|
94
|
+
COUNT ( * ) AS taggings_count
|
95
|
+
FROM
|
96
|
+
notes
|
97
|
+
GROUP BY
|
98
|
+
name;
|
99
|
+
SQL
|
100
|
+
end
|
101
|
+
|
102
|
+
def down
|
103
|
+
execute <<-SQL
|
104
|
+
DROP VIEW tagged_notes;
|
105
|
+
SQL
|
106
|
+
end
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
Now lets take a look at `tagged_notes` view.
|
111
|
+
|
112
|
+
| tag_name | taggings_count |
|
113
|
+
|----------|----------------|
|
114
|
+
| Ruby | 124056 |
|
115
|
+
| React | 30632 |
|
116
|
+
| Rails | 28696 |
|
117
|
+
| Crystal | 6566 |
|
118
|
+
| Elixir | 3475 |
|
119
|
+
|
120
|
+
Now you can create `TaggedNote` model and work with the view like you usually do with Rails models.
|
121
|
+
|
66
122
|
### Materialized View Strategy
|
67
123
|
|
124
|
+
Similar to the strategy above, but the view will be Materialized and refreshed with the trigger
|
125
|
+
|
68
126
|
TBD
|
69
127
|
|
70
128
|
### Table Strategy with Triggers
|
71
129
|
|
130
|
+
|
131
|
+
|
72
132
|
TBD
|
73
133
|
|
74
134
|
## Development
|
@@ -6,7 +6,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration<%= ActiveRecord::VE
|
|
6
6
|
CREATE OR REPLACE VIEW <%= view_name %> AS
|
7
7
|
|
8
8
|
SELECT UNNEST
|
9
|
-
( <%= source_column_name %> ) AS
|
9
|
+
( <%= source_column_name %> ) AS <%= source_column_name.singularize %>_name,
|
10
10
|
COUNT ( * ) AS taggings_count
|
11
11
|
FROM
|
12
12
|
<%= source_table_name %>
|
data/lib/metka/version.rb
CHANGED