-
-
Save anonymous/847d0fdc118553c46730 to your computer and use it in GitHub Desktop.
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
diff --git a/lib/Mojo/Pg/Database.pm b/lib/Mojo/Pg/Database.pm | |
index 3f0f484..fe63cb3 100644 | |
--- a/lib/Mojo/Pg/Database.pm | |
+++ b/lib/Mojo/Pg/Database.pm | |
@@ -89,10 +89,8 @@ sub query { | |
} | |
sub tables { | |
- shift->query( | |
- "select schemaname || '.' || tablename from pg_catalog.pg_tables | |
- where schemaname not in ('pg_catalog', 'information_schema')" | |
- )->arrays->map(sub { $_->[0] })->to_array; | |
+ [grep { $_ !~ /^(?:pg_catalog|information_schema)\./ } | |
+ shift->dbh->tables('', '', '', '', {})]; | |
} | |
sub unlisten { | |
@@ -303,8 +301,8 @@ also append a callback to perform operation non-blocking. | |
my $tables = $db->tables; | |
-Return table names (that are not internal) for this database as an array | |
-reference. | |
+Return table and view names for this database, that are visible to the current | |
+user and not internal, as an array reference. | |
# Names of all tables | |
say for @{$db->tables}; | |
diff --git a/t/migrations.t b/t/migrations.t | |
index 3a03fd8..3a12f43 100644 | |
--- a/t/migrations.t | |
+++ b/t/migrations.t | |
@@ -69,6 +69,10 @@ EOF | |
is $pg->migrations->latest, 10, 'latest version is 10'; | |
is $pg->migrations->active, 0, 'active version is 0'; | |
is $pg->migrations->migrate->active, 10, 'active version is 10'; | |
+ok !!(grep {/^mojo_migrations_test\.migration_test_one$/} @{$pg->db->tables}), | |
+ 'first table exists'; | |
+ok !!(grep {/^mojo_migrations_test\.migration_test_two$/} @{$pg->db->tables}), | |
+ 'second table exists'; | |
is_deeply $pg->db->query('select * from migration_test_one')->hash, | |
{foo => 'works ♥'}, 'right structure'; | |
is $pg->migrations->migrate->active, 10, 'active version is 10'; | |
diff --git a/t/results.t b/t/results.t | |
index c932b04..eae3a2f 100644 | |
--- a/t/results.t | |
+++ b/t/results.t | |
@@ -28,6 +28,8 @@ ok !!(grep {/^mojo_results_test\.results.test$/} @{$db->tables}), | |
'results table exists'; | |
ok !(grep {/^information_schema\.tables$/} @{$db->tables}), | |
'internal tables are hidden'; | |
+ok !(grep {/^pg_catalog\.pg_tables$/} @{$db->tables}), | |
+ 'internal tables are hidden'; | |
# Result methods | |
is_deeply $db->query('select * from results_test')->rows, 2, 'two rows'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment