Frappe框架中的文档和数据库有什么区别?

发布于 2025-01-12 11:26:31 字数 639 浏览 3 评论 0原文

我是 Frappe 框架的新手,在 Frappe 文档中,我遇到了两种不同的存储数据的方式:“文档和数据库 API” 我所知道的是它们都被使用以某种方式将数据存储到其中。

我需要知道的是:

  1. 数据库和文档存储数据有什么区别,或者为什么不使用一种方法来存储数据(例如数据库)?

当我创建一个新的文档类型(例如 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)

这将产生第二个问题:

  1. 文档”如何存储和调用其中的数据(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:

  1. 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:

  1. how could "Document" store and call the data (my_data) from it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2025-01-19 11:26:31

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 (via frappe.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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文