# sql/schema.py
# Copyright (C) 2005-2015 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""The schema module provides the building blocks for database metadata.
Each element within this module describes a database entity which can be
created and dropped, or is otherwise part of such an entity. Examples include
tables, columns, sequences, and indexes.
All entities are subclasses of :class:`~sqlalchemy.schema.SchemaItem`, and as
defined in this module they are intended to be agnostic of any vendor-specific
constructs.
A collection of entities are grouped into a unit called
:class:`~sqlalchemy.schema.MetaData`. MetaData serves as a logical grouping of
schema elements, and can also be associated with an actual database connection
such that operations involving the contained elements can contact the database
as needed.
Two of the elements here also build upon their "syntactic" counterparts, which
are defined in :class:`~sqlalchemy.sql.expression.`, specifically
:class:`~sqlalchemy.schema.Table` and :class:`~sqlalchemy.schema.Column`.
Since these objects are part of the SQL expression language, they are usable
as components in SQL expressions.
"""
from __future__ import absolute_import
import inspect
from .. import exc, util, event, inspection
from .base import SchemaEventTarget, DialectKWArgs
from . import visitors
from . import type_api
from .base import _bind_or_error, ColumnCollection
from .elements import ClauseElement, ColumnClause, _truncated_label, \
_as_truncated, TextClause, _literal_as_text,\
ColumnElement, _find_columns, quoted_name
from .selectable import TableClause
import collections
import sqlalchemy
from . import ddl
import types
RETAIN_SCHEMA = util.symbol('retain_schema')
def _get_table_key(name, schema):
if schema is None:
return name
else:
return schema + "." + name
@inspection._self_inspects
class SchemaItem(SchemaEventTarget, visitors.Visitable):
"""Base class for items that define a database schema."""
__visit_name__ = 'schema_item'
def _execute_on_connection(self, connection, multiparams, params):
return connection._execute_default(self, multiparams, params)
def _init_items(self, *args):
"""Initialize the list of child items for this SchemaItem."""
for item in args:
if item is not None:
item._set_parent_with_dispatch(self)
def get_children(self, **kwargs):
"""used to allow SchemaVisitor access"""
return []
def __repr__(self):
return util.generic_repr(self, omit_kwarg=['info'])
@property
@util.deprecated('0.9', 'Use ``<obj>.name.quote``')
def quote(self):
"""Return the value of the ``quote`` flag passed
to this schema object, for those schema items which
have a ``name`` field.
"""
return self.name.quote
@util.memoized_property
def info(self):
"""Info dictionary associated with the object, allowing user-defined
data to be associated with this :class:`.SchemaItem`.
The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as :class:`.Table` and :class:`.Column`.
"""
return {}
def _schema_item_copy(self, schema_item):
if 'info' in self.__dict__:
schema_item.info = self.info.copy()
schema_item.dispatch._update(self.dispatch)
return schema_item
class Table(DialectKWArgs, SchemaItem, TableClause):
"""Represent a table in a database.
e.g.::
mytable = Table("mytable", metadata,
Column('mytable_id', Integer, primary_key=True),
Column('value', String(50))
)
The :class:`.Table` object constructs a unique instance of itself based
on its name and optional schema name within the given
:class:`.MetaData` object. Calling the :class:`.Table`
constructor with the same name and same :class:`.MetaData` argument
a second time will return the *same* :class:`.Table` object - in this way
the :class:`.Table` constructor acts as a registry function.
.. seealso::
:ref:`metadata_describing` - Introduction to database metadata
Constructor arguments are as follows:
:param name: The name of this table as represented in the database.
The table name, along with the value of the ``schema`` parameter,
forms a key which uniquely identifies this :class:`.Table` within
the owning :class:`.MetaData` collection.
Additional calls to :class:`.Table` with the same name, metadata,
and schema name will return the same :class:`.Table` object.
Names which contain no upper case characters
will be treated as case insensitive names, and will not be quoted
unless they are a reserved word or contain special characters.
A name with any number of upper case characters is considered
to be case sensitive, and will be sent as quoted.
To enable unconditional quoting for the table name, specify the flag
``quote=True`` to the constructor, or use the :class:`.quoted_name`
construct to specify the name.
:param metadata: a :class:`.MetaData` object which will contain this
table. The metadata is used as a point of association of this table
with other tables which are referenced via foreign key. It also
may be used to associate this table with a particular
:class:`.Connectable`.
:param \*args: Additional positional arguments are used primarily
to add the list of :class:`.Column` objects contained within this
table. Similar to the style of a CREATE TABLE statement, other
:class:`.SchemaItem` constructs may be added here, including
:class:`.PrimaryKeyConstraint`, and :class:`.ForeignKeyConstraint`.
:param autoload: Defaults to False, unless :paramref:`.Table.autoload_with`
is set in which case it defaults to True; :class:`.Column` objects
for this table should be reflected from the database, possibly
augmenting or replacing existing :class:`.Column` objects that were
expicitly specified.
.. versionchanged:: 1.0.0 setting the :paramref:`.Table.autoload_with`
parameter implies that :paramref:`.Table.autoload` will default
to True.
.. seealso::
:ref:`metadata_reflection_toplevel`
:param autoload_replace: Defaults to ``True``; when using
:paramref:`.Table.autoload`
in conjunction with :paramref:`.Table.extend_existing`, indicates
that :class:`.Column` objects present in the already-existing
:class:`.Table` object should be replaced with columns of the same
name retrieved from the autoload process. When ``False``, columns
already present under existing names will be omitted from the
reflection process.
Note that this setting does not impact :class:`.Column` objects
specified programmatically within the call to :class:`.Table` that
also is autoloading; those :class:`.Column` objects will always
replace existing columns of the same name when
:paramref:`.Table.extend_existing` is ``True``.
.. versionadded:: 0.7.5
.. seealso::
:paramref:`.Table.autoload`
:paramref:`.Table.extend_existing`
:param autoload_with: An :class:`.Engine` or :class:`.Connection` object
with which this :class:`.Table` object will be reflected; when
set to a non-None value, it implies that :paramref:`.Table.autoload`
is ``True``. If left unset, but :paramref:`.Table.autoload` is
explicitly set to ``True``, an autoload operation w
没有合适的资源?快使用搜索试试~ 我知道了~
Python库 | SQLAlchemy-1.0.0b1.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 142 浏览量
2022-04-15
16:30:00
上传
评论
收藏 4.23MB GZ 举报
温馨提示
资源分类:Python库 所属语言:Python 资源全名:SQLAlchemy-1.0.0b1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
Python库 | SQLAlchemy-1.0.0b1.tar.gz (780个子文件)
AUTHORS 545B
processors.c 20KB
resultproxy.c 19KB
utils.c 5KB
setup.cfg 1KB
CHANGES 156B
docs.css 9KB
basic.css 8KB
pygments.css 4KB
changelog.css 97B
sphinx_paramlinks.css 89B
binary_data_two.dat 24KB
binary_data_one.dat 7KB
selectable.html 622KB
changelog_09.html 430KB
sqlelement.html 406KB
genindex.html 384KB
internals.html 364KB
changelog_06.html 337KB
changelog_08.html 308KB
changelog_07.html 302KB
metadata.html 290KB
constraints.html 290KB
dml.html 289KB
changelog_04.html 255KB
query.html 247KB
changelog_05.html 245KB
migration_10.html 245KB
tutorial.html 244KB
changelog_10.html 242KB
postgresql.html 236KB
connections.html 223KB
tutorial.html 222KB
migration_09.html 206KB
events.html 197KB
changelog_03.html 192KB
session_api.html 187KB
events.html 177KB
migration_08.html 164KB
mysql.html 152KB
internals.html 142KB
migration_07.html 117KB
mapping_api.html 117KB
custom_types.html 116KB
loading_relationships.html 106KB
mssql.html 104KB
inheritance.html 104KB
automap.html 103KB
collections.html 102KB
join_conditions.html 98KB
pooling.html 97KB
migration_06.html 92KB
glossary.html 92KB
type_basics.html 92KB
session_basics.html 90KB
associationproxy.html 90KB
hybrid.html 90KB
ddl.html 88KB
test_versioning.html 86KB
migration_04.html 86KB
oracle.html 81KB
sqlite.html 77KB
relationship_api.html 75KB
engines.html 74KB
session_transaction.html 73KB
mixins.html 73KB
changelog_02.html 70KB
mutable.html 69KB
session_state_management.html 66KB
examples.html 66KB
functions.html 66KB
reflection.html 63KB
defaults.html 62KB
migration_05.html 61KB
baked.html 60KB
api.html 59KB
changelog_01.html 56KB
contextual.html 54KB
compiler.html 52KB
mapped_attributes.html 51KB
performance.html 50KB
loading_columns.html 50KB
inheritance.html 49KB
sessions.html 48KB
basic_relationships.html 48KB
cascades.html 46KB
mapping_columns.html 44KB
ormconfiguration.html 43KB
backref.html 41KB
postgis.html 40KB
attribute_shard.html 40KB
persistence_techniques.html 39KB
deprecated.html 39KB
optimized_al.html 38KB
adjacency_list.html 36KB
history_meta.html 36KB
event.html 35KB
dictlike-polymorphic.html 35KB
type_api.html 34KB
self_referential.html 34KB
共 780 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
- 基于Java的财务报销管理系统后端开发源码
- 基于Python核心技术的cola项目设计源码介绍
- 基于Python及多语言集成的TSDT软件过程改进设计源码
- 基于Java语言的歌唱比赛评分系统设计源码
- 基于JavaEE技术的课程项目答辩源码设计——杨晔萌、李知林、岳圣杰、张俊范小组作品
- 基于Java原生安卓开发的蔚蓝档案娱乐应用设计源码
- 基于Java、Vue、JavaScript、CSS、HTML的毕设设计源码
- 基于Java和HTML的CMS看点咨询系统设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功