Beispiel #1
0
 def get_friends(cls, user_id):
     """返回好友列表"""
     db_conf, tb_shard = models.get_db_table(user_id)
     cnn = Connection(*db_conf)
     try:
         tb_name = '%s_%d' % (cls.__tablename__, tb_shard,)
         sql = 'SELECT `id`, `user_id`, `friend_id`, `created_at` FROM `%s` WHERE `user_id`=%%s' % (tb_name,)
         iter = cnn.iter(sql, user_id)
         return [cls(**row) for row in iter]
     finally:
         cnn.close()