本文整理汇总了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)