diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-04 17:24:12 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-04 17:24:12 +0000 |
commit | 385cf6e7b67dc2a51672bc8272da44e0a8cad1b1 (patch) | |
tree | 9a3cdb8ba0dc0bac2afb27e683e7a37dcaca5e47 /lib/sqlalchemy/databases/information_schema.py | |
parent | f9cea034014ba872b31e478c4ac9a6845f7f9e86 (diff) | |
download | sqlalchemy-385cf6e7b67dc2a51672bc8272da44e0a8cad1b1.tar.gz |
added ISchema object to engine/information_schema, provides somewhat generic information_schema access for db's that support it, i.e. postgres, mysql 5
Diffstat (limited to 'lib/sqlalchemy/databases/information_schema.py')
-rw-r--r-- | lib/sqlalchemy/databases/information_schema.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/sqlalchemy/databases/information_schema.py b/lib/sqlalchemy/databases/information_schema.py index dae3af2c6..c0503c25c 100644 --- a/lib/sqlalchemy/databases/information_schema.py +++ b/lib/sqlalchemy/databases/information_schema.py @@ -7,6 +7,20 @@ from sqlalchemy import * from sqlalchemy.ansisql import * generic_engine = ansisql.engine() + +gen_schemata = schema.Table("schemata", generic_engine, + Column("catalog_name", String), + Column("schema_name", String), + Column("schema_owner", String), + schema="information_schema") + +gen_tables = schema.Table("tables", generic_engine, + Column("table_catalog", String), + Column("table_schema", String), + Column("table_name", String), + Column("table_type", String), + schema="information_schema") + gen_columns = schema.Table("columns", generic_engine, Column("table_schema", String), Column("table_name", String), @@ -40,6 +54,25 @@ gen_key_constraints = schema.Table("key_column_usage", generic_engine, Column("constraint_name", String), schema="information_schema") +class ISchema(object): + def __init__(self, engine): + self.engine = engine + self.cache = {} + def __getattr__(self, name): + if name not in self.cache: + # This is a bit of a hack. + # It would probably be better to have a dict + # with just the information_schema tables at + # the module level, so as to avoid returning + # unrelated objects that happen to be named + # 'gen_*' + try: + gen_tbl = globals()['gen_'+name] + except KeyError: + raise AttributeError('information_schema table %s not found' % name) + self.cache[name] = gen_tbl.toengine(self.engine) + return self.cache[name] + def reflecttable(engine, table, ischema_names, use_mysql=False): columns = gen_columns.toengine(engine) |