Frappe框架中的文档和数据库有什么区别?
我是 Frappe 框架的新手,在 Frappe 文档中,我遇到了两种不同的存储数据的方式:“文档和数据库 API” 我所知道的是它们都被使用以某种方式将数据存储到其中。
我需要知道的是:
- 数据库和文档存储数据有什么区别,或者为什么不使用一种方法来存储数据(例如数据库)?
当我创建一个新的文档类型(例如 TestApp)时,该文档类型将像这样创建:
class TestApp(Document):
pass
如果我们假设该模型具有以下名为 "my_data" 的字段,那么我们可以将此字段打印到像这样的模型:
class TestApp(Document):
def save(self, *args, **kwargs):
print("data is: ", self.my_data)
super(TestApp, self).save(*args, **kwargs)
这将产生第二个问题:
- “文档”如何存储和调用其中的数据(my_data)?
I'm a newbie in the Frappe framework, in the Frappe documentation, I encountered two different ways that can store data which are: "Document and Database API" all I know is that both of them are used to store data into them somehow.
what I need to know is that:
- what is the difference between database and document to store data or why don't use one method to store data (database for example)?
when I create a new doctype (e.g TestApp) that doctype will be created like so:
class TestApp(Document):
pass
and if we assumed that this model has the following field which is called "my_data", so we can print this field into that model like so:
class TestApp(Document):
def save(self, *args, **kwargs):
print("data is: ", self.my_data)
super(TestApp, self).save(*args, **kwargs)
which will create the second question which is:
- how could "Document" store and call the data (my_data) from it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Frappe 提供了混合应用程序数据建模结构,具有开箱即用的 ORM 和查询生成器。
Document
接口(通过frappe.get_doc
)是 ORM。通过这样,每条记录(表中的一行)都是一个文档。本质上,文档是 DocType(文档类型)的一个实例,它充当一种模板。您可以通过此连接到文档的生命周期。至于 DB API 和查询生成器,它们在标准 DBMS 协议上提供了一个薄层。您可以使用它们在文档生命周期之外有效地更新数据。这些本质上是围绕 SQL 的瘦 Python 包装器。
每个DocType的创建都会创建一个新表,每个新字段对应一个新列,每个Document是一行。每个(非自定义)DocType 使用您在控制器中找到的
.json
文件来跟踪其架构。这使得共享应用程序和管理迁移变得容易。frappe.get_doc
调用返回的文档包含 DBMS 中维护的数据及其控制器中定义的方法。您可以查看文档的源代码看看魔法是如何发生的。文档参考:
Frappe provides a hybrid App Data Modelling structure, with an ORM and Query Builder out of the box.
The
Document
interface (viafrappe.get_doc
) is the ORM. Through this, each record (a row in the Table) is a Document. Essentially, a Document is an instance of the DocType (Document Type) which acts as a sort of template. You can hook into a Document's lifecycle through this.As for the DB APIs and the Query Builder(s), they offer a thin layer over standard DBMS protocols. You can use them to efficiently update data outside of the Document lifecycle. These are essentially thin Python wrappers around SQL.
The creation of each DocType makes a new table, each new field corresponds to a new column and each Document is a row. Every (non-custom) DocType tracks it's schema using
.json
files that you'll find with the controller. This makes it easy to share your apps and manage migrations.The document returned by a
frappe.get_doc
call contains the data maintained in the DBMS and the methods defined in it's controller. You can checkout the source code for Document to see how the magic happens.Documentation References: