From b3e7570aefed191953aa9f84c14744aa67b970ca Mon Sep 17 00:00:00 2001 From: synicix Date: Tue, 8 Dec 2020 19:29:37 -0600 Subject: [PATCH 1/6] Added basic list_tables function for schema class --- datajoint/schemas.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/datajoint/schemas.py b/datajoint/schemas.py index a708db3ce..fa67a53cf 100644 --- a/datajoint/schemas.py +++ b/datajoint/schemas.py @@ -288,6 +288,15 @@ def repl(s): with open(python_filename, 'wt') as f: f.write(python_code) + def list_tables(self): + """ + Return a list of all tables in the schema except tables with ~ in first character such as ~logs + :return: A list of table names in their raw datajoint naming convection form + """ + + query_result = self.connection.query('SELECT table_name FROM information_schema.tables WHERE table_schema = \'' + self.database + '\'').fetchall() + return [table_name_tuple[0] for table_name_tuple in query_result if '~' != table_name_tuple[0][0]] + class VirtualModule(types.ModuleType): """ From 32b2874bc50485a671fb88dfdc78ba7d6ae7a2f6 Mon Sep 17 00:00:00 2001 From: synicix Date: Wed, 9 Dec 2020 17:11:51 -0600 Subject: [PATCH 2/6] Update list_tables to more efficient solution --- datajoint/schemas.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/datajoint/schemas.py b/datajoint/schemas.py index fa67a53cf..27b768ed2 100644 --- a/datajoint/schemas.py +++ b/datajoint/schemas.py @@ -294,8 +294,9 @@ def list_tables(self): :return: A list of table names in their raw datajoint naming convection form """ - query_result = self.connection.query('SELECT table_name FROM information_schema.tables WHERE table_schema = \'' + self.database + '\'').fetchall() - return [table_name_tuple[0] for table_name_tuple in query_result if '~' != table_name_tuple[0][0]] + return [table_name for (table_name,) in self.connection.query(""" + SELECT table_name FROM information_schema.tables + WHERE table_schema = %s and table_name NOT LIKE '~%%'""", args=(self.database))] class VirtualModule(types.ModuleType): From 804ba11dc1d8f2790d626911bc2c99bcfb16d37b Mon Sep 17 00:00:00 2001 From: synicix Date: Wed, 9 Dec 2020 17:14:05 -0600 Subject: [PATCH 3/6] Update comments to fit in 95 characters convention --- datajoint/schemas.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datajoint/schemas.py b/datajoint/schemas.py index 27b768ed2..5b03e2033 100644 --- a/datajoint/schemas.py +++ b/datajoint/schemas.py @@ -290,7 +290,8 @@ def repl(s): def list_tables(self): """ - Return a list of all tables in the schema except tables with ~ in first character such as ~logs + Return a list of all tables in the schema except tables with ~ in first character such + as ~logs and ~job :return: A list of table names in their raw datajoint naming convection form """ From 828807319fe350cb0b5378f68ad36c55685440e8 Mon Sep 17 00:00:00 2001 From: synicix Date: Wed, 9 Dec 2020 18:12:14 -0600 Subject: [PATCH 4/6] Added test for schema.list_tables --- tests/test_schema.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_schema.py b/tests/test_schema.py index 98ec3e7f5..c180e922d 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -4,6 +4,7 @@ from . import schema from . import schema_empty from . import PREFIX, CONN_INFO +from .schema_simple import schema as schema_simple def relation_selector(attr): @@ -105,6 +106,9 @@ class Unit(dj.Part): test_schema.drop() +def test_list_tables(): + assert(['#a', '#argmax_test', '#data_a', '#data_b', '#i_j', '#j_i', '#l', '#t_test_update', '__b', '__b__c', '__d', '__e', '__e__f', 'f', 'reserved_word'] == schema_simple.list_tables()) + def test_schema_save(): assert_true("class Experiment(dj.Imported)" in schema.schema.code) From 82d23a7465d109abde77b34449a2210f1b9d3890 Mon Sep 17 00:00:00 2001 From: synicix Date: Thu, 10 Dec 2020 16:21:27 -0600 Subject: [PATCH 5/6] Format line to fit is 95 char requirements... --- tests/test_schema.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_schema.py b/tests/test_schema.py index c180e922d..2d868b60d 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -107,7 +107,9 @@ class Unit(dj.Part): test_schema.drop() def test_list_tables(): - assert(['#a', '#argmax_test', '#data_a', '#data_b', '#i_j', '#j_i', '#l', '#t_test_update', '__b', '__b__c', '__d', '__e', '__e__f', 'f', 'reserved_word'] == schema_simple.list_tables()) + assert(['#a', '#argmax_test', '#data_a', '#data_b', '#i_j', '#j_i', '#l',\ + '#t_test_update', '__b', '__b__c', '__d', '__e', '__e__f', 'f',\ + 'reserved_word'] == schema_simple.list_tables()) def test_schema_save(): From 9021ff9831a5bac11999ee19fc27752044cc656a Mon Sep 17 00:00:00 2001 From: synicix Date: Thu, 10 Dec 2020 16:27:33 -0600 Subject: [PATCH 6/6] Remove white space --- datajoint/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datajoint/schemas.py b/datajoint/schemas.py index 5b03e2033..6dc3777ed 100644 --- a/datajoint/schemas.py +++ b/datajoint/schemas.py @@ -298,7 +298,7 @@ def list_tables(self): return [table_name for (table_name,) in self.connection.query(""" SELECT table_name FROM information_schema.tables WHERE table_schema = %s and table_name NOT LIKE '~%%'""", args=(self.database))] - + class VirtualModule(types.ModuleType): """