Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions datajoint/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ 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 and ~job
:return: A list of table names in their raw datajoint naming convection form
"""

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):
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -105,6 +106,11 @@ 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)
Expand Down