def search(self, object_id=None, object_name=None, object_subname=None, **kwargs):
andList = [ md.InventoryObjects.c.class_id == self._classId ]
if not object_id is None:
andList.append(md.InventoryObjects.c.object_id == object_id)
if not object_name is None:
andList.append(md.InventoryObjects.c.object_name.like(object_name))
if not object_subname is None:
andList.append(md.InventoryObjects.c.object_subname.like(object_subname))
# append attributes subqueries
for k in kwargs:
if k in self._attributes:
andList.append(md.InventoryObjects.c.object_id.in_(
ex.select([md.InventoryObjectAttributes.c.object_id]).select_from(md.InventoryObjectAttributes).where(and_(
md.InventoryObjectAttributes.c.class_id == self._classId,
md.InventoryObjectAttributes.c.attr_key == k,
md.InventoryObjectAttributes.c.attr_value.like(kwargs[k])
))
))
data = []
for row in self._connection.execute(md.InventoryObjects.select().where(and_(*andList))):
data.append({
"object_id": row["object_id"],
self._objectName : row["object_name"],
self._objectSubName : row["object_subname"]
})
return data
评论列表
文章目录