数据文件的对象文件夹
datastore.objects的Python项目详细描述
#datastore.objects
[datastore.objects](https://github.com/datastore/datastore.objects)是 简单的对象映射器 [数据存储](https://github.com/jbenet/datastore)(非关系)。多亏了 数据存储的多功能性使(序列化和)保持自定义 类到任何类型的数据存储服务。
注意:请先熟悉数据存储。
##安装
pip install datastore.objects
##接口
###键
datastore.objects使用默认的datastore.key 类型和实例片段。
`python >>> from datastore.objects import Key, Model >>> class Scientist(Model): >>> pass >>> Scientist.key Key('/Scientist') >>> Scientist('Tesla').keyKey('/Scientist:Tesla') `
###型号
datastore.objects提供一个继承自的类来定义 模型。datastore.objects.model处理数据存储序列化和 反序列化、属性验证等。
`python >>> from datastore.objects import Model >>> class Scientist(Model): >>> pass `
###属性
datastore.objects使用描述符属性跟踪所需的属性 储存。这在很大程度上取决于其他python orms(django,app engine) 做吧。简而言之,您可以这样定义模型属性:
`python >>> from datastore.objects import Attribute, Model >>> class Scientist(Model): >>> name = Attribute(required=True) >>> field = Attribute(default='Physics') >>> tesla = Scientist('Tesla') >>> tesla.name = 'Nicola Tesla' >>> tesla.field 'Physics' >>> tesla.field = 'Electrical Engineering' >>> tesla.data {'name': 'Nicola Tesla', 'field': 'Electrical Engineering'} `
###对象数据存储
datastore.objects提供一个包装任何其他数据存储的shimdatastore。 因此,可以使用各种数据存储中的任何一种来持久化对象。 objectdatastore确保序列化(放置时)和反序列化(获取时) 正确的数据,并构造类。
`python >>> import datastore >>> from datastore.objects import Attribute, Model, ObjectDatastore >>> >>> class Scientist(Model): >>> name = Attribute(required=True) >>> field = Attribute(default='Physics') >>> >>> tesla = Scientist('Tesla') >>> tesla.name = 'Tesla' >>> tesla.field = 'Electrical Engineering' >>> >>> dds = datastore.DictDatastore() >>> ods = ObjectDatastore(dds, model=Scientist) >>> ods.put(tesla.key, tesla) >>> dds.get(tesla.key) {'name': 'Tesla', 'field': 'Electrical Engineering'} >>> ods.get(tesla.key) <Model /Scientist:Tesla> `
##关于
####作者
datastore.objects由[juan batiz benet](https://github.com/jbenet)编写, 属于[雅典娜](http://athena.ai)。
####许可证
它是免费的开源软件,在 麻省理工学院的执照。
####联系人
项目网页:https://github.com/datastore/datastore.objects。 问题:https://github.com/jbenet/object-datastore/issues