sql_view 0.0.5 → 0.0.6
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 +12 -0
- data/lib/sql_view/version.rb +1 -1
- data/lib/sql_view.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 025552fef24e528e14b29c5e5fde2f011e329a2aee4169d831d602aae26ca107
|
4
|
+
data.tar.gz: f0de63bac86f0a4ad119b972bb9357325c6556ff737c6be245514a4002021915
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4213c7dc5a9c882664f9214cec6e148313221d0a799484517b3db45a288d9516094c70738c89030010ffa9a607a561e8339be9099741df291c9540bd13067247
|
7
|
+
data.tar.gz: e7177d5289085a4be25f4ff9d4bdecdab2104c1816281a7abeecdee5418be1b6aa2e18a05e0087f140370335b7fd146bf50d5017e2dcaa3c84722c3fc1ac1e46
|
data/README.md
CHANGED
@@ -78,6 +78,18 @@ ActiveUserView.model.includes(:profile)
|
|
78
78
|
|
79
79
|
If you need to refresh materialized view - `ActiveUserView.sql_view.refresh` (if you need to do it concerrently - `.refresh(concurrently: false)`.
|
80
80
|
|
81
|
+
It can also be used with your other models:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class Account < ApplicationRecord
|
85
|
+
has_many :users
|
86
|
+
|
87
|
+
has_one :account_stat_view, class_name: AccountStatViewView.model.to_s, foreign_key: :account_id
|
88
|
+
has_many :active_users, join_table: :active_users_views, class_name: ActiveUserView.model.to_s, foreign_key: :account_id
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
|
81
93
|
More examples in this file: `./test/sql_view_test.rb`
|
82
94
|
|
83
95
|
## Installation
|
data/lib/sql_view/version.rb
CHANGED
data/lib/sql_view.rb
CHANGED
@@ -68,7 +68,7 @@ module SqlView
|
|
68
68
|
sql = <<-SQL
|
69
69
|
REFRESH#{materialized_or_not}VIEW#{concurrently_or_not}#{parent.view_name};
|
70
70
|
SQL
|
71
|
-
execute(sql)
|
71
|
+
execute(sql, log: false)
|
72
72
|
end
|
73
73
|
|
74
74
|
def up
|
@@ -88,8 +88,8 @@ module SqlView
|
|
88
88
|
execute(sql)
|
89
89
|
end
|
90
90
|
|
91
|
-
def execute(sql)
|
92
|
-
SqlView.log
|
91
|
+
def execute(sql, log: true)
|
92
|
+
SqlView.log(sql) if log
|
93
93
|
ActiveRecord::Base.connection.execute sql#.wp
|
94
94
|
end
|
95
95
|
|
@@ -103,6 +103,7 @@ module SqlView
|
|
103
103
|
|
104
104
|
class ClassBuilder
|
105
105
|
def ClassBuilder.create_model(parent)
|
106
|
+
class_name = "#{parent}Model"
|
106
107
|
klass = Class.new(ActiveRecord::Base) do
|
107
108
|
def self.model_name
|
108
109
|
ActiveModel::Name.new(self, nil, parent.view_name)
|
@@ -120,10 +121,11 @@ module SqlView
|
|
120
121
|
# because of the error undefined scan for nil class
|
121
122
|
klass.class_eval %Q{
|
122
123
|
def self.name
|
123
|
-
"#{
|
124
|
+
"#{class_name}"
|
124
125
|
end
|
125
126
|
}
|
126
|
-
klass
|
127
|
+
Object.const_set(class_name, klass) unless const_defined?(class_name)
|
128
|
+
Object.const_get(class_name)
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|