Python中ORM序列化问题
大家讲道理
大家讲道理 2017-04-17 17:56:32
0
2
264

在Python中有什么方法可以对ORM库查询的数据进行序列化操作,主要针对SQLAlchemy或Peewee这2个框架。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
PHPzhong

If you want to serialize json, you can use marshmallow
With SALAlchemy, it is marshmallow-sqlalchemy

PHPzhong

We use pickle for serialization when using sqlalchemy. When the front end passes it back directly, we can directly obtain the object without having to go to the database to obtain the object again. The code is as follows:


251 
252     def __str__(self):
253         return base64.urlsafe_b64encode(pickle.dumps(self)) .decode('ascii')
254 
255     @staticmethod
256     def fromstr(ss):
257         if isinstance(ss, bytes):
258             ss = ss.encode('ascii')
259         obj = pickle.loads(base64.urlsafe_b64decode(ss))
260         return obj
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template