Created
June 21, 2021 06:49
-
-
Save adriangohjw/00f97a37cb5dcb5df5e25a21132086a4 to your computer and use it in GitHub Desktop.
Rails: Scenic gem for Database Views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserSalary < ApplicationRecord | |
attr_reader :a_but_different_name, | |
:b, | |
:c | |
end | |
class JobListing < ApplicationRecord | |
attr_reader :a, | |
:b_but_different_name, | |
:c | |
end | |
class MyCareersFutureJob < ApplicationRecord | |
attr_reader :a, | |
:b, | |
:c_but_different_name | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Salary < ApplicationRecord | |
attr_reader :a, :b, :c | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Salary | |
attr_reader :a, :b, :c | |
def initialize(data) | |
case data | |
when UserSalary | |
@a = data.a_but_different_name | |
@b = data.b | |
@c = data.c | |
when JobListing | |
@a = data.a | |
@b = data.b_but_different_name | |
@c = data.c | |
when MyCareersFutureJob | |
@a = data.a | |
@b = data.b | |
@c = data.c_but_different_name | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
a_but_different_name AS "a", | |
b, | |
c | |
FROM user_salaries | |
UNION | |
SELECT | |
a, | |
b_but_different_name AS "b", | |
c | |
FROM job_listings | |
UNION | |
SELECT | |
a, | |
b, | |
c_but_different_name AS "c" | |
FROM my_careers_future_jobs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out Behind The Scenes of NodeFlair's Newly Launched Salaries Feature (Part Two)!