def print_table(self, fullname): with self.conn as conn: try: schema, tname = fullname.split('.') except ValueError: schema, tname = fullname, None pprint(util.get_table_info(conn, tname, schema))
def test_introspection(): from sqlplain import core, util, _util with core.ScratchDB( 'config://scratch/psycopg2_uri', _util.createbook) as db: assert_equal( util.get_table_info(db.conn, 'book_author'), ['book_author', ['code', 'author_id'], [], {'author_id': 'public.author.id', 'code': 'public.book.code'}]) assert_equal( util.get_schema_info(db.conn), [['author', ['id'], ['firstname', 'lastname'], {}], ['book', ['code'], ['title', 'score'], {'score': 'public.score.value'}], ['book_author', ['code', 'author_id'], [], {'author_id': 'public.author.id', 'code': 'public.book.code'}], ['reading_history', ['code'], ['date'], {'code': 'public.book.code'}], ['score', ['value'], ['evaluation'], {}]])