Skip to content

Commit

Permalink
preparation for a release
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkasyanchuk committed Feb 15, 2022
1 parent ed9711a commit 63cd64a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Binary file added docs/sql_view.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions test/dummy/app/sql_views/active_user_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ActiveUserView < SQLView::Model
materialized

schema -> { User.where(age: 18..60) }

extend_model_with do
# sample how you can extend it, similar to regular AR model
#
# include SomeConcern
#
# belongs_to :user
# has_many :posts
#
# scope :ordered, -> { order(:created_at) }
# scope :by_role, ->(role) { where(role: role) }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateActiveUserView < ActiveRecord::Migration[7.0]
def up
ActiveUserView.sql_view.up
end

def down
ActiveUserView.sql_view.down
end
end
14 changes: 13 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_02_14_211243) do
ActiveRecord::Schema.define(version: 2022_02_15_124409) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -101,4 +101,16 @@
FROM workers;
SQL

create_sql_view "active_user_views", sql: <<-SQL
CREATE MATERIALIZED VIEW "active_user_views" AS
SELECT users.id,
users.name,
users.country,
users.age,
users.created_at,
users.updated_at
FROM users
WHERE ((users.age >= 18) AND (users.age <= 60));
SQL

end

0 comments on commit 63cd64a

Please sign in to comment.