Skip to content

Commit 6f15271

Browse files
committed
Combine queries, fetch current_schema alongside views
1 parent 8a2a565 commit 6f15271

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/scenic/adapters/postgres/views.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def views_from_postgres
2828
c.relname as viewname,
2929
pg_get_viewdef(c.oid) AS definition,
3030
c.relkind AS kind,
31-
n.nspname AS namespace
31+
n.nspname AS namespace,
32+
current_schema() AS current_schema
3233
FROM pg_class c
3334
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
3435
WHERE
@@ -41,7 +42,7 @@ def views_from_postgres
4142
end
4243

4344
def to_scenic_view(result)
44-
namespace, viewname = result.values_at "namespace", "viewname"
45+
namespace, viewname, current_schema = result.values_at "namespace", "viewname", "current_schema"
4546

4647
namespaced_viewname = if namespace != current_schema
4748
"#{pg_identifier(namespace)}.#{pg_identifier(viewname)}"
@@ -56,10 +57,6 @@ def to_scenic_view(result)
5657
)
5758
end
5859

59-
def current_schema
60-
@current_schema ||= connection.execute("SELECT CURRENT_SCHEMA()").first["current_schema"]
61-
end
62-
6360
def pg_identifier(name)
6461
return name if /^[a-zA-Z_][a-zA-Z0-9_]*$/.match?(name)
6562

0 commit comments

Comments
 (0)