在我的应用程序中,我有一个定义/概述如下的工作类。此作业类的实例表示特定作业运行。作业可以有多个检查点,每个检查点可以有多个命令。在
Job
- JobName
- [JobCheckpoint]
- StartTime
- EndTime
- Status
- ...
JobCheckpoint
- JobCheckpointName
- [JobCommand]
- StartTime
- EndTime
- Status
- ...
JobCommand
- JobCommandName
- [Command]
- StartTime
- EndTime
- Status
- ...
在任何一天都有大约10万个不同的工作在运行。作业信息保存在文件系统中。我想用Python设计一个用于查询这些作业对象的用户界面。例如,用户应该能够查询
为了解决这个问题,我考虑在用户界面中提供以下方法。在
^{pr2}$我不知道如何用Python设计这个过滤器类
这里的线索真的很感谢。在
这些都是部分主观问题。但我会尽我目前所知和所提问题中的可用信息来回答其中一些问题。在
过滤器类将是什么样子?
这可能取决于存储机制。它是作为一堆Python对象存储在内存中,还是首先从SQL数据库或NoSQL数据库中取出。在
如果它是从SQL数据库获取的,那么可以利用SQL的过滤机制。它毕竟是一种(结构化)查询语言。在
在这种情况下,过滤器类就像一个将字段值转换成一堆SQL运算符/条件的转换器。在
如果是一堆Python对象,而没有用于查询数据的数据库机制,那么您可能需要考虑自己的查询/筛选方法。在
筛选器类可能正在使用条件类和运算符类。也许你有一个操作符类作为一个抽象类,并且有“glue”操作符将条件粘合在一起(and/OR)。以及另一种运算符,用于将域对象的属性与值进行比较。在
对于后者,即使您没有为其设计“过滤语言”,也可以从API查询格式中获得一些灵感,该格式在这里为Flask untillet:https://flask-restless.readthedocs.io/en/stable/searchformat.html#query-format
当然,如果您正在设计一个查询接口,例如restapi,Flask neurgent的查询格式可以给您一些关于如何处理查询的启发。在
返回的域对象列表是正确的还是应该返回dict的列表?
返回域对象列表的优点是可以使用继承。这至少是一个可能的优势。在
某些类别的草图:
相关问题 更多 >
编程相关推荐