lalinsky / python-phoenixdb

Phoenix database adapter for Python (migrated to the Apache Phoenix repo)
https://issues.apache.org/jira/browse/PHOENIX-4636
Apache License 2.0
26 stars 24 forks source link

fetching a dictionary type result with column name #2

Closed yugantar7 closed 7 years ago

yugantar7 commented 7 years ago

The result we were getting were of list format and difficult to map the column names, added a new method docResult to give a dictionary type result. By default it'll be a list like it is now, but if you give doc=True in fetchall(), fetchmany() or fetchone(), it'll return a dictionary type result.

lalinsky commented 7 years ago

Thanks. I have refactored the code a little bit, so use a pattern similar to what it's used in psycopg2 or PyMySQL.

Now you can use this:

db = phoenixdb.connect(..., cursor_factory=phoenixdb.cursor.DictCursor)
cursor = db.cursor()

Or this:

cursor = db.cursor(cursor_factory=phoenixdb.cursor.DictCursor)

In both cases, all the fetch* methods will return dicts instead of lists.