sql_view 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 453bfcdc70b0ca2eba4be95d6eca062e840e9e3f4950f8fca7471421216d1de9
4
- data.tar.gz: 14d65cba7bbcc28dc6741622abef7b91a8863ed8e738b35de373c1758e21f045
3
+ metadata.gz: 025552fef24e528e14b29c5e5fde2f011e329a2aee4169d831d602aae26ca107
4
+ data.tar.gz: f0de63bac86f0a4ad119b972bb9357325c6556ff737c6be245514a4002021915
5
5
  SHA512:
6
- metadata.gz: 99a4e50942b3322d2a86e04b5c5b56e060718788beee10af35ca79de9331bf882d16f0311c9908d97bd8c5d88926e29fd1360fcaf30c90d5d3fd17b77813a238
7
- data.tar.gz: d502bab08d5c44d183f6c741ed2d12c53cd5b27962c9a3eca384c66e213a0d1c5bdbce058184a13fdaf3495fca65f13f7e469a0a2fc59da861f4e8cffc18335d
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
@@ -1,3 +1,3 @@
1
1
  module SqlView
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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 sql
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
- "#{parent.class}"
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.5
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-07 00:00:00.000000000 Z
11
+ date: 2023-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails