|
11 | 11 | import decimal |
12 | 12 |
|
13 | 13 | from ..utils import is_uuid, safezip |
14 | | -from ..queries import Expr, Compiler, table, Select, SKIP, Explain, Code |
| 14 | +from ..queries import Expr, Compiler, table, Select, SKIP, Explain, Code, this |
15 | 15 | from ..abcs.database_types import ( |
16 | 16 | AbstractDatabase, |
17 | 17 | AbstractDialect, |
|
30 | 30 | DbPath, |
31 | 31 | Boolean, |
32 | 32 | ) |
| 33 | +from ..abcs.mixins import Compilable |
| 34 | +from ..abcs.mixins import AbstractMixin_Schema |
33 | 35 |
|
34 | 36 | logger = logging.getLogger("database") |
35 | 37 |
|
@@ -101,6 +103,22 @@ def apply_query(callback: Callable[[str], Any], sql_code: Union[str, ThreadLocal |
101 | 103 | return callback(sql_code) |
102 | 104 |
|
103 | 105 |
|
| 106 | +class Mixin_Schema(AbstractMixin_Schema): |
| 107 | + def table_information(self) -> Compilable: |
| 108 | + return table("information_schema", "tables") |
| 109 | + |
| 110 | + def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable: |
| 111 | + return ( |
| 112 | + self.table_information() |
| 113 | + .where( |
| 114 | + this.table_schema == table_schema, |
| 115 | + this.table_name.like(like) if like is not None else SKIP, |
| 116 | + this.table_type == "BASE TABLE", |
| 117 | + ) |
| 118 | + .select(this.table_name) |
| 119 | + ) |
| 120 | + |
| 121 | + |
104 | 122 | class BaseDialect(AbstractDialect): |
105 | 123 | SUPPORTS_PRIMARY_KEY = False |
106 | 124 | TYPE_CLASSES: Dict[str, type] = {} |
@@ -354,7 +372,9 @@ def _refine_coltypes(self, table_path: DbPath, col_dict: Dict[str, ColType], whe |
354 | 372 | return |
355 | 373 |
|
356 | 374 | fields = [Code(self.dialect.normalize_uuid(self.dialect.quote(c), String_UUID())) for c in text_columns] |
357 | | - samples_by_row = self.query(table(*table_path).select(*fields).where(Code(where) if where else SKIP).limit(sample_size), list) |
| 375 | + samples_by_row = self.query( |
| 376 | + table(*table_path).select(*fields).where(Code(where) if where else SKIP).limit(sample_size), list |
| 377 | + ) |
358 | 378 | if not samples_by_row: |
359 | 379 | raise ValueError(f"Table {table_path} is empty.") |
360 | 380 |
|
|
0 commit comments