Commits

Takeshi Komiya  committed 47ad146

Refactor: Rename inspector classes

  • Participants
  • Parent commits cbe4ed2

Comments (0)

Files changed (5)

File src/schema2rst/inspectors/__init__.py

 #  limitations under the License.
 
 import sqlalchemy
-from schema2rst.inspectors import common, mysql, pgsql
 
 
 def create_engine(config):
 
 def create_for(engine):
     if engine.driver in ('mysqldb', 'pymysql'):
-        return mysql.Inspector(engine)
+        from schema2rst.inspectors.mysql import MySQLInspector
+        return MySQLInspector(engine)
     elif engine.driver in ('psycopg2',):
-        return pgsql.Inspector(engine)
+        from schema2rst.inspectors.pgsql import PgSQLInspector
+        return PgSQLInspector(engine)
     else:
-        return common.Inspector(engine)
+        from schema2rst.inspectors.base import SimpleInspector
+        return SimpleInspector(engine)

File src/schema2rst/inspectors/base.py

+# -*- coding: utf-8 -*-
+#  Copyright 2011 Takeshi KOMIYA
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+from sqlalchemy.engine.reflection import Inspector
+
+
+class SimpleInspector(Inspector):
+    def __init__(self, bind):
+        super(SimpleInspector, self).__init__(bind)
+
+    def get_tables(self, **kw):
+        tables = []
+        table_names = super(SimpleInspector, self).get_table_names(**kw)
+        for table_name in sorted(table_names):
+            table = {'name': table_name, 'fullname': ''}
+            tables.append(table)
+
+        return tables
+
+    def get_columns(self, table_name, **kw):
+        constraints = self.get_pk_constraint(table_name)
+        primary_keys = constraints.get('constrained_columns')
+        columns = super(SimpleInspector, self).get_columns(table_name, **kw)
+        for column in columns:
+            column['fullname'] = column['name']
+            column['comment'] = ''
+
+            if column['name'] in primary_keys:
+                column['primary_key'] = True
+            else:
+                column['primary_key'] = False
+
+        return columns

File src/schema2rst/inspectors/common.py

-# -*- coding: utf-8 -*-
-#  Copyright 2011 Takeshi KOMIYA
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-
-from sqlalchemy.engine import reflection
-
-
-class Inspector(reflection.Inspector):
-    def __init__(self, bind):
-        super(Inspector, self).__init__(bind)
-
-    def get_tables(self, **kw):
-        tables = []
-        table_names = super(Inspector, self).get_table_names(**kw)
-        for table_name in sorted(table_names):
-            table = {'name': table_name, 'fullname': ''}
-            tables.append(table)
-
-        return tables
-
-    def get_columns(self, table_name, **kw):
-        constraints = self.get_pk_constraint(table_name)
-        primary_keys = constraints.get('constrained_columns')
-        columns = super(Inspector, self).get_columns(table_name, **kw)
-        for column in columns:
-            column['fullname'] = column['name']
-            column['comment'] = ''
-
-            if column['name'] in primary_keys:
-                column['primary_key'] = True
-            else:
-                column['primary_key'] = False
-
-        return columns

File src/schema2rst/inspectors/mysql.py

 #  limitations under the License.
 
 import re
-from schema2rst.inspectors import common
+from schema2rst.inspectors.base import SimpleInspector
 
 
-class Inspector(common.Inspector):
+class MySQLInspector(SimpleInspector):
     def get_tables(self, **kw):
-        tables = super(Inspector, self).get_tables(**kw)
+        tables = super(MySQLInspector, self).get_tables(**kw)
         for table in tables:
             query = ("""SELECT TABLE_COMMENT
                         FROM information_schema.Tables
         return [k for k in fk if column_name in k['constrained_columns']]
 
     def get_columns(self, table_name, **kw):
-        columns = super(Inspector, self).get_columns(table_name, **kw)
+        columns = super(MySQLInspector, self).get_columns(table_name, **kw)
         for column in columns:
             query = ("""SELECT COLUMN_TYPE, COLLATION_NAME,
                                EXTRA, COLUMN_COMMENT

File src/schema2rst/inspectors/pgsql.py

 #  limitations under the License.
 
 import re
-from schema2rst.inspectors import common
+from schema2rst.inspectors.base import SimpleInspector
 
 
-class Inspector(common.Inspector):
+class PgSQLInspector(SimpleInspector):
     def get_tables(self):
         query = ("""SELECT c.relname, obj_description(c.oid, 'pg_class')
                     FROM pg_class c
                  self.default_schema_name)
         fullnames = dict(self.bind.execute(query).fetchall())
 
-        tables = super(Inspector, self).get_tables()
+        tables = super(PgSQLInspector, self).get_tables()
         for table in tables:
             table['fullname'] = fullnames.get(table['name'])
 
                  (self.default_schema_name, table_name))
         comments = dict(self.bind.execute(query).fetchall())
 
-        columns = super(Inspector, self).get_columns(table_name, **kw)
+        columns = super(PgSQLInspector, self).get_columns(table_name, **kw)
         for column in columns:
             options = []