-
Notifications
You must be signed in to change notification settings - Fork 4
/
intro.html
3 lines (3 loc) · 17.4 KB
/
intro.html
1
2
3
<h1><span class="yiyi-st" id="yiyi-46">概述<a class="headerlink" href="#overview" title="Permalink to this headline">¶ T0></a></span></h1><p><span class="yiyi-st" id="yiyi-47">SQLAlchemy的SQL工具包和ORM是一套python数据库操作的综合工具包。</span><span class="yiyi-st" id="yiyi-48">它有多个不同领域的功能,可以单独使用或组合使用。</span><span class="yiyi-st" id="yiyi-49">其主要组件如下图所示,包含组件层次上的依赖关系。</span></p><img alt="http://sqlalchemy.readthedocs.io/en/latest/_images/sqla_arch_small.png" src="http://sqlalchemy.readthedocs.io/en/latest/_images/sqla_arch_small.png"><p><span class="yiyi-st" id="yiyi-50">如上图所示,SQLAlchemy 最重要的两个部分是 <strong>ORM</strong> 和 <strong>SQL 表达式语言</strong>。</span><span class="yiyi-st" id="yiyi-51">SQL表达式可以独立于ORM使用。</span><span class="yiyi-st" id="yiyi-52">使用 ORM 时,SQL 表达式语言仍然是公开 API 的一部分,因为它在对象关系配置和查询中使用。</span></p><div class="section" id="documentation-overview"><h2><span class="yiyi-st" id="yiyi-53">文档概述<a class="headerlink" href="#documentation-overview" title="Permalink to this headline">¶</a></span></h2><p><span class="yiyi-st" id="yiyi-54">文档分为三个部分: <a class="reference internal" href="orm_index.html"><span>SQLAlchemy ORM</span></a>、<a class="reference internal" href="core_index.html"><span>SQLAlchemy 核心</span></a>和 <a class="reference internal" href="dialects_index.html"><span>方言(Dialects)</span></a>.</span></p><p><span class="yiyi-st" id="yiyi-55">在 <a class="reference internal" href="orm_index.html"><span>SQLAlchemy ORM</span></a>中, 对象关系映射被充分引入和描述。</span><span class="yiyi-st" id="yiyi-56">新用户可以从<a class="reference internal" href="orm_tutorial.html"><span>对象关系教程</span></a>开始。</span><span class="yiyi-st" id="yiyi-57">如果你想要了解自动构建高级SQL以及管理Python对象,推荐阅读此教程。</span></p><p><span class="yiyi-st" id="yiyi-58">在 <a class="reference internal" href="core_index.html"><span>SQLAlchemy Core</span></a> 中,主要介绍了SQLAlchemy 的 SQL、数据库集成和描述服务, 这部分的核心是 SQL 表达语言。</span><span class="yiyi-st" id="yiyi-59">SQL 表达式是独立于 ORM 包的一套自成一体的工具集, 它可以用来创建易于使用的 SQ 表达式,该 SQL 表达式可通过编程创建、修改和执行,返回游标结果集。</span><span class="yiyi-st" id="yiyi-60">对比 ORM 使用域为中心的方式,表达语言提供模式为中心的架构。</span><span class="yiyi-st" id="yiyi-61">新用户请从 <a class="reference internal" href="core_tutorial.html"><span>SQL 表达式教程</span></a>开始。</span><span class="yiyi-st" id="yiyi-62">SQLAlchemy 引擎,链接和池服务同样在<a class="reference internal" href="core_index.html"><span>SQLAlchemy Core</span></a>中有描述。</span></p><p><span class="yiyi-st" id="yiyi-63"><a class="reference internal" href="dialects_index.html"><span>Dialects</span></a>介绍了所有 SQLAlchemy 支持的数据库和 DBAPI 后端。</span></p></div><div class="section" id="code-examples"><h2><span class="yiyi-st" id="yiyi-64">代码示例<a class="headerlink" href="#code-examples" title="Permalink to this headline">¶</a></span></h2><p><span class="yiyi-st" id="yiyi-65">主要关于ORM的工作代码示例包含在SQLAlchemy发行版中.</span><span class="yiyi-st" id="yiyi-66">所有包含的示例应用程序的描述在<a class="reference internal" href="orm_examples.html"><span>ORM Examples</span></a>.中。</span></p><p><span class="yiyi-st" id="yiyi-67">还有各种各样的示例涉及核心SQLAlchemy构造以及维基上的ORM, </span><span class="yiyi-st" id="yiyi-68">参见<a class="reference external" href="http://www.sqlalchemy.org/trac/wiki/UsageRecipes">Theatrum Chemicum</a>。</span></p></div><div class="section" id="installation-guide"><h2><span class="yiyi-st" id="yiyi-69">安装指南<a class="headerlink" href="#installation-guide" title="Permalink to this headline">¶</a></span></h2><div class="section" id="supported-platforms"><h3><span class="yiyi-st" id="yiyi-70">支持的平台<a class="headerlink" href="#supported-platforms" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-71">SQLAlchemy已经针对以下平台进行了测试:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-72">cPython自2.6版开始,通过2.xx系列</span></li><li><span class="yiyi-st" id="yiyi-73">cPython版本3,贯穿所有3.xx系列</span></li><li><span class="yiyi-st" id="yiyi-74"><a class="reference external" href="http://pypy.org/">Pypy</a> 2.1 or greater</span></li></ul><div class="versionchanged"><p><span class="yiyi-st" id="yiyi-75"><span class="versionmodified">在0.9版本中更改:</span> Python 2.6现在是支持的最小Python版本。</span></p></div><p><span class="yiyi-st" id="yiyi-76">目前不支持的平台包括Jython,IronPython。</span><span class="yiyi-st" id="yiyi-77">曾经已经支持 Jython,并且可能会在将来的版本中支持,这取决于Jython本身的状态。</span></p></div><div class="section" id="supported-installation-methods"><h3><span class="yiyi-st" id="yiyi-78">支持的安装方法<a class="headerlink" href="#supported-installation-methods" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-79">SQLAlchemy安装是通过基于<a class="reference external" href="http://pypi.python.org/pypi/setuptools/">setuptools</a>的标准Python方法,通过直接引用<code class="docutils literal"><span class="pre">setup.py</span></code>或通过使用<a class="reference external" href="http://pypi.python.org/pypi/pip/">pip</a>或其他setuptools,兼容的方法。</span></p><div class="versionchanged"><p><span class="yiyi-st" id="yiyi-80"><span class="versionmodified">在版本1.1中更改:</span> setup.py文件现在需要setuptools;不再支持简单的distutils安装。</span></p></div></div><div class="section" id="install-via-pip"><h3><span class="yiyi-st" id="yiyi-81">通过pip安装<a class="headerlink" href="#install-via-pip" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-82">当<code class="docutils literal"><span class="pre">pip</span></code>可用时,可以从Pypi下载并在一个步骤中安装该分发:</span></p><div class="highlight-python"><div class="highlight"><pre><span></span>pip install SQLAlchemy</pre></div></div><p><span class="yiyi-st" id="yiyi-83">该命令将从<a class="reference external" href="http://pypi.python.org/pypi/SQLAlchemy">Python Cheese Shop</a>下载最新的<strong>发布的</strong>版SQLAlchemy并将其安装到您的系统中。</span></p><p><span class="yiyi-st" id="yiyi-84">为了安装最新的<strong>prerelease</strong>版本,比如<code class="docutils literal"><span class="pre">1.1.0b1</span></code>,pip要求使用<code class="docutils literal"><span class="pre">--pre</span></code>标志:</span></p><div class="highlight-python"><div class="highlight"><pre><span></span>pip install --pre SQLAlchemy</pre></div></div><p><span class="yiyi-st" id="yiyi-85">如上所述,如果最新版本是预发行版本,则将安装它而不是最新发布的版本。</span></p></div><div class="section" id="installing-using-setup-py"><h3><span class="yiyi-st" id="yiyi-86">使用setup.py <a class="headerlink" href="#installing-using-setup-py" title="Permalink to this headline">¶</a>进行安装</span></h3><p><span class="yiyi-st" id="yiyi-87">否则,您可以使用<code class="docutils literal"><span class="pre">setup.py</span></code>脚本从分发安装:</span></p><div class="highlight-python"><div class="highlight"><pre><span></span>python setup.py install</pre></div></div></div><div class="section" id="installing-the-c-extensions"><h3><span class="yiyi-st" id="yiyi-88">安装C扩展<a class="headerlink" href="#installing-the-c-extensions" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-89">SQLAlchemy包含C扩展,它提供了额外的速度提升来处理结果集。</span><span class="yiyi-st" id="yiyi-90">这些扩展在cPython的2.xx和3.xx系列上均受支持。</span></p><p><span class="yiyi-st" id="yiyi-91"><code class="docutils literal"><span class="pre">setup.py</span></code> will automatically build the extensions if an appropriate platform is detected. </span><span class="yiyi-st" id="yiyi-92">如果C扩展的构建失败,由于缺少编译器或其他问题,安装过程将输出警告消息,并在完成报告最终状态时重新运行没有C扩展的构建。</span></p><p><span class="yiyi-st" id="yiyi-93">要运行构建/安装而不尝试编译C扩展,可以指定<code class="docutils literal"><span class="pre">DISABLE_SQLALCHEMY_CEXT</span></code>环境变量。</span><span class="yiyi-st" id="yiyi-94">对于这种情况的用例要么是针对特殊的测试环境,要么是通常的“重建”机制无法解决的罕见情况下的兼容性/构建问题:</span></p><div class="highlight-python"><div class="highlight"><pre><span></span>export DISABLE_SQLALCHEMY_CEXT=1; python setup.py install</pre></div></div><div class="versionchanged"><p><span class="yiyi-st" id="yiyi-95">在版本1.1中更改:遗留的--without-cextensions标志已从安装程序中删除,因为它依赖于setuptools的不推荐使用的功能。<span class="versionmodified"></span><code class="docutils literal"><span class="pre"></span></code></span></p></div></div><div class="section" id="installing-on-python-3"><h3><span class="yiyi-st" id="yiyi-96">在Python 3上安装<a class="headerlink" href="#installing-on-python-3" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-97">SQLAlchemy直接在Python 2或Python 3上运行,并且可以在任何环境中安装,无需任何调整或代码转换。</span></p></div><div class="section" id="installing-a-database-api"><h3><span class="yiyi-st" id="yiyi-98">安装数据库API <a class="headerlink" href="#installing-a-database-api" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-99">SQLAlchemy旨在与针对特定数据库构建的<a class="reference internal" href="glossary.html#term-dbapi"><span class="xref std std-term">DBAPI</span></a>实现一起运行,并包含对最流行数据库的支持。</span><span class="yiyi-st" id="yiyi-100">The individual database sections in <a class="reference internal" href="dialects_index.html"><em>Dialects</em></a> enumerate the available DBAPIs for each database, including external links.</span></p></div><div class="section" id="checking-the-installed-sqlalchemy-version"><h3><span class="yiyi-st" id="yiyi-101">检查安装的SQLAlchemy版本<a class="headerlink" href="#checking-the-installed-sqlalchemy-version" title="Permalink to this headline">¶</a></span></h3><p><span class="yiyi-st" id="yiyi-102">本文档涵盖了SQLAlchemy版本1.1。</span><span class="yiyi-st" id="yiyi-103">如果您正在使用已安装SQLAlchemy的系统,请从您的Python提示符中检查版本,如下所示:</span></p><div class="highlight-python+sql"><div class="highlight"><pre><span></span><span class="o">>>></span> <span class="kn">import</span> <span class="nn">sqlalchemy</span>
<span class="o">>>></span> <span class="n">sqlalchemy</span><span class="o">.</span><span class="n">__version__</span> <span class="c1"># doctest: +SKIP</span>
<span class="mf">1.1</span><span class="o">.</span><span class="mi">0</span></pre></div></div></div></div><div class="section" id="to-1-1-migration"><h2><span class="yiyi-st" id="yiyi-104">1.0到1.1迁移<a class="headerlink" href="#to-1-1-migration" title="Permalink to this headline">¶</a></span></h2><p><span class="yiyi-st" id="yiyi-105">Notes on what’s changed from 1.0 to 1.1 is available here at <a class="reference internal" href="changelog_migration_11.html"><em>What’s New in SQLAlchemy 1.1?</em></a>.</span></p></div>