sqlalchemy 核心和 ORM 有什么区别? [英] What is the difference between sqlalchemy core and ORM?

查看:33
本文介绍了sqlalchemy 核心和 ORM 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLAlchemy CoreSQLAlchemy ORM?

推荐答案

顾名思义,ORM 是一个对象关系映射器:它的目的是将数据库关系表示为 Python 对象.

The ORM is, as the name implies, an object-relational mapper: Its purpose is to represent database relations as Python objects.

核心是一个查询构建器.它的目的是提供一种编程方式来生成 SQL 查询(和 DDL)——但这些查询的结果只是元组(有一点额外的魔法),而不是你自己的对象(在这种情况下,你的"是,应用程序开发人员的")设计.

The core is a query builder. Its purpose is to provide a programmatic means to generate SQL queries (and DDL) -- but the results of those queries are just tuples (with a little extra magic), not objects of your own ("your" being, in this case, "the application developer's") design.

一般来说,如果您尝试以编程方式构建查询(特别是基于仅在运行时可用的信息),您应该使用核心.如果您正在尝试构建 MVC 风格的应用程序并希望数据库支持的对象成为模型",那么您应该使用 ORM.

In general, if you're trying to programmatically build queries (particularly based on information only available at runtime), you should be using the core. If you're trying to build your application MVC-style and want database-backed objects to be the "model", you should be using the ORM.

这篇关于sqlalchemy 核心和 ORM 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆