本文整理匯總了Python中sqlalchemy.engine.result.RowProxy方法的典型用法代碼示例。如果您正苦於以下問題:Python result.RowProxy方法的具體用法?Python result.RowProxy怎麽用?Python result.RowProxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.engine.result
的用法示例。
在下文中一共展示了result.RowProxy方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from sqlalchemy.engine import result [as 別名]
# 或者: from sqlalchemy.engine.result import RowProxy [as 別名]
def __init__(self, x, owner_id=None):
"""Create a Playlist object."""
self.id = None
self.type = PlaylistTypes.User
self.name = None
if not owner_id:
username = config['username']
self.owner_id = MusicDatabase.getUserID(username)
else:
self.owner_id = owner_id
self.playlist_type = DatabaseEnum('playlist_type').id_value('user')
self.songs = []
if isinstance(x, (sqlite3.Row, RowProxy, dict)):
self.id = x['id']
self.name = x['name']
self.owner_id = x['owner_id']
self.load_playlist_songs()
示例2: _show_columns
# 需要導入模塊: from sqlalchemy.engine import result [as 別名]
# 或者: from sqlalchemy.engine.result import RowProxy [as 別名]
def _show_columns(
cls, inspector: Inspector, table_name: str, schema: Optional[str]
) -> List[RowProxy]:
"""
Show presto column names
:param inspector: object that performs database schema inspection
:param table_name: table name
:param schema: schema name
:return: list of column objects
"""
quote = inspector.engine.dialect.identifier_preparer.quote_identifier
full_table = quote(table_name)
if schema:
full_table = "{}.{}".format(quote(schema), full_table)
columns = inspector.bind.execute("SHOW COLUMNS FROM {}".format(full_table))
return columns
示例3: scan
# 需要導入模塊: from sqlalchemy.engine import result [as 別名]
# 或者: from sqlalchemy.engine.result import RowProxy [as 別名]
def scan(cls: Type[T], row: RowProxy) -> T:
"""
Read the data from a row into an object.
Args:
row: The RowProxy object.
Returns:
An object containing the information in the row.
"""
return cls(**dict(zip(cls.column_names, row)))
示例4: scan
# 需要導入模塊: from sqlalchemy.engine import result [as 別名]
# 或者: from sqlalchemy.engine.result import RowProxy [as 別名]
def scan(cls, row: RowProxy) -> 'TelegramFile':
telegram_file = cast(TelegramFile, super().scan(row))
if isinstance(telegram_file.thumbnail, str):
telegram_file.thumbnail = cls.get(telegram_file.thumbnail)
return telegram_file
示例5: verify_presto_column
# 需要導入模塊: from sqlalchemy.engine import result [as 別名]
# 或者: from sqlalchemy.engine.result import RowProxy [as 別名]
def verify_presto_column(self, column, expected_results):
inspector = mock.Mock()
inspector.engine.dialect.identifier_preparer.quote_identifier = mock.Mock()
keymap = {
"Column": (None, None, 0),
"Type": (None, None, 1),
"Null": (None, None, 2),
}
row = RowProxy(mock.Mock(), column, [None, None, None, None], keymap)
inspector.bind.execute = mock.Mock(return_value=[row])
results = PrestoEngineSpec.get_columns(inspector, "", "")
self.assertEqual(len(expected_results), len(results))
for expected_result, result in zip(expected_results, results):
self.assertEqual(expected_result[0], result["name"])
self.assertEqual(expected_result[1], str(result["type"]))
示例6: default
# 需要導入模塊: from sqlalchemy.engine import result [as 別名]
# 或者: from sqlalchemy.engine.result import RowProxy [as 別名]
def default(self, obj):
'''
Converts an object and returns a ``JSON``-friendly structure.
:param obj: object or structure to be converted into a
``JSON``-ifiable structure
Considers the following special cases in order:
* object has a callable __json__() attribute defined
returns the result of the call to __json__()
* date and datetime objects
returns the object cast to str
* Decimal objects
returns the object cast to float
* SQLAlchemy objects
returns a copy of the object.__dict__ with internal SQLAlchemy
parameters removed
* SQLAlchemy ResultProxy objects
Casts the iterable ResultProxy into a list of tuples containing
the entire resultset data, returns the list in a dictionary
along with the resultset "row" count.
.. note:: {'count': 5, 'rows': [('Ed Jones',), ('Pete Jones',),
('Wendy Williams',), ('Mary Contrary',), ('Fred Smith',)]}
* SQLAlchemy RowProxy objects
Casts the RowProxy cursor object into a dictionary, probably
losing its ordered dictionary behavior in the process but
making it JSON-friendly.
* webob_dicts objects
returns webob_dicts.mixed() dictionary, which is guaranteed
to be JSON-friendly.
'''
if hasattr(obj, '__json__') and six.callable(obj.__json__):
return obj.__json__()
elif isinstance(obj, (date, datetime)):
return str(obj)
elif isinstance(obj, Decimal):
# XXX What to do about JSONEncoder crappy handling of Decimals?
# SimpleJSON has better Decimal encoding than the std lib
# but only in recent versions
return float(obj)
elif is_saobject(obj):
props = {}
for key in obj.__dict__:
if not key.startswith('_sa_'):
props[key] = getattr(obj, key)
return props
elif isinstance(obj, ResultProxy):
props = dict(rows=list(obj), count=obj.rowcount)
if props['count'] < 0:
props['count'] = len(props['rows'])
return props
elif isinstance(obj, RowProxy):
return dict(obj)
elif isinstance(obj, webob_dicts):
return obj.mixed()
else:
return JSONEncoder.default(self, obj)