版本:1.1.0b2 |发布日期:2016年7月1日

SQLAlchemy 1.1文档


0.6.9 ¶ T0>


一般¶ T0>

  • [general] Adjusted the “importlater” mechanism, which is used internally to resolve import cycles, such that the usage of __import__ is completed when the import of sqlalchemy or sqlalchemy.orm is done, thereby avoiding any usage of __import__ after the application starts new threads, fixes.


ORM ¶ T0>

  • [orm] [bug] fixed inappropriate evaluation of user-mapped object in a boolean context within query.get().


  • [orm] [bug] Fixed the error formatting raised when a tuple is inadvertently passed to session.query().


  • [orm] Fixed bug whereby the source clause used by query.join() would be inconsistent if against a column expression that combined multiple entities together.


  • [orm] Fixed bug apparent only in Python 3 whereby sorting of persistent + pending objects during flush would produce an illegal comparison, if the persistent object primary key is not a single integer.


  • [orm] Fixed bug where query.join() + aliased=True from a joined-inh structure to itself on relationship() with join condition on the child table would convert the lead entity into the joined one inappropriately.


  • [orm] Fixed bug whereby mapper.order_by attribute would be ignored in the “inner” query within a subquery eager load. ¶ T0>


  • [orm] Fixed bug whereby if a mapped class redefined __hash__() or __eq__() to something non-standard, which is a supported use case as SQLA should never consult these, the methods would be consulted if the class was part of a “composite” (i.e. non-single-entity) result set.


  • [orm] Fixed subtle bug that caused SQL to blow up if: column_property() against subquery + joinedload + LIMIT + order by the column property() occurred. ¶ T0>


  • [orm] The join condition produced by with_parent as well as when using a “dynamic” relationship against a parent will generate unique bindparams, rather than incorrectly repeating the same bindparam. ¶ T0>


  • [orm] Repaired the “no statement condition” assertion in Query which would attempt to raise if a generative method were called after from_statement() were called..


  • [orm] Cls.column.collat​​e(“some collat​​ion”)现在可以工作。


发动机¶ T0>

  • [engine] Backported the fix for introduced in 0.7.4, which ensures that the connection is in a valid state before attempting to call rollback()/prepare()/release() on savepoint and two-phase transactions.


SQL ¶ T0>

  • [sql] Fixed two subtle bugs involving column correspondence in a selectable, one with the same labeled subquery repeated, the other when the label has been “grouped” and loses itself. 影响。¶ T0>


  • [sql] Fixed bug whereby “warn on unicode” flag would get set for the String type when used with certain dialects. 这个bug不在0.7.

  • [sql] Fixed bug whereby with_only_columns() method of Select would fail if a selectable were passed.. 但是,FROM行为在这里仍然是不正确的,因此在任何情况下都需要0.7来使用这个用例。


架构¶ T0>

  • [schema] 当ForeignKeyConstraint引用未找到父级的列名称时,添加了一条信息性错误消息

的PostgreSQL ¶ T0>

  • [postgresql] Fixed bug related to whereby the same modified index behavior in PG 9 affected primary key reflection on a renamed column..


MySQL的¶ T0>

  • [mysql] 修正了OurSQL方言的XA命令使用ANSI中性引用符号“'”而不是“”。¶ T0>


  • [mysql] 一个CREATE TABLE会把COLLATE选项放在CHARSET之后,这看起来是MySQL的任意规则的一部分,关于它是否会真正起作用。



  • [mssql] [bug] 在检索索引名称列表和索引内的列名时解码传入的值


预言¶ T0>

  • [oracle] 添加ORA-00028断开代码,使用cx_oracle _Error.code获取代码,


  • [oracle] 修复了没有生成正确DDL的oracle.RAW类型。


  • [oracle] 将CURRENT添加到保留字列表


杂项¶ T0>

  • [examples] Adjusted dictlike-polymorphic.py example to apply the CAST such that it works on PG, other databases.


0.6.8 ¶ T0>


ORM ¶ T0>

  • [orm] 针对基于列的实体调用query.get()是无效的,这种情况现在引发一个弃用警告。


  • [orm] 非主映射器将继承主映射器的_identity_class。这样一来,对于通常在继承映射中的类建立的non_primary将产生与主映射器的标识映射兼容的结果


  • [orm] Backported 0.7’s identity map implementation, which does not use a mutex around removal. 这是因为尽管0.6.7的调整,一些用户仍然陷入僵局。不使用互斥体的0.7方法似乎不会产生“字典改变大小”的问题,这是互斥体的原始原理。


  • [orm] Fixed the error message emitted for “can’t execute syncrule for destination column ‘q’; mapper ‘X’ does not map this column” to reference the correct mapper. ¶ T0>


  • [orm] Fixed bug where determination of “self referential” relationship would fail with no workaround for joined-inh subclass related to itself, or joined-inh subclass related to a subclass of that with no cols in the sub-sub class in the join condition.


  • [orm] mapper() will ignore non-configured foreign keys to unrelated tables when determining inherit condition between parent and child class. 这相当于已经应用于声明的行为。请注意,0.7有一个更全面的解决方案,改变了join()本身如何确定FK错误。


  • [orm] Fixed bug whereby mapper mapped to an anonymous alias would fail if logging were used, due to unescaped % sign in the alias name.


  • [orm] Modify the text of the message which occurs when the “identity” key isn’t detected on flush, to include the common cause that the Column isn’t set up to detect auto-increment correctly;.


  • [orm] Fixed bug where transaction-level “deleted” collection wouldn’t be cleared of expunged states, raising an error if they later became transient.


发动机¶ T0>

  • [engine] Adjusted the __contains__() method of a RowProxy result row such that no exception throw is generated internally; NoSuchColumnError() also will generate its message regardless of whether or not the column construct can be coerced to a string..


SQL ¶ T0>

  • [sql] Fixed bug whereby if FetchedValue was passed to column server_onupdate, it would not have its parent “column” assigned, added test coverage for all column default assignment patterns.


  • [sql] Fixed bug whereby nesting a label of a select() with another label in it would produce incorrect exported columns. 除此之外,这将破坏另一个column_property()的ORM column_property()映射。¶ T0>


的PostgreSQL ¶ T0>

  • [postgresql] Fixed bug affecting PG 9 whereby index reflection would fail if against a column whose name had changed. ¶ T0>


  • [postgresql] 关于数组数组MATCH运算符的一些单元测试修正。一个潜在的浮点错误问题是固定的,MATCH运算符的某些测试现在只能在面向EN的语言环境中执行。¶ T0>



  • [mssql] Fixed bug in MSSQL dialect whereby the aliasing applied to a schema-qualified table would leak into enclosing select statements.


  • [mssql] Fixed bug whereby DATETIME2 type would fail on the “adapt” step when used in result sets or bound parameters. 这个问题不在0.7.


0.6.7 ¶ T0>


ORM ¶ T0>

  • [orm] Tightened the iterate vs. remove mutex around the identity map iteration, attempting to reduce the chance of an (extremely rare) reentrant gc operation causing a deadlock. 可以在0.7中删除互斥。


  • [orm] Query.subquery()添加了name参数,以允许将固定名称分配给别名对象¶ T4>


  • [orm] 当连接表继承映射器在本地映射表上没有主键时(但在超类表上有pks),则发出警告。


  • [orm] Fixed bug where “middle” class in a polymorphic hierarchy would have no ‘polymorphic_on’ column if it didn’t also specify a ‘polymorphic_identity’, leading to strange errors upon refresh, wrong class loaded when querying from that target. 当使用单个表继承时,也会发出正确的WHERE标准。


  • [orm] Fixed bug where a column with a SQL or server side default that was excluded from a mapping with include_properties or exclude_properties would result in UnmappedColumnError.


  • [orm] 在异常情况下,在父对象被解除引用后发生集合上的附加事件或类似事件时,会发出警告,这会阻止父会话在会话中被标记为“脏” 。这是0.7中的一个例外。


  • [orm] Fixed bug in query.options() whereby a path applied to a lazyload using string keys could overlap a same named attribute on the wrong entity. 注意0.7有这个修补程序的更新版本。


  • [orm] Reworded the exception raised when a flush is attempted of a subclass that is not polymorphic against the supertype.


  • [orm] Some fixes to the state handling regarding backrefs, typically when autoflush=False, where the back-referenced collection wouldn’t properly handle add/removes with no net change. 感谢Richard Murri提供的测试案例+补丁。


  • [orm] a “having” clause would be copied from the inside to the outside query if from_self() were used..


发动机¶ T0>

  • [engine] Fixed bug in QueuePool, SingletonThreadPool whereby connections that were discarded via overflow or periodic cleanup() were not explicitly closed, leaving garbage collection to the task instead. 这通常只影响像Jython和Pypy这样的非引用计数后端。感谢Jaimy Azle的发现。


SQL ¶ T0>

  • [sql] Column.copy(), as used in table.tometadata(), copies the ‘doc’ attribute.


  • [sql] Added some defs to the resultproxy.c extension so that the extension compiles and runs on Python 2.4.


  • [sql] The compiler extension now supports overriding the default compilation of expression._BindParamClause including that the auto-generated binds within the VALUES/SET clause of an insert()/update() statement will also use the new compilation rules.


  • [sql] Added accessors to ResultProxy “returns_rows”, “is_insert”


  • [sql] The limit/offset keywords to select() as well as the value passed to select.limit()/offset() will be coerced to integer.


的PostgreSQL ¶ T0>

  • [postgresql] When explicit sequence execution derives the name of the auto-generated sequence of a SERIAL column, which currently only occurs if implicit_returning=False, now accommodates if the table + column name is greater than 63 characters using the same logic Postgresql uses.


  • [postgresql] 在“断开”异常列表中添加了额外的libpq消息,“无法从服务器接收数据”


  • [postgresql] 为postgresql方言增加了RESERVED_WORDS。


  • [postgresql] 固定BIT类型允许“长度”参数,“变化”参数。反射也是固定的。


MySQL的¶ T0>

  • [mysql] oursql dialect accepts the same “ssl” arguments in create_engine() as that of MySQLdb.


源码¶ T0>

  • [sqlite] Fixed bug where reflection of foreign key created as “REFERENCES ” without col name would fail.



  • [mssql] Rewrote the query used to get the definition of a view, typically when using the Inspector interface, to use sys.sql_modules instead of the information schema, thereby allowing views definitions longer than 4000 characters to be fully returned.


预言¶ T0>

  • [oracle] Using column names that would require quotes for the column itself or for a name-generated bind parameter, such as names with special characters, underscores, non-ascii characters, now properly translate bind parameter keys when talking to cx_oracle.


  • [oracle] Oracle dialect adds use_binds_for_limits=False create_engine() flag, will render the LIMIT/OFFSET values inline instead of as binds, reported to modify the execution plan used by Oracle.


火鸟¶ T0>

  • [firebird] The “implicit_returning” flag on create_engine() is honored if set to False.


杂项¶ T0>

  • [informix] 新增RESERVED_WORDS informix方言


  • [ext] The horizontal_shard ShardedSession class accepts the common Session argument “query_cls” as a constructor argument, to enable further subclassing of ShardedQuery.


  • [declarative] 添加了一个明确的检查,用于名称'metadata'用于声明类的列属性。


  • [declarative] 修复引用旧的@classproperty名称引用@declared_attr 的错误消息


  • [declarative] Arguments in __mapper_args__ that aren’t “hashable” aren’t mistaken for always-hashable, possibly-column arguments.


  • [documentation] 记录的SQLite DATE / TIME / DATETIME类型


  • [examples] The Beaker caching example allows a “query_cls” argument to the query_callable() function.


0.6.6 ¶ T0>


ORM ¶ T0>

  • [orm] Fixed bug whereby a non-“mutable” attribute modified event which occurred on an object that was clean except for preceding mutable attribute changes would fail to strongly reference itself in the identity map. 这将导致对象被垃圾收集,失去了以前没有保存在“可变更改”字典中的任何更改的跟踪。

  • [orm] Fixed bug whereby “passive_deletes=’all’” wasn’t passing the correct symbols to lazy loaders during flush, thereby causing an unwarranted load.


  • [orm] Fixed bug which prevented composite mapped attributes from being used on a mapped select statement.. 请注意,复合材料的工作将在0.7. 中发生显着变化


  • [orm] active_history flag also added to composite(). 该标志在0.6中没有任何效果,而是一个用于向前兼容的占位符标志,正如它在0.7中应用于组合。


  • [orm] Fixed uow bug whereby expired objects passed to Session.delete() would not have unloaded references or collections taken into account when deleting objects, despite passive_deletes remaining at its default of False.


  • [orm] 当继承的映射器上已经指定了version_id_col时,如果这些列表达式不相同,则会发出警告。


  • [orm] “innerjoin” flag doesn’t take effect along the chain of joinedload() joins if a previous join in that chain is an outer join, thus allowing primary rows without a referenced child row to be correctly returned in results.


  • [orm] Fixed bug regarding “subqueryload” strategy whereby strategy would fail if the entity was an aliased() construct.


  • [orm] Fixed bug regarding “subqueryload” strategy whereby the join would fail if using a multi-level load of the form from A->joined-subclass->C


  • [orm] 固定Query对象的索引值-1。它被错误地转换为导致IndexError的空片-1:0.


  • [orm] The mapper argument “primary_key” can be passed as a single column as well as a list or tuple. 说明它为标量值的文档示例已被更改为列表。


  • [orm] Added active_history flag to relationship() and column_property(), forces attribute events to always load the “old” value, so that it’s available to attributes.get_history().


  • [orm] 如果组合键中的参数个数太多,而且太小,Query.get()将会出现。


  • [orm] Backport of “optimized get” fix from 0.7, improves the generation of joined-inheritance “load expired row” behavior.


  • [orm] A little more verbiage to the “primaryjoin” error, in an unusual condition that the join condition “works” for viewonly but doesn’t work for non-viewonly, and foreign_keys wasn’t used - adds “foreign_keys” to the suggestion. 对于通用“方向”错误的建议,也加上“foreign_keys”。

发动机¶ T0>

  • [engine] 现在,仅当明确使用Unicode类型时,才引发针对非Unicode绑定数据的“unicode警告”。而不是在引擎或字符串类型上使用convert_unicode = True时

  • [engine] Fixed memory leak in C version of Decimal result processor.


  • [engine] 为RowProxy的C版本实现序列检查功能,为RowProxy实现2.7样式的“collections.Sequence”注册


  • [engine] Threadlocal engine methods rollback(), commit(), prepare() won’t raise if no transaction is in progress; this was a regression introduced in 0.6.


  • [engine] Threadlocal engine returns itself upon begin(), begin_nested(); engine then implements contextmanager methods to allow the “with” statement.


SQL ¶ T0>

  • [sql] Fixed operator precedence rules for multiple chains of a single non-associative operator. 即“x - (y - z)”将被编译为“x - (y - z)”而不是“x - y - z”。也可以使用标签,即“x - (y - z).label('foo')”


  • [sql] The ‘info’ attribute of Column is copied during Column.copy(), i.e. as occurs when using columns in declarative mixins.


  • [sql] 为布尔值增加了一个绑定处理器,这个布尔值强制为int,对于像pymssql这样的天真地调用str()的DBAPI。

  • [sql] CheckConstraint will copy its ‘initially’, ‘deferrable’, and ‘_create_rule’ attributes within a copy()/tometadata()


的PostgreSQL ¶ T0>

  • [postgresql] IN子句中的单个元素元组表达式正确地括起来,也来自


  • [postgresql] Ensured every numeric, float, int code, scalar + array, are recognized by psycopg2 and pg8000’s “numeric” base type.


  • [postgresql] 添加as_uuid = True标志到UUID类型,将接收并返回值作为Python UUID()对象而不是字符串。目前,UUID类型只能用于psycopg2.


  • [postgresql] Fixed bug whereby KeyError would occur with non-ENUM supported PG versions after a pool dispose+recreate would occur.


MySQL的¶ T0>

  • [mysql] Fixed error handling for Jython + zxjdbc, such that has_table() property works again. 从0.6.3回归(我们没有Jython buildbot,对不起)


源码¶ T0>

  • [sqlite] CREATE TABLE中的REFERENCES子句,包含具有相同模式名称的另一个表的远程模式,现在根据SQLite的要求,使用没有schema子句的远程名称/ T2>


  • [sqlite] On the same theme, the REFERENCES clause in a CREATE TABLE that includes a remote schema to a different schema than that of the parent table doesn’t render at all, as cross-schema references do not appear to be supported.


  • [mssql] 不幸的是没有正确测试索引反射的重写,并返回不正确的结果。现在这个回归是固定的。


预言¶ T0>

  • [oracle] The cx_oracle “decimal detection” logic, which takes place for result set columns with ambiguous numeric characteristics, now uses the decimal point character determined by the locale/ NLS_LANG setting, using an on-first-connect detection of this character. 使用非周期小数点NLS_LANG设置时,还需要cx_oracle 5.0.3或更高版本。


火鸟¶ T0>

  • [firebird] Firebird numeric type now checks for Decimal explicitly, lets float() pass right through, thereby allowing special values such as float(‘inf’).


杂项¶ T0>

  • [declarative] 如果__table_args__不是tuple或dict格式,并且不是None,则会产生错误。


  • [sqlsoup] Added “map_to()” method to SqlSoup, which is a “master” method which accepts explicit arguments for each aspect of the selectable and mapping, including a base class per mapping.


  • [sqlsoup] 与map(),with_labels(),join()方法一起使用的mapable selectables不再把给定的参数放到内部的“cache”字典中。特别是由于join()和select()对象是在方法本身中创建的,所以这几乎是纯粹的内存泄漏行为。

  • [examples] The versioning example now supports detection of changes in an associated relationship().

0.6.5 ¶ T0>


ORM ¶ T0>

  • [orm] 添加了一个新的“lazyload”选项“immediateload”。在填充对象时自动发出通常的“惰性”加载操作。这里的用例是当加载对象被放置在脱机缓存中时,或者在会话不可用之后以其他方式使用时,并且希望直接“选择”加载而不是“加入”或“子查询”。¶ T0>


  • [orm] New Query methods: query.label(name), query.as_scalar(), return the query’s statement as a scalar subquery with /without label; query.with_entities(*ent), replaces the SELECT list of the query with new entities. 大致相当于query.values()的生成形式,它接受映射实体以及列表达式。


  • [orm] Fixed recursion bug which could occur when moving an object from one reference to another, with backrefs involved, where the initiating parent was a subclass (with its own mapper) of the previous parent.

  • [orm] Fixed a regression in 0.6.4 which occurred if you passed an empty list to “include_properties” on mapper()


  • [orm] 在Query中修正了标签错误,如果任何列表达式都没有被标记,NamedTuple将错误应用标签。

  • [orm] Patched a case where query.join() would adapt the right side to the right side of the left’s join inappropriately


  • [orm] Query.select_from() has been beefed up to help ensure that a subsequent call to query.join() will use the select_from() entity, assuming it’s a mapped entity and not a plain selectable, as the default “left” side, not the first entity in the Query object’s list of entities.

  • [orm] The exception raised by Session when it is used subsequent to a subtransaction rollback (which is what happens when a flush fails in autocommit=False mode) has now been reworded (this is the “inactive due to a rollback in a subtransaction” message). 尤其是,如果回滚是由于flush()期间的异常造成的,则消息将说明是这种情况,并重申在刷新期间发生的原始异常的字符串形式。如果会话由于显式使用了子事务(不是很常见)而被关闭,那么这个消息就是这种情况。

  • [orm] The exception raised by Mapper when repeated requests to its initialization are made after initialization already failed no longer assumes the “hasattr” case, since there’s other scenarios in which this message gets emitted, and the message also does not compound onto itself multiple times - you get the same message for each attempt at usage. “compiles”这个用词不明的地方正在交易中用于“初始化”。

  • [orm] Fixed bug in query.update() where ‘evaluate’ or ‘fetch’ expiration would fail if the column expression key was a class attribute with a different keyname as the actual column name.


  • [orm] Added an assertion during flush which ensures that no NULL-holding identity keys were generated on “newly persistent” objects. 当用户定义的代码无意中触发未完全加载的对象上的刷新时,可能会发生这种情况。

  • [orm] lazy loads for relationship attributes now use the current state, not the “committed” state, of foreign and primary key attributes when issuing SQL, if a flush is not in process. 以前只能使用数据库提交状态。特别是,这会导致多对一的get() - on-lazyload操作失败,因为当这些属性被确定并且“提交”状态可能不可用时,autoflush不会被触发。¶ T0>


  • [orm] A new flag on relationship(), load_on_pending, allows the lazy loader to fire off on pending objects without a flush taking place, as well as a transient object that’s been manually “attached” to the session. 请注意,此标志阻止加载对象时发生的属性事件,因此,直到刷新后,backrefs才可用。该标志仅用于特定的用例。

  • [orm] Another new flag on relationship(), cascade_backrefs, disables the “save-update” cascade when the event was initiated on the “reverse” side of a bidirectional relationship. 这是一种更清晰的行为,可以将多对一设置为临时对象,而不会将其吸引到子对象的会话中,同时仍允许向前集合级联。我们可能在0.7中默认为False

  • [orm] Slight improvement to the behavior of “passive_updates=False” when placed only on the many-to-one side of a relationship; documentation has been clarified that passive_updates=False should really be on the one-to-many side.

  • [orm] 在多对一的情况下放置passive_deletes = True会发出警告,因为您可能打算把它放在一对多的一边。

  • [orm] Fixed bug that would prevent “subqueryload” from working correctly with single table inheritance for a relationship from a subclass - the “where type in (x, y, z)” only gets placed on the inside, instead of repeatedly.

  • [orm] When using from_self() with single table inheritance, the “where type in (x, y, z)” is placed on the outside of the query only, instead of repeatedly. 可以对此进行一些调整。

  • [orm] scoped_session emits a warning when configure() is called if a Session is already present (checks only the current thread)


  • [orm] reworked the internals of mapper.cascade_iterator() to cut down method calls by about 9% in some circumstances.


发动机¶ T0>

  • [engine] 固定了0.6.4中的一个回归,从而允许光标错误一致的更改打破了result.lastrowid访问器。已经为result.lastrowid添加了测试覆盖率。请注意,lastrowid只支持Pysqlite和一些MySQL驱动程序,所以在一般情况下不是超级有用的。

  • [engine] the logging message emitted by the engine when a connection is first used is now “BEGIN (implicit)” to emphasize that DBAPI has no explicit begin().

  • [engine] 在metadata.reflect()中添加了“views = True”选项,将可用视图的列表添加到正在反映的视图中。


  • [engine] engine_from_config() now accepts ‘debug’ for ‘echo’, ‘echo_pool’, ‘force’ for ‘convert_unicode’, boolean values for ‘use_native_unicode’.


SQL ¶ T0>

  • [sql] Fixed bug in TypeDecorator whereby the dialect-specific type was getting pulled in to generate the DDL for a given type, which didn’t always return the correct result.

  • [sql] TypeDecorator can now have a fully constructed type specified as its “impl”, in addition to a type class.

  • [sql] TypeDecorator will now place itself as the resulting type for a binary expression where the type coercion rules would normally return its impl type - previously, a copy of the impl type would be returned which would have the TypeDecorator embedded into it as the “dialect” impl, this was probably an unintentional way of achieving the desired effect.

  • [sql] TypeDecorator.load_dialect_impl() returns “self.impl” by default, i.e. not the dialect implementation type of “self.impl”. 这支持编译正确。行为可以像以前一样以相同的方式被用户覆盖,达到相同的效果。

  • [sql] 添加了type_coerce(expr,type_)表达式元素。在计算表达式和处理结果行时,将给定的表达式视为给定类型,但不影响除匿名标签之外的SQL生成。

  • [sql] Table.tometadata() now copies Index objects associated with the Table as well.

  • [sql] Table.tometadata() issues a warning if the given Table is already present in the target MetaData - the existing Table object is returned.

  • [sql] An informative error message is raised if a Column which has not yet been assigned a name, i.e. as in declarative, is used in a context where it is exported to the columns collection of an enclosing select() construct, or if any construct involving that column is compiled before its name is assigned.

  • [sql] as_scalar(), label() can be called on a selectable which contains a Column that is not yet named.


  • [sql] Fixed recursion overflow which could occur when operating with two expressions both of type “NullType”, but not the singleton NULLTYPE instance.


的PostgreSQL ¶ T0>

  • [postgresql] 将“as_tuple”标志添加到ARRAY类型,将结果作为元组返回,而不是列表以允许散列。

  • [postgresql] 修正了阻止从“enum”等自定义类型构建“domain”的bug。


MySQL的¶ T0>

  • [mysql] Fixed bug involving reflection of CURRENT_TIMESTAMP default used with ON UPDATE clause, thanks to Taavi Burns



  • [mssql] 修正了未能正确处理未知类型反射的反射问题。


  • [mssql] Fixed bug where aliasing of tables with “schema” would fail to compile properly.


  • [mssql] 重写索引的反射以使用sys。目录,以便任何配置的列名(空格,嵌入逗号等)可以反映出来。请注意,索引的反射需要SQL Server 2005或更高版本。


  • [mssql] 现在,mssql + pymssql方言尊重URL的“端口”部分,而不是放弃它。


预言¶ T0>

  • [oracle] 无论检测到Oracle的版本,现在都可以使用create_engine()的implicit_retunring参数。Previously, the flag would be forced to False if server version info was < 10.


杂项¶ T0>

  • [declarative] @classproperty(soon / now @dered_attr)对不是mixin的基类的__mapper_args__,__table_args__,__tablename__生效,以及mixins


  • [declarative] @classproperty ‘s official name/location for usage with declarative is sqlalchemy.ext.declarative.declared_attr. 同样的事情,但在那里移动,因为它更多的是一个“标记”,而不仅仅是一个属性技术。


  • [declarative] Fixed bug whereby columns on a mixin wouldn’t propagate correctly to a single-table, or joined-table, inheritance scheme where the attribute name is different than that of the column.,.


  • [declarative] A mixin can now specify a column that overrides a column of the same name associated with a superclass. 感谢Oystein Haaland。

  • [informix] Major cleanup / modernization of the Informix dialect for 0.6, courtesy Florian Apolloner.


  • [tests] the NoseSQLAlchemyPlugin has been moved to a new package “sqlalchemy_nose” which installs along with “sqlalchemy”. 这样,“nosetests”脚本将一如既往地工作,而且还允许-with-coverage选项在SQLAlchemy模块导入之前打开覆盖范围,从而使coverage能够正常工作。

  • [misc] CircularDependencyError now has .cycles and .edges members, which are the set of elements involved in one or more cycles, and the set of edges as 2-tuples.


0.6.4 ¶ T0>


ORM ¶ T0>

  • [orm] 名称ConcurrentModificationError已更改为StaleDataError,并且已修改描述性错误消息以准确反映问题所在。对于可能在“except:”子句中指定ConcurrentModificationError的方案,这两个名称将保留在可预见的将来。

  • [orm] Added a mutex to the identity map which mutexes remove operations against iteration methods, which now pre-buffer before returning an iterable. 这是因为asyncrhonous gc可以随时通过gc线程移除项目。


  • [orm] The Session class is now present in sqlalchemy.orm.*. 对于那些需要一步式Session构造函数的情况,我们不再使用具有非标准默认值的create_session()。然而,大多数用户应该坚持使用sessionmaker()。

  • [orm] query.with_parent() now accepts transient objects and will use the non-persistent values of their pk/fk attributes in order to formulate the criterion. 文件也明确了with_parent()。的用途

  • [orm] The include_properties and exclude_properties arguments to mapper() now accept Column objects as members in addition to strings. 这样就可以区分名称相同的Column对象,如join()中的对象。

  • [orm] A warning is now emitted if a mapper is created against a join or other single selectable that includes multiple columns with the same name in its .c. 集合,并且这些列没有明确命名为相同或单独属性(或排除)的一部分。在0.7这个警告将是一个例外。请注意,当组合因继承而发生时,不会发出此警告,因此属性仍允许自然地被覆盖。在0.7中会进一步改善。


  • [orm] The primary_key argument to mapper() can now specify a series of columns that are only a subset of the calculated “primary key” columns of the mapped selectable, without an error being raised. 这有助于可选择的有效主键比可选中实际标记为“primary_key”的列的数量更简单的情况,例如在主键列上与两个表的联接。


  • [orm] An object that’s been deleted now gets a flag ‘deleted’, which prohibits the object from being re-add()ed to the session, as previously the object would live in the identity map silently until its attributes were accessed. make_transient()函数现在重置此标志以及“key”标志。

  • [orm] make_transient() can be safely called on an already transient instance.

  • [orm] a warning is emitted in mapper() if the polymorphic_on column is not present either in direct or derived form in the mapped selectable or in the with_polymorphic selectable, instead of silently ignoring it. 寻找这个在0.7中成为例外。

  • [orm] Another pass through the series of error messages emitted when relationship() is configured with ambiguous arguments. “foreign_keys”设置不再被提及,因为它几乎是不需要的,最好用户设置正确的ForeignKey元数据,这是现在的建议。如果使用“foreign_keys”并且不正确,那么消息建议该属性可能是不必要的。文档的属性被加强。这是因为ML上的所有混淆的关系()用户似乎都试图使用foreign_keys,由于这个消息只是表达元数据更清晰,所以只会进一步混淆他们。

  • [orm] If the “secondary” table has no ForeignKey metadata and no foreign_keys is set, even though the user is passing screwed up information, it is assumed that primary/secondaryjoin expressions should consider only and all cols in “secondary” to be foreign. 在任何情况下,外键都不能在其他地方使用“secondary”。现在发出警告而不是错误,映射成功。


  • [orm] Moving an o2m object from one collection to another, or vice versa changing the referenced object by an m2o, where the foreign key is also a member of the primary key, will now be more carefully checked during flush if the change in value of the foreign key on the “many” side is the result of a change in the primary key of the “one” side, or if the “one” is just a different object. 在一个例子中,一个可级联的数据库已经级联了这个值,我们需要看看“新”PK值来做更新,另一个我们需要继续看“老”。We now look at the “old”, assuming passive_updates=True, unless we know it was a PK switch that triggered the change.


  • [orm] 可以手动更改version_id_col的值,这将导致该行的UPDATE。版本化的UPDATE和DELETE现在使用WHERE子句中version_id_col的“提交”值,而不是挂起的更改值。如果在属性上存在手动更改,版本生成器也会被绕过。


  • [orm] Repaired the usage of merge() when used with concrete inheriting mappers. 这样的映射器通常具有所谓的“具体”属性,这些属性是“禁止”从父项传播的子类属性 - 这些属性允许merge()操作无效地传递。

  • [orm] Specifying a non-column based argument for column_mapped_collection, including string, text() etc., will raise an error message that specifically asks for a column element, no longer misleads with incorrect information about text() or literal().


  • [orm] Similarly, for relationship(), foreign_keys, remote_side, order_by - all column-based expressions are enforced - lists of strings are explicitly disallowed since this is a very common error

  • [orm] Dynamic attributes don’t support collection population - added an assertion for when set_committed_value() is called, as well as when joinedload() or subqueryload() options are applied to a dynamic attribute, instead of failure / silent failure.


  • [orm] Fixed bug whereby generating a Query derived from one which had the same column repeated with different label names, typically in some UNION situations, would fail to propagate the inner columns completely to the outer query.


  • [orm] object_session() raises the proper UnmappedInstanceError when presented with an unmapped instance.


  • [orm] 对计算的Mapper属性应用进一步的记忆,在大量多态映射配置中,运行时mapper.py调用计数大大减少(〜90%)。

  • [orm] mapper _get_col_to_prop private method used by the versioning example is deprecated; now use mapper.get_property_by_column() which will remain the public method for this.

  • [orm] 版本化示例现在可以正常工作,如果在以前为NULL的col上进行版本控制

发动机¶ T0>

  • [engine] Calling fetchone() or similar on a result that has already been exhausted, has been closed, or is not a result-returning result now raises ResourceClosedError, a subclass of InvalidRequestError, in all cases, regardless of backend. 以前,一些DBAPI会引发ProgrammingError(即pysqlite),其他的会返回None,导致下游的破坏(即MySQL-python)。

  • [engine] Fixed bug in Connection whereby if a “disconnect” event occurred in the “initialize” phase of the first connection pool connect, an AttributeError would be raised when the Connection would attempt to invalidate the DBAPI connection.


  • [engine] Connection, ResultProxy, as well as Session use ResourceClosedError for all “this connection/transaction/result is closed” types of errors.

  • [engine] Connection.invalidate() can be called more than once and subsequent calls do nothing.

SQL ¶ T0>

  • [sql] Calling execute() on an alias() construct is pending deprecation for 0.7, as it is not itself an “executable” construct. 它目前“代理”它的内在元素,并且是有条件的“可执行的”,但是这并不是我们现在喜欢的那种模棱两可。

  • [sql] The execute() and scalar() methods of ClauseElement are now moved appropriately to the Executable subclass. ClauseElement.execute()/ scalar()仍然存在,并且在0.7中被弃用,但是请注意,如果你不是一个可执行文件,这些总会引发一个错误(除非你是一个别名(),参见前面的注释)¶ T0>

  • [sql] 为Numeric-> Integer添加了基本的数学表达式强制,所以无论表达式的方向如何,结果类型都是Numeric。

  • [sql] 在列上使用“index = True”标志时,更改了用于生成截断的“auto”索引名称的方案。截断只发生在自动生成的名字中,而不是用户定义的名字(而不是用户自定义的名字),截断方案本身现在基于标识符名称的md5哈希碎片,所以名称相似的列上的多个索引仍然具有唯一的名称。


  • [sql] The generated index name also is based on a “max index name length” attribute which is separate from the “max identifier length” - this to appease MySQL who has a max length of 64 for index names, separate from their overall max length of 255.


  • [sql] the text() construct, if placed in a column oriented situation, will at least return NULLTYPE for its type instead of None, allowing it to be used a little more freely for ad-hoc column expressions than before. 然而,literal_column()仍然是更好的选择。

  • [sql] 当ForeignKey无法解析目标时,添加了对父表/列,目标表/列的错误信息的完整描述

  • [sql] Fixed bug whereby replacing composite foreign key columns in a reflected table would cause an attempt to remove the reflected constraint from the table a second time, raising a KeyError.


  • [sql] the _Label construct, i.e. the one that is produced whenever you say somecol.label(), now counts itself in its “proxy_set” unioned with that of its contained column’s proxy set, instead of directly returning that of the contained column. 这允许依赖于_Labels本身身份的列对应操作返回正确的结果

  • [sql] 修复了ORM bug。


的PostgreSQL ¶ T0>

  • [postgresql] Fixed the psycopg2 dialect to use its set_isolation_level() method instead of relying upon the base “SET SESSION ISOLATION” command, as psycopg2 resets the isolation level on each new transaction otherwise.


  • [mssql] Fixed “default schema” query to work with pymssql backend.

预言¶ T0>

  • [oracle] 对于需要显式CAST的情况,在Oracle方言中增加了ROWID类型。


  • [oracle] Oracle reflection of indexes has been tuned so that indexes which include some or all primary key columns, but not the same set of columns as that of the primary key, are reflected. 包含与主键相同的列的索引在反射内被跳过,因为在这种情况下索引被假定为自动生成的主键索引。以前,PK列存在的任何索引都会被跳过。感谢Kent Bower的补丁。


  • [oracle] Oracle now reflects the names of primary key constraints - also thanks to Kent Bower.


火鸟¶ T0>

  • [firebird] 修正了如果“default”关键字是小写字母,列默认值将无法反映的问题。

杂项¶ T0>

  • [declarative] if @classproperty is used with a regular class-bound mapper property attribute, it will be called to get the actual attribute value during initialization. 目前,在不是混合的声明类的列或关系属性上使用@class属性没有什么好处 - 评估与不使用@class属性的同时。但在这里,我们至少允许它按预期运行。

  • [declarative] Fixed bug where “Can’t add additional column” message would display the wrong name.

  • [informix] 使用补丁来重新获得基本的Informix功能。我们依靠最终用户测试来确保Informix在某种程度上工作。


  • [documentation] The docs have been reorganized such that the “API Reference” section is gone - all the docstrings from there which were public API are moved into the context of the main doc section that talks about it. 主要文档分为“SQLAlchemy核心”和“SQLAlchemy ORM”部分,mapper / relationship文档已经被打破。许多部分被重写和/或重组。

  • [examples] The beaker_caching example has been reorganized such that the Session, cache manager, declarative_base are part of environment, and custom cache code is portable and now within “caching_query.py”. 这使得这个例子可以更容易地“拖入”现有的项目。

  • [examples] 当复制列时,history_meta版本控制配方设置“unique = False”,以便版本控制表处理具有重复值的多个行


0.6.3 ¶ T0>


ORM ¶ T0>

  • [orm] Removed errant many-to-many load in unitofwork which triggered unnecessarily on expired/unloaded collections. 只有当passive_updates为False并且父主键已经改变时,或者如果passive_deletes为False并且已经发生了父项的删除,这个加载现在才会发生。


  • [orm] Column-entities (i.e. query(Foo.id)) copy their state more fully when queries are derived from themselves + a selectable (i.e. from_self(), union(), etc. ),所以join()等具有正确的工作状态。


  • [orm] Fixed bug where Query.join() would fail if querying a non-ORM column then joining without an on clause when a FROM clause is already present, now raises a checked exception the same way it does when the clause is not present.


  • [orm] Improved the check for an “unmapped class”, including the case where the superclass is mapped but the subclass is not. 任何尝试访问cls._sa_class_manager.mapper的尝试都会引发UnmappedClassError()。


  • [orm] Added “column_descriptions” accessor to Query, returns a list of dictionaries containing naming/typing information about the entities the Query will return. 可以有助于在ORM查询之上构建GUI。

MySQL的¶ T0>

  • [mysql] The _extract_error_code() method now works correctly with each MySQL dialect ( MySQL-python, OurSQL, MySQL-Connector-Python, PyODBC). 以前,重新连接逻辑会失败的OperationalError条件,但是由于MySQLdb和OurSQL有自己的重新连接功能,这里没有这些驱动程序的症状,除非一个人看日志。


预言¶ T0>

  • [oracle] 更多调整cx_oracle十进制处理。不含小数位的“模糊”数字在连接处理程序级被强制为int。这样做的好处是int返回时不会涉及到SQLA类型的对象,并且不必先转换为Decimal。



0.6.2 ¶ T0>


ORM ¶ T0>

  • [orm] Query.join() will check for a call of the form query.join(target, clause_expression), i.e. missing the tuple, and raise an informative error message that this is the wrong calling form.

  • [orm] Fixed bug regarding flushes on self-referential bi-directional many-to-many relationships, where two objects made to mutually reference each other in one flush would fail to insert a row for both sides. 0.5的回归。


  • [orm] the post_update feature of relationship() has been reworked architecturally to integrate more closely with the new 0.6 unit of work. 更改的动机是在一个UPDATE语句中执行多个“更新后”调用(每个调用同一行的不同外键列),而不是每行每列一个UPDATE语句。在保持一致的行排序的同时,多行更新也被批量放入executemany()中。

  • [orm] Query.statement,Query.subquery()等现在将绑定参数的值(即由query.params()指定的参数)转移到生成的SQL表达式中。以前,这些值不会被传送,绑定参数会变成None。

  • [orm] Subquery-eager-loading now works with Query objects which include params(), as well as get() Queries.

  • [orm] Can now call make_transient() on an instance that is referenced by parent objects via many-to-one, without the parent’s foreign key value getting temporarily set to None - this was a function of the “detect primary key switch” flush handler. 现在忽略不再处于“持久”状态的对象,并且父母的外键标识符不受影响。

  • [orm] query.order_by() now accepts False, which cancels any existing order_by() state on the Query, allowing subsequent generative methods to be called which do not support ORDER BY. 这与传递None的已有功能不同,后者会禁止任何现有的order_by()设置,包括映射器上配置的那些设置。False会使得order_by()永远不会被调用,而None是一个有效的设置。

  • [orm] An instance which is moved to “transient”, has an incomplete or missing set of primary key attributes, and contains expired attributes, will raise an InvalidRequestError if an expired attribute is accessed, instead of getting a recursion overflow.

  • [orm] make_transient()函数现在位于生成的文档中。

  • [orm] make_transient() removes all “loader” callables from the state being made transient, removing any “expired” state - all unloaded attributes reset back to undefined, None/empty on access.

SQL ¶ T0>

  • [sql] 由convert_unicode = True的Unicode和String类型发出的警告不再嵌入传递的实际值。这样一来,Python警告注册表的大小不会继续增加,警告会按照警告过滤器设置发出一次,而大字符串值不会污染输出。


  • [sql] Fixed bug that would prevent overridden clause compilation from working for “annotated” expression elements, which are often generated by the ORM.

  • [sql] LIKE运算符或类似运算符的“ESCAPE”参数通过render_literal_value()传递,可能会实现反斜杠的转义。


  • [sql] Fixed bug in Enum type which blew away native_enum flag when used with TypeDecorators or other adaption scenarios.

  • [sql] Inspector hits bind.connect() when invoked to ensure initialize has been called. 内部名称“.conn”更改为“.bind”,因为这就是它的原因。

  • [sql] Modified the internals of “column annotation” such that a custom Column subclass can safely override _constructor to return Column, for the purposes of making “configurational” column classes that aren’t involved in proxying, etc.

  • [sql] Column.copy() takes along the “unique” attribute among others, fixes regarding declarative mixins


的PostgreSQL ¶ T0>

  • [postgresql] render_literal_value() is overridden which escapes backslashes, currently applies to the ESCAPE clause of LIKE and similar expressions. 最终,这将必须检测“standard_conforming_strings”的完整行为的价值。


  • [postgresql] 如果在8.3之前的PG版本中使用types.Enum,则不会生成“CREATE TYPE”/“DROP TYPE” - supports_native_enum标志完全符合条件¶ t2 >


MySQL的¶ T0>

  • [mysql] MySQL dialect doesn’t emit CAST() for MySQL version detected < 4.0.2. 这允许在连接上进行unicode检查。


  • [mysql] 除了ANSI_QUOTES,MySQL方言现在还检测NO_BACKSLASH_ESCAPES sql模式。

  • [mysql] render_literal_value() is overridden which escapes backslashes, currently applies to the ESCAPE clause of LIKE and similar expressions. 这个行为来源于检测NO_BACKSLASH_ESCAPES的值。



  • [mssql] If server_version_info is outside the usual range of (8, ), (9, ), (10, ), a warning is emitted which suggests checking that the FreeTDS version configuration is using 7.0 or 8.0, not 4.2.


预言¶ T0>

  • [oracle] Fixed ora-8 compatibility flags such that they don’t cache a stale value from before the first database connection actually occurs.


  • [oracle] Oracle’s “native decimal” metadata begins to return ambiguous typing information about numerics when columns are embedded in subqueries as well as when ROWNUM is consulted with subqueries, as we do for limit/offset. 我们已经将这些不明确的条件添加到cx_oracle“convert to Decimal()”处理程序中,以便在更多情况下而不是作为浮点数接收数字。如果需要的话,这些被转换成Integer或者Float,或者被保存为无损的Decimal。


火鸟¶ T0>

  • [firebird] 修正了do_execute()中的错误签名,0.6.1中引入了错误。


  • [firebird] Firebird dialect adds CHAR, VARCHAR types which accept a “charset” flag, to support Firebird “CHARACTER SET” clause.


杂项¶ T0>

  • [declarative] Added support for @classproperty to provide any kind of schema/mapping construct from a declarative mixin, including columns with foreign keys, relationships, column_property, deferred. 这解决了所有关于声明性混合的问题。如果在mixin中指定了任何MapperProperty子类而不使用@classproperty,则会产生错误。

    References: #1805, #1796, #1751

  • [declarative] a mixin class can now define a column that matches one which is present on a __table__ defined on a subclass. 但是,它不能定义__table__中不存在的一个,现在这个错误信息就起作用了。


  • [extension] [compiler] 当覆盖编译内置子句结构时,会自动复制'default'编译器,所以如果用户定义的编译器特定于特定的后端,则不会引发KeyError;调用另一个后端的编译。


  • [documentation] 添加了Inspector的文档


  • [documentation] Fixed @memoized_property and @memoized_instancemethod decorators so that Sphinx documentation picks up these attributes and methods, such as ResultProxy.inserted_primary_key.


0.6.1 ¶ T0>


ORM ¶ T0>

  • [orm] 修正0.6.0版中引入的回归,涉及对可变属性进行不正确的历史记录。


  • [orm] Fixed regression introduced in 0.6.0 unit of work refactor that broke updates for bi-directional relationship() with post_update=True.


  • [orm] session.merge() will not expire attributes on the returned instance if that instance is “pending”.


  • [orm] 修正了CollectionAdapter的__setstate__方法,在反序列化过程中父级InstanceState还没有被反序列化的时候不会失败


  • [orm] 添加内部警告,以防万一没有完整PK的实例发生过期,然后被要求刷新。


  • [orm] Added more aggressive caching to the mapper’s usage of UPDATE, INSERT, and DELETE expressions. 假设该语句没有附加每个对象的SQL表达式,表达式对象在第一次创建之后由映射器缓存,并且其编译后的表单在相关引擎期间持久地存储在缓存字典中。缓存是一个LRUCache,极少数情况下,映射程序接收的数据量非常大,不同的列模式为UPDATE。

SQL ¶ T0>

  • [sql] expr.in_() now accepts a text() construct as the argument. 分组圆括号是自动添加的,即用法如col.in_(text(“select id from table”))


  • [sql] Columns of _Binary type (i.e. LargeBinary, BLOB, etc.) 将右侧的“basestring”强制转换为_Binary,以便进行所需的DBAPI处理。

  • [sql] Added table.add_is_dependent_on(othertable), allows manual placement of dependency rules between two Table objects for use within create_all(), drop_all(), sorted_tables.


  • [sql] Fixed bug that prevented implicit RETURNING from functioning properly with composite primary key that contained zeroes.


  • [sql] Fixed errant space character when generating ADD CONSTRAINT for a named UNIQUE constraint.

  • [sql] Fixed “table” argument on constructor of ForeginKeyConstraint


  • [sql] Fixed bug in connection pool cursor wrapper whereby if a cursor threw an exception on close(), the logging of the message would fail.


  • [sql] the _make_proxy() method of ColumnClause and Column now use self.__class__ to determine the class of object to be returned instead of hardcoding to ColumnClause/Column, making it slightly easier to produce specific subclasses of these which work in alias/subquery situations.

  • [sql] func.XXX() doesn’t inadvertently resolve to non-Function classes (e.g. fixes func.text()).


MySQL的¶ T0>

  • [mysql] func.sysdate() emits “SYSDATE()”, i.e. with the ending parenthesis, on MySQL.


源码¶ T0>

  • [sqlite] 修正了由于SQLite AUTOINCREMENT关键字被渲染而导致“PRIMARY KEY”约束移动到列级别时,约束的约束串联


预言¶ T0>

  • [oracle] 添加了对版本5以下的cx_oracle版本的检查,在这种情况下不会使用不兼容的“输出类型处理程序”。这将影响十进制精度和一些unicode处理问题。


  • [oracle] Fixed use_ansi=False mode, which was producing broken WHERE clauses in pretty much all cases.


  • [oracle] Re-established support for Oracle 8 with cx_oracle, including that use_ansi is set to False automatically, NVARCHAR2 and NCLOB are not rendered for Unicode, “native unicode” check doesn’t fail, cx_oracle “native unicode” mode is disabled, VARCHAR() is emitted with bytes count instead of char count.


  • [oracle] oracle_xe 5 doesn’t accept a Python unicode object in its connect string in normal Python 2.x mode - so we coerce to str() directly. 在这里连接字符串不支持非ascii字符,因为我们不知道可以使用什么编码。


  • [oracle] FOR UPDATE is emitted in the syntactically correct position when limit/offset is used, i.e. the ROWNUM subquery. 但是,Oracle不能真正使用ORDER BY或子查询来处理FOR UPDATE,因此它仍然不是很好用,但至少SQLA能够通过Oracle解析器获取SQL。


火鸟¶ T0>

  • [firebird] Added a label to the query used within has_table() and has_sequence() to work with older versions of Firebird that don’t provide labels for result columns.


  • [firebird] 当通过查询字符串传递时,为“type_conv”属性添加整数强制,以便由Kinterbasdb正确解释。


  • [firebird] 在连接断开的异常字符串列表中添加了“连接关闭”。


杂项¶ T0>

  • [engines] 修正了Python 2.4中的C扩展。


  • [engines] 在发生dispose()后,池类将重新使用相同的“pool_logging_name”设置。

  • [engines] Engine gains an “execution_options” argument and update_execution_options() method, which will apply to all connections generated by this engine.

  • [sqlsoup] the SqlSoup constructor accepts a base argument which specifies the base class to use for mapped classes, the default being object.


0.6.0 ¶ T0>


ORM ¶ T0>

  • [orm] 工作单元内部已被重写。由于不再依赖于递归调用,现在可以刷新大量对象相互依赖对象的工作单元而不会发生递归溢出。现在,内部结构的数量对于特定的会话状态保持不变,而不管映射上有多少关系。事件流现在对应于由映射器和基于实际工作而产生的关系生成的线性步骤列表,通过单个拓扑排序进行正确排序的筛选。刷新操作使用更少的步骤和更少的内存来组装。


  • [orm] Along with the UOW rewrite, this also removes an issue introduced in 0.6beta3 regarding topological cycle detection for units of work with long dependency cycles. 我们现在使用Guido编写的算法(感谢Guido!)。¶ T0>

  • [orm] one-to-many relationships now maintain a list of positive parent-child associations within the flush, preventing previous parents marked as deleted from cascading a delete or NULL foreign key set on those child objects, despite the end-user not removing the child from the old association.


  • [orm] 一个集合的延迟加载会关闭多对一反向的默认预先加载,因为这个加载在定义上是不必要的。


  • [orm] Session.refresh() now does an equivalent expire() on the given instance first, so that the “refresh-expire” cascade is propagated. 以前,refresh()不受“refresh-expire”级联的影响。这是0.6beta2行为的变化,其中传递给refresh()的“lockmode”标志会导致版本检查的发生。由于实例首先过期,因此refresh()总是将对象升级到最新版本。

  • [orm] The ‘refresh-expire’ cascade, when reaching a pending object, will expunge the object if the cascade also includes “delete-orphan”, or will simply detach it otherwise.


  • [orm] id(obj) is no longer used internally within topological.py, as the sorting functions now require hashable objects only.


  • [orm] The ORM will set the docstring of all generated descriptors to None by default. 这可以使用'doc'来覆盖(或者如果使用Sphinx,属性docstrings也可以)

  • [orm] 将kw参数'doc'添加到所有mapper属性可调参数以及Column()。将字符串'doc'组装为描述符上的'__doc__'属性。

  • [orm] Usage of version_id_col on a backend that supports cursor.rowcount for execute() but not executemany() now works when a delete is issued (already worked for saves, since those don’t use executemany()). 对于根本不支持cursor.rowcount的后端,发出的警告与save相同。


  • [orm] The ORM now short-term caches the “compiled” form of insert() and update() constructs when flushing lists of objects of all the same class, thereby avoiding redundant compilation per individual INSERT/UPDATE within an individual flush() call.

  • [orm] internal getattr(), setattr(), getcommitted() methods on ColumnProperty, CompositeProperty, RelationshipProperty have been underscored (i.e. are private), signature has changed.

SQL ¶ T0>

  • [sql] Restored some bind-labeling logic from 0.5 which ensures that tables with column names that overlap another column of the form “_” won’t produce errors if column._label is used as a bind name during an UPDATE. 添加了0.5中不存在的测试覆盖率。


  • [sql] somejoin.select(fold_equivalents=True) is no longer deprecated, and will eventually be rolled into a more comprehensive version of the feature for.


  • [sql] the Numeric type raises an enormous warning when expected to convert floats to Decimal from a DBAPI that returns floats. 这包括SQLite,Sybase,MS-SQL。


  • [sql] Fixed an error in expression typing which caused an endless loop for expressions with two NULL types.

  • [sql] Fixed bug in execution_options() feature whereby the existing Transaction and other state information from the parent connection would not be propagated to the sub-connection.

  • [sql] 添加了新的“compiled_cache”执行选项。当连接将子句表达式编译为方言和参数特定的编译对象时,Compiled对象将被缓存的字典。用户有责任管理该字典的大小,该字典将具有与方言,子句元素,INSERT或UPDATE的VALUES或SET子句中的列名相对应的键,以及用于INSERT或UPDATE语句。

  • [sql] 将get_pk_constraint()添加到reflection.Inspector,类似于get_primary_keys(),除了返回一个包含约束名称的dict,用于受支持的后端(PG迄今)。/ T2>


  • [sql] Table.create() and Table.drop() no longer apply metadata- level create/drop events.


的PostgreSQL ¶ T0>

  • [postgresql] Postgresql now reflects sequence names associated with SERIAL columns correctly, after the name of the sequence has been changed. 感谢Kumar McMillan提供的补丁。


  • [postgresql] 修复了psycopg2.pGNumeric类型时收到未知数​​字时丢失的导入

  • [postgresql] psycopg2/pg8000 dialects now aware of REAL[], FLOAT[], DOUBLE_PRECISION[], NUMERIC[] return types without raising an exception.

  • [postgresql] Postgresql reflects the name of primary key constraints, if one exists.


预言¶ T0>

  • [oracle] Now using cx_oracle output converters so that the DBAPI returns natively the kinds of values we prefer:

  • [oracle] NUMBER values with positive precision + scale convert to cx_oracle.STRING and then to Decimal. 当使用cx_oracle时,这允许数值类型的完美精度。


  • [oracle] 现在STRING / FIXED_CHAR本地转换为unicode。SQLAlchemy的String类型不需要进行任何类型的转换。

火鸟¶ T0>

  • [firebird] The functionality of result.rowcount can be disabled on a per-engine basis by setting ‘enable_rowcount=False’ on create_engine(). 通常情况下,无条件地在任何UPDATE或DELETE语句之后调用cursor.rowcount,因为游标然后关闭,Firebird需要打开游标才能获得行数。这个电话稍微昂贵,所以它可以被禁用。要在每次执行的基础上重新启用,可以使用“enable_rowcount = True”执行选项。

杂项¶ T0>

  • [engines] The C extension now also works with DBAPIs which use custom sequences as row (and not only tuples).


  • [ext] the compiler extension now allows @compiles decorators on base classes that extend to child classes, @compiles decorators on child classes that aren’t broken by a @compiles decorator on the base class.

  • [ext] Declarative will raise an informative error message if a non-mapped class attribute is referenced in the string-based relationship() arguments.

  • [ext] Further reworked the “mixin” logic in declarative to additionally allow __mapper_args__ as a @classproperty on a mixin, such as to dynamically assign polymorphic_identity.

  • [examples] 更新了attribute_shard.py示例,以便使用更强大的方法来搜索Query,以查找将列与文本值进行比较的二进制表达式。

0.6beta3 ¶ T0>


ORM ¶ T0>

  • [orm] Major feature: Added new “subquery” loading capability to relationship(). 这是一个热切的加载选项,它为查询中表示的每个集合生成第二个SELECT,同时为所有父母生成一个SELECT。查询重新发布包装在子查询中的原始最终用户查询,将连接应用到目标集合,并将所有这些集合完全加载到一个结果中,类似于“已加入”的加载,但使用所有内部连接,多次获取完整的父行(因为大多数DBAPI似乎是这样做的,即使列被跳过)。子查询加载可在mapper配置级别使用“lazy ='subquery'”,在查询选项级别使用“subqueryload(props ..)”,“subqueryload_all(props ...)”。


  • [orm] To accommodate the fact that there are now two kinds of eager loading available, the new names for eagerload() and eagerload_all() are joinedload() and joinedload_all(). 在可预见的将来,旧名称仍然是同义词。

  • [orm] The “lazy” flag on the relationship() function now accepts a string argument for all kinds of loading: “select”, “joined”, “subquery”, “noload” and “dynamic”, where the default is now “select”. True / False / None的旧值仍然保留其通常的含义,并且在可预见的未来仍然是同义词。

  • [orm] 添加with_hint()方法到Query()构造。这直接调用select()。with_hint(),也接受实体以及表和别名。请参阅下面的SQL部分中的with_hint()。


  • [orm] Fixed bug in Query whereby calling q.join(prop).from_self(...). join(prop)将无法在加入与内部相同的条件时在子查询之外呈现第二个连接。

  • [orm] Fixed bug in Query whereby the usage of aliased() constructs would fail if the underlying table (but not the actual alias) were referenced inside the subquery generated by q.from_self() or q.select_from().

  • [orm] Fixed bug which affected all eagerload() and similar options such that “remote” eager loads, i.e. eagerloads off of a lazy load such as query(A).options(eagerload(A.b, B.c)) wouldn’t eagerload anything, but using eagerload(“b.c”) would work fine.

  • [orm] Query gains an add_columns(*columns) method which is a multi- version of add_column(col). add_column(col)将来会被废弃。

  • [orm] Query.join() will detect if the end result will be “FROM A JOIN A”, and will raise an error if so.

  • [orm] Query.join(Cls.propname, from_joinpoint=True) will check more carefully that “Cls” is compatible with the current joinpoint, and act the same way as Query.join(“propname”, from_joinpoint=True) in that regard.

SQL ¶ T0>

  • [sql] 添加with_hint()方法来选择()构造。指定表/别名,提示文本和可选的方言名称,“提示”将在语句的适当位置呈现。适用于Oracle,Sybase,MySQL。


  • [sql] Fixed bug introduced in 0.6beta2 where column labels would render inside of column expressions already assigned a label.


的PostgreSQL ¶ T0>

  • [postgresql] psycopg2方言将通过“sqlalchemy.dialects.postgresql”记录器名称记录NOTICE消息


  • [postgresql] the TIME and TIMESTAMP types are now available from the postgresql dialect directly, which add the PG-specific argument ‘precision’ to both. TIME和TIMEZONE类型的“精度”和“时区”正确反映。


MySQL的¶ T0>

  • [mysql] 不要再猜测TINYINT(1)在反射时应该是BOOLEAN - 返回TINYINT(1)。在表定义中使用布尔值/布尔值来获得布尔转换行为。


预言¶ T0>

  • [oracle] The Oracle dialect will issue VARCHAR type definitions using character counts, i.e. VARCHAR2(50 CHAR), so that the column is sized in terms of characters and not bytes. 字符类型的列反射也将使用ALL_TAB_COLUMNS.CHAR_LENGTH而不是ALL_TAB_COLUMNS.DATA_LENGTH。当服务器版本为9或更高版本时,这两种行为都会生效 - 对于版本8,使用旧的行为。


杂项¶ T0>

  • [declarative] Using a mixin won’t break if the mixin implements an unpredictable __getattribute__(), i.e. Zope interfaces.


  • [declarative] 在mixins上使用@classdecorator和类似来定义__tablename__,__table_args__等现在可以工作,如果方法引用最终子类的属性。


  • [declarative] relationships and columns with foreign keys aren’t allowed on declarative mixins, sorry.


  • [ext] sqlalchemy.orm.shard模块现在成为扩展名sqlalchemy.ext.horizo​​ntal_shard。旧的导入使用了一个弃用警告。

0.6beta2 ¶ T0>


ORM ¶ T0>

  • [orm] The official name for the relation() function is now relationship(), to eliminate confusion over the relational algebra term. relation()将在可预见的未来保持相同的状态。


  • [orm] 为Mapper增加了“version_id_generator”参数,这是一个可调用的参数,在“version_id_col”当前值的情况下返回下一个版本号。可用于替代版本控制方案,如uuid,时间戳。


  • [orm] added “lockmode” kw argument to Session.refresh(), will pass through the string value to Query the same as in with_lockmode(), will also do version check for a version_id_col-enabled mapping.

  • [orm] Fixed bug whereby calling query(A).join(A.bs).add_entity(B) in a joined inheritance scenario would double-add B as a target and produce an invalid query.


  • [orm] Fixed bug in session.rollback() which involved not removing formerly “pending” objects from the session before re-integrating “deleted” objects, typically occurred with natural primary keys. 如果它们之间存在主键冲突,则删除的附件将在内部失败。以前的“挂起”对象现在先被清除。


  • [orm] 删除了很多没有人关心的日志记录,日志记录中的日志记录会响应日志级别的实时更改。没有明显的额外开销。


  • [orm] Fixed bug in session.merge() which prevented dict-like collections from merging.

  • [orm] session.merge() works with relations that specifically don’t include “merge” in their cascade options - the target is ignored completely.

  • [orm] session.merge() will not expire existing scalar attributes on an existing target if the target has a value for that attribute, even if the incoming merged doesn’t have a value for the attribute. 这可以防止对现有项目不必要的加载如果目的地没有attr,那么仍然会将attr标记为已到期,但是会履行一些延期cols的合同。


  • [orm] The “allow_null_pks” flag is now called “allow_partial_pks”, defaults to True, acts like it did in 0.5 again. 除此之外,它也在merge()中实现,这样,如果标志为False,则不会为具有部分NULL主键的传入实例发出SELECT。


  • [orm] Fixed bug in 0.6-reworked “many-to-one” optimizations such that a many-to-one that is against a non-primary key column on the remote table (i.e. foreign key against a UNIQUE column) will pull the “old” value in from the database during a change, since if it’s in the session we will need it for proper history/backref accounting, and we can’t pull from the local identity map on a non-primary key column.


  • [orm] fixed internal error which would occur if calling has() or similar complex expression on a single-table inheritance relation().


  • [orm] query.one() no longer applies LIMIT to the query, this to ensure that it fully counts all object identities present in the result, even in the case where joins may conceal multiple identities for two or more rows. 作为奖励,现在也可以用发出from_statement()的查询来调用one(),因为它不再修改查询。


  • [orm] query.get() now returns None if queried for an identifier that is present in the identity map with a different class than the one requested, i.e. when using polymorphic loading.


  • [orm] A major fix in query.join(), when the “on” clause is an attribute of an aliased() construct, but there is already an existing join made out to a compatible target, query properly joins to the right aliased() construct instead of sticking onto the right side of the existing join.


  • [orm] Slight improvement to the fix for to not issue needless updates of the primary key column during a so-called “row switch” operation, i.e. add + delete of two objects with the same PK.


  • [orm] 当属性加载或刷新操作由于对象与任何会话分离而失败时,现在使用sqlalchemy.orm.exc.DetachedInstanceError。UnboundExecutionError特定于绑定到会话和语句的引擎。

  • [orm] Query called in the context of an expression will render disambiguating labels in all cases. 请注意,这不适用于现有的.statement和.subquery()访问器/方法,它仍然遵循缺省为False的.with_labels()设置。

  • [orm] Query.union() retains disambiguating labels within the returned statement, thus avoiding various SQL composition errors which can result from column name conflicts.


  • [orm] Fixed bug in attribute history that inadvertently invoked __eq__ on mapped instances.

  • [orm] Some internal streamlining of object loading grants a small speedup for large results, estimates are around 10-15%. 给“状态”内部一个很好的清理,复杂性较低,数据库成员,方法调用,空白字典创建。

  • [orm] query.delete()的说明文件


  • [orm] Fixed cascade bug in many-to-one relation() when attribute was set to None, introduced in r6711 (cascade deleted items into session during add()).

  • [orm] Calling query.order_by() or query.distinct() before calling query.select_from(), query.with_polymorphic(), or query.from_statement() raises an exception now instead of silently dropping those criterion.


  • [orm] query.scalar() now raises an exception if more than one row is returned. 所有其他行为保持不变。


  • [orm] Fixed bug which caused “row switch” logic, that is an INSERT and DELETE replaced by an UPDATE, to fail when version_id_col was in use.


SQL ¶ T0>

  • [sql] join() will now simulate a NATURAL JOIN by default. 意思是,如果左边是一个连接,它将尝试将右边连接到左边的最右边,如果连接成功,即使有更多连接目标,也不会引发任何有关模糊连接条件的异常。左侧。¶ T0>


  • [sql] The most common result processors conversion function were moved to the new “processors” module. 鼓励方言作者在符合他们的需求时使用这些函数,而不是实现自定义函数。

  • [sql] SchemaType and subclasses Boolean, Enum are now serializable, including their ddl listener and other event callables.


  • [sql] Some platforms will now interpret certain literal values as non-bind parameters, rendered literally into the SQL statement. 这是为了支持由包括MS-SQL和Sybase在内的一些平台强制执行的严格的SQL-92规则。在这个模型中,绑定参数在SELECT的columns子句中是不允许的,也不是某些不明确的表达式,如“?=?”。启用此模式后,基本编译器将以线内字面值呈现绑定,但仅跨字符串和数字值显示。其他类型如日期会引发错误,除非方言子类为这些定义了文字渲染函数。bind参数必须已经有嵌入的文字值,否则会引发错误(即不能用直接bindparam('x'))。方言还可以扩展不接受绑定的区域,比如在函数的参数列表中(当使用本机SQL绑定时,它们不能在MS-SQL上工作)。

  • [sql] 将“unicode_errors”参数添加到String,Unicode等行为就像标准库的string.decode()函数的'errors'关键字参数。这个标志要求convert_unicode设置为“force” - 否则,SQLAlchemy不保证处理unicode转换的任务。请注意,此标志为已经返回unicode对象的后端(大多数DBAPI所做的)的行取回操作增加了显着的性能开销。这个标志只能作为绝对最后的手段,用于从具有不同或损坏的编码的列读取字符串,这只适用于首先接受无效编码的数据库(即MySQL)。不是 PG,Sqlite等)

  • [sql] 增加了数学否定运算符支持,-x。

  • [sql] FunctionElement subclasses are now directly executable the same way any func.foo() construct is, with automatic SELECT being applied when passed to execute().

  • [sql] The “type” and “bind” keyword arguments of a func.foo() construct are now local to “func.” constructs and are not part of the FunctionElement base class, allowing a “type” to be handled in a custom constructor or class-level variable.

  • [sql] 恢复了ResultProxy的keys()方法。

  • [sql] The type/expression system now does a more complete job of determining the return type from an expression as well as the adaptation of the Python operator into a SQL operator, based on the full left/right/operator of the given expression. 特别是为Postgresql EXTRACT创建的日期/时间/间隔系统现在已经被扩展到类型系统中。以前经常发生的“列+文字”表达式迫使“文字”类型与“列”类型相同的行为现在通常不会发生 - “文字”的类型首先从Python类型派生假定标准的本地Python类型+日期类型,然后回落到表达式另一侧的已知类型。如果“后备”类型是兼容的(即来自字符串的CHAR),那么字面将使用该类型。TypeDecorator类型在默认情况下覆盖这个,强制无条件地强制“literal”,这可以通过实现coerce_compared_value()方法来改变。也是。的一部分


  • [sql] Made sqlalchemy.sql.expressions.Executable part of public API, used for any expression construct that can be sent to execute(). FunctionElement现在继承可执行文件,以便获得execution_options(),这些文件也传播给execute()中生成的select()。依次可执行的子类_Generative,它标记支持@_generative修饰器的任何ClauseElement - 为了编译器扩展的好处,这些也可能变成“public”。

  • [sql] A change to the solution for - an end-user defined bind parameter name that directly conflicts with a column-named bind generated directly from the SET or VALUES clause of an update/insert generates a compile error. 这减少了调用计数,并消除了一些不良名称冲突仍然可能发生的情况。


  • [sql] Column() requires a type if it has no foreign keys (this is not new). 现在,如果Column()没有类型,也没有外键,就会出现错误。


  • [sql] the “scale” argument of the Numeric() type is honored when coercing a returned floating point value into a string on its way to Decimal - this allows accuracy to function on SQLite, MySQL.


  • [sql] the copy() method of Column now copies over uninitialized “on table attach” events. 帮助新的声明式“mixin”功能。

MySQL的¶ T0>

  • [mysql] 修正了COLLATE存在的反射错误,可空标志和服务器的默认值不会被反映出来


  • [mysql] Fixed reflection of TINYINT(1) “boolean” columns defined with integer flags like UNSIGNED.

  • [mysql] 进一步修复mysql连接器方言


  • [mysql] Composite PK table on InnoDB where the “autoincrement” column isn’t first will emit an explicit “KEY” phrase within CREATE TABLE thereby avoiding errors.


  • [mysql] 增加了对各种MySQL关键字的反射/创建表支持


  • [mysql] Fixed import error which could occur reflecting tables on a Windows host


源码¶ T0>

  • [sqlite] 将“native_datetime = True”标志添加到create_engine()。这将导致DATE和TIMESTAMP类型跳过所有的绑定参数和结果行处理,假设在连接上启用了PARSE_DECLTYPES。请注意,这与“func.current_date()”不完全兼容,它将作为字符串返回。



  • [mssql] 重新建立对pymssql方言的支持

  • [mssql] 隐式返回,反射等的各种修复 - MS-SQL方言在0.6中还不完整(但是很接近)

  • [mssql] 增加了对mxODBC的基本支持。


  • [mssql] 删除了text_as_varchar选项

预言¶ T0>

  • [oracle] “out”参数需要cx_oracle支持的类型。如果找不到cx_oracle类型,则会产生错误。

  • [oracle] Oracle ‘DATE’ now does not perform any result processing, as the DATE type in Oracle stores full date+time objects, that’s what you’ll get. 请注意,泛型类型.Date类型在传入的值上仍然调用value.date()。当反映一个表时,反射类型将是'DATE'。

  • [oracle] 增加了对Oracle的WITH_UNICODE模式的初步支持。至少,这为Python 3创建了对cx_Oracle的初始支持。在Python 2.xx中使用WITH_UNICODE模式时,会发出一个大而令人恐惧的警告,要求用户认真考虑使用这种困难的操作模式。


  • [oracle] The except_() method now renders as MINUS on Oracle, which is more or less equivalent on that platform.


  • [oracle] 添加了对TIMESTAMP WITH TIME ZONE(即TIMESTAMP(timezone = True))进行渲染和反映的支持。


  • [oracle] Oracle INTERVAL type can now be reflected.

杂项¶ T0>

  • [py3k] 改进了关于Python 3的安装/测试设置,现在Distribute运行在Py3k上。distribute_setup.py现在包括在内。请参阅README.py3k for Python 3安装/测试说明。

  • [engines] Added an optional C extension to speed up the sql layer by reimplementing RowProxy and the most common result processors. 实际的加速将很大程度上取决于您的DBAPI以及您的表中使用的数据类型的组合,并且可以从30%改善到200%以上。它也为大型查询的ORM速度提供了适度(〜15-20%)的间接改进。请注意,默认情况下,不是内置/安装的。有关安装说明,请参阅自述文件。

  • [engines] the execution sequence pulls all rowcount/last inserted ID info from the cursor before commit() is called on the DBAPI connection in an “autocommit” scenario. 这有助于mxodbc与rowcount,可能是一个好主意。

  • [engines] 打开日志记录,以便更频繁地调用isEnabledFor(),以便在下次连接时更改引擎/池的日志级别。这增加了少量的方法调用开销。在调用create_engine()之后,只需要进行日志记录时,这种情况可以忽略不计,并且可以使所有这些情况变得更容易。


  • [engines] 不推荐使用assert_unicode标志。SQLAlchemy将在所有要求对非Unicode Unicode字符串进行编码的情况下以及Unicode或UnicodeType类型显式传递字符串时发出警告。对于已经接受Python unicode对象的DBAPI,String类型将不起任何作用。

  • [engines] Bind parameters are sent as a tuple instead of a list. 一些后端驱动程序不会接受绑定参数作为列表。

  • [engines] threadlocal engine wasn’t properly closing the connection upon close() - fixed that.

  • [engines] Transaction object doesn’t rollback or commit if it isn’t “active”, allows more accurate nesting of begin/rollback/commit.

  • [engines] Python unicode objects as binds result in the Unicode type, not string, thus eliminating a certain class of unicode errors on drivers that don’t support unicode binds.

  • [engines] Added “logging_name” argument to create_engine(), Pool() constructor as well as “pool_logging_name” argument to create_engine() which filters down to that of Pool. 在记录消息的“名称”字段中发出给定的字符串名称,而不是缺省的十六进制标识符字符串。


  • [engines] Dialect的visit_pool()方法被删除,并被on_connect()取代。这个方法返回一个可调用的对象,在每个对象被创建后都会收到原始的DBAPI连接。如果非无,则可调用组件通过连接策略组装成first_connect / connect pool侦听器。为方言提供更简单的界面。

  • [engines] StaticPool现在可以初始化,配置和重新创建,而无需打开新的连接 - 连接仅在第一次请求时打开。dispose()现在也可以在AssertionPool上运行。


  • [ticket: 1673] [metadata] Added the ability to strip schema information when using “tometadata” by passing “schema=None” as an argument. 如果没有指定schema,那么表的模式被保留。

  • [declarative] DeclarativeMeta exclusively uses cls.__dict__ (not dict_) as the source of class information; _as_declarative exclusively uses the dict_ passed to it as the source of class information (which when using DeclarativeMeta is cls.__dict__). 这在理论上应该使定制元类更容易修改传入_as_declarative的状态。

  • [declarative] declarative now accepts mixin classes directly, as a means to provide common functional and column-based elements on all subclasses, as well as a means to propagate a fixed set of __table_args__ or __mapper_args__ to subclasses. 对于__table_args __ / __ mapper_args__从继承的mixin到本地的自定义组合,现在可以使用描述符。声明文档中提供了新的细节。感谢Chris Withers为此付出了努力。


  • [declarative] the __mapper_args__ dict is copied when propagating to a subclass, and is taken straight off the class __dict__ to avoid any propagation from the parent. 映射器继承已经从父映射器传播你想要的东西。


  • [declarative] 当一个单表子类指定一个已经存在于基类中的列时,会引发一个异常


  • [sybase] Implemented a preliminary working dialect for Sybase, with sub-implementations for Python-Sybase as well as Pyodbc. 处理表格创建/下降和基本往返功能。还没有包含unicode /特殊表达式/ etc等的反映或全面支持

  • [examples] 改变了烧杯缓存的例子有一个单独的RelationCache选项用于lazyload缓存。这个对象通过将几个分组到一个共同的结构中来更有效地查找任何数量的潜在属性。FromCache和RelationCache都比较简单。

  • [documentation] Major cleanup work in the docs to link class, function, and method names into the API docs.


0.6beta1 ¶ T0>


ORM ¶ T0>

  • [orm]

    • query.update()的'expire'选项已被重命名为'fetch',因此与query.delete()的匹配。“过期”已被弃用,并发出警告。
    • 对于同步策略,query.update()和query.delete()都默认为“评估”。
    • update()和delete()的“同步”策略在失败时引发错误。没有隐含的回退到“取”。评估失败是基于标准的结构,所以成功/失败是基于代码结构的确定性。

  • [orm]

    • 现在多对一的关系在更少的情况下触发延迟加载,在大多数情况下,当新的代码被替换时,不会获取“旧”的值。
    • 现在,对于一个简单的加载(称为“use_get”条件),即Related-> Sub(Base),使用get()方法的多对一关系无需重新定义primaryjoin条件的基表。
    • 使用声明列指定外键,即ForeignKey(MyRelatedClass.id)不会中断发生的“use_get”条件
    • relation(),eagerload()和eagerload_all()现在具有一个名为“innerjoin”的选项。指定TrueFalse来控制eager连接是否构造为INNER或OUTER连接。默认是一如既往的False映射器选项将覆盖关系()中指定的任何设置。通常应该设置为多对一,而不是可空的外键关系,以提高连接性能。
    • 当所有正在进行的加载是多对一的联接时,当LIMIT / OFFSET出现时,预加载的行为使得主查询被包装在一个子查询中成为一个例外。在这种情况下,由于多对一连接不会将行添加到结果中,所以急切连接与限制/偏移量直接对抗父表,而没有额外的子查询开销。

    References: #1186, #1492, #1544

  • [orm] Session.merge()的增强/改变:

  • [orm] the “dont_load=True” flag on Session.merge() is deprecated and is now “load=False”.

  • [orm] Session.merge() is performance optimized, using half the call counts for “load=False” mode compared to 0.5 and significantly fewer SQL queries in the case of collections for “load=True” mode.

  • [orm] merge() will not issue a needless merge of attributes if the given instance is the same instance which is already present.

  • [orm] merge() now also merges the “options” associated with a given state, i.e. those passed through query.options() which follow along with an instance, such as options to eagerly- or lazyily- load various attributes. 这对于构建高度集成的缓存方案是必不可少的。这是一个微妙的行为变化与0.5.

  • [orm] A bug was fixed regarding the serialization of the “loader path” present on an instance’s state, which is also necessary when combining the usage of merge() with serialized state and associated options that should be preserved.

  • [orm] The all new merge() is showcased in a new comprehensive example of how to integrate Beaker with SQLAlchemy. 请参阅下面“示例”注释中的注释。

  • [orm] Primary key values can now be changed on a joined-table inheritance object, and ON UPDATE CASCADE will be taken into account when the flush happens. 在使用SQLite或MySQL / MyISAM时,在mapper()上将新的“passive_updates”标志设置为False


  • [orm] flush() now detects when a primary key column was updated by an ON UPDATE CASCADE operation from another primary key, and can then locate the row for a subsequent UPDATE on the new PK value. 发生这种情况时,关系()是建立关系以及passive_updates = True。


  • [orm] the “save-update” cascade will now cascade the pending removed values from a scalar or collection attribute into the new session during an add() operation. 这样flush()操作也会删除或修改这些断开项目的行。

  • [orm] Using a “dynamic” loader with a “secondary” table now produces a query where the “secondary” table is not aliased. 这允许辅助表格对象在关系()的“order_by”属性中使用,并允许它用于动态关系的过滤条件。


  • [orm] relation() with uselist=False will emit a warning when an eager or lazy load locates more than one valid value for the row. 这可能是由于初次加入/二次加入条件,这是不适合渴望的左外联合或其他条件。


  • [orm] an explicit check occurs when a synonym() is used with map_column=True, when a ColumnProperty (deferred or otherwise) exists separately in the properties dictionary sent to mapper with the same keyname. 而不是默默地替换现有的属性(以及该属性的可能选项),会引发错误。


  • [orm] a “dynamic” loader sets up its query criterion at construction time so that the actual query is returned from non-cloning accessors like “statement”.

  • [orm] 当迭代一个Query()时返回的“named tuple”对象现在可以被pickleable

  • [orm] mapping to a select() construct now requires that you make an alias() out of it distinctly. 这样可以消除对等问题的混淆


  • [orm] query.join() has been reworked to provide more consistent behavior and more flexibility (includes)


  • [orm] query.select_from() accepts multiple clauses to produce multiple comma separated entries within the FROM clause. 从多宿主连接()子句中选择时很有用。

  • [orm] query.select_from() also accepts mapped classes, aliased() constructs, and mappers as arguments. 特别是当从多个连接表类查询时,这有助于确保完整的连接被呈现。

  • [orm] query.get() can be used with a mapping to an outer join where one or more of the primary key values are None.


  • [orm] query.from_self(), query.union(), others which do a “SELECT * from (SELECT...)” type of nesting will do a better job translating column expressions within the subquery to the columns clause of the outer query. 这可能是与0.5不兼容的,因为这可能会破坏没有应用标签的文字表达式(即literal('foo')等)。


  • [orm] relation primaryjoin and secondaryjoin now check that they are column-expressions, not just clause elements. 这就禁止像FROM表达式那样直接放在那里。


  • [orm] expression.null() is fully understood the same way None is when comparing an object/collection-referencing attribute within query.filter(), filter_by(), etc.


  • [orm] 添加了“make_transient()”辅助函数,它将持久/分离的实例转换为临时实例(即删除instance_key并从任何会话中删除)。


  • [orm] 映​​射器()上的allow_null_pks标志已被弃用,默认情况下该功能变为“开启”。这意味着对于任何主键列都有一个非空值的行将被认为是一个标识。通常只有在映射到外连接时才需要这种情况。


  • [orm] the mechanics of “backref” have been fully merged into the finer grained “back_populates” system, and take place entirely within the _generate_backref() method of RelationProperty. 这使得RelationProperty的初始化过程更简单,并允许设置(比如从RelationProperty的子类)更容易地传播到反向引用。内部的BackRef()消失了,backref()返回一个由RelationProperty所理解的普通元组。

  • [orm] mapper()上的version_id_col特性在与不支持“rowcount”的方言一起使用时会引发警告。


  • [orm] added “execution_options()” to Query, to so options can be passed to the resulting statement. 目前只有Select语句具有这些选项,唯一使用的选项是“stream_results”,唯一知道“stream_results”的语言是psycopg2.

  • [orm] Query.yield_per() will set the “stream_results” statement option automatically.

  • [orm]

    • mapper()上的'allow_null_pks'标志已被弃用。它现在什么都不做,所有情况下都是“开”的。
    • sessionmaker()上的'transactional'标志被删除。使用'autocommit = True'来表示'transactional = False'。
    • mapper()上的'polymorphic_fetch'参数被删除。加载可以使用'with_polymorphic'选项进行控制。
    • mapper()上的“select_table”参数被删除。为此功能使用'with_polymorphic =(“*”,)“。
    • 同义词()的“代理”参数被删除。这个标志在整个0.5中没有做任何事情,因为“代理代”行为现在是自动的。
    • 将单个元素列表传递给eagerload(),eagerload_all(),contains_eager(),lazyload(),defer()和undefer()而不是多个位置*参数已被弃用。
    • 将单个元素列表传递给query.order_by(),query.group_by(),query.join()或query.outerjoin()而不是多个位置*参数已被弃用。
    • query.iterate_instances()被删除。使用query.instances()。
    • Query.query_from_parent()被删除。使用sqlalchemy.orm.with_parent()函数生成一个“父”子句,或者query.with_parent()。
    • query._from_self()被删除,改用query.from_self()。
    • composite()的“comparator”参数被删除。使用“comparator_factory”。
    • RelationProperty._get_join()被删除。
    • Session上的'echo_uow'标志被删除。在“sqlalchemy.orm.unitofwork”名称上使用日志记录。
    • session.clear()被删除。使用session.expunge_all()。
    • session.save(),session.update(),session.save_or_update()被删除。使用session.add()和session.add_all()。
    • session.flush()上的“objects”标志仍然被弃用。
    • session.merge()中的“dont_load = True”标志已弃用,以支持“load = False”。
    • ScopedSession.mapper保持不推荐使用。请参阅http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper中的使用方法
    • 将InstanceState(内部SQLAlchemy状态对象)传递给attributes.init_collection()或attributes.get_history()已弃用。这些函数是公共API,通常需要一个常规的映射对象实例。
    • declarative_base()的'engine'参数被删除。使用“绑定”关键字参数。

SQL ¶ T0>

  • [sql] the “autocommit” flag on select() and text() as well as select().autocommit() are deprecated - now call .execution_options(autocommit=True) on either of those constructs, also available directly on Connection and orm.Query.

  • [sql] the autoincrement flag on column now indicates the column which should be linked to cursor.lastrowid, if that method is used. 有关详细信息,请参阅API文档。

  • [sql] an executemany() now requires that all bound parameter sets require that all keys are present which are present in the first bound parameter set. insert / update语句的结构和行为很大程度上取决于第一个参数集,其中包括哪些缺省值将被触发,并且所有其余缺省值都会执行最少的猜测操作,以便不影响性能。由于这个原因,默认情况下会默认“失败”的参数,所以这是现在防范。


  • [sql] returning() support is native to insert(), update(), delete(). Postgresql,Firebird,MSSQL和Oracle存在不同级别功能的实现。可以使用列表达式显式调用返回(),这些列表达式通常通过fetchone()或first()返回结果集。


  • [sql] union(), intersect(), except() and other “compound” types of statements have more consistent behavior w.r.t. 圆括号。嵌入在另一个元素中的每个复合元素现在都将用括号分组 - 以前,列表中的第一个复合元素不会被分组,因为SQLite不喜欢以括号开头的语句。但是,Postgresql特别是有关于INTERSECT的优先规则,并且对括号同样适用于所有的子元素更为一致。所以现在,SQLite的解决方法也是以前PG的解决方法 - 当嵌套复合元素时,第一个通常需要调用“.alias()。select()”来将其包装在子查询中。¶ T0>


  • [sql] insert() and update() constructs can now embed bindparam() objects using names that match the keys of columns. 这些绑定参数将绕过通常路由到生成的SQL的VALUES或SET子句中显示的那些键。


  • [sql] the Binary type now returns data as a Python string (or a “bytes” type in Python 3), instead of the built- in “buffer” type. 这允许二进制数据的对称往返。


  • [sql] Added a tuple_() construct, allows sets of expressions to be compared to another set, typically with IN against composite primary keys or similar. 也接受一个I​​N多列。“标量选择只能有一列”的错误信息被删除 - 将依靠数据库来报告与col不匹配的问题。

  • [sql] User-defined “default” and “onupdate” callables which accept a context should now call upon “context.current_parameters” to get at the dictionary of bind parameters currently being processed. 这个字典可以用同样的方法得到,不管是单执行还是执行语句执行。

  • [sql] multi-part schema names, i.e. with dots such as “dbo.master”, are now rendered in select() labels with underscores for dots, i.e. “dbo_master_table_column”. 这是一个在结果集中表现更好的“友好”标签。


  • [sql] removed needless “counter” behavior with select() labelnames that match a column name in the table, i.e. generates “tablename_id” for “id”, instead of “tablename_id_1” in an attempt to avoid naming conflicts, when the table has a column actually named “tablename_id” - this is because the labeling logic is always applied to all columns so a naming conflict will never occur.

  • [sql] calling expr.in_([]), i.e. with an empty list, emits a warning before issuing the usual “expr != expr” clause. “expr!= expr”可能非常昂贵,如果列表是空的,用户最好不要发出in_(),而只是不要查询,或者修改适合更复杂情况的标准。/ T0>


  • [sql] Added “execution_options()” to select()/text(), which set the default options for the Connection. 请参阅“引擎”中的注释。

  • [sql]

    • select()上的“标量”标志被移除,使用select.as_scalar()。
    • bindparam()上的“shortname”属性被删除。
    • postgres_returning,insert(),update(),delete()上的firebird_returning标志被弃用,使用新的returns()方法。
    • 加入时的fold_equivalents标志已被弃用(将保持到实施)


架构¶ T0>

  • [schema] the __contains__() method of MetaData now accepts strings or Table objects as arguments. 如果给定,则首先将参数转换为table.key,即“[SCHEMANAME。] ¶ T1> T0>


  • [schema] deprecated MetaData.connect() and ThreadLocalMetaData.connect() have been removed - send the “bind” attribute to bind a metadata.

  • [schema] 不赞成使用metadata.table_iterator()方法(使用sorted_tables)

  • [schema] 不推荐使用PassiveDefault - 使用DefaultClause。

  • [schema] the “metadata” argument is removed from DefaultGenerator and subclasses, but remains locally present on Sequence, which is a standalone construct in DDL.

  • [schema] Removed public mutability from Index and Constraint objects:

    • ForeignKeyConstraint.append_element()
    • Index.append_column()
    • UniqueConstraint.append_column()
    • PrimaryKeyConstraint.add()
    • PrimaryKeyConstraint.remove()


  • [schema] The “start” and “increment” attributes on Sequence now generate “START WITH” and “INCREMENT BY” by default, on Oracle and Postgresql. Firebird现在不支持这些关键字。


  • [schema] UniqueConstraint, Index, PrimaryKeyConstraint all accept lists of column names or column objects as arguments.

  • [schema]

    • Table.key(不知道这是什么)
    • Table.primary_key不可分配 - 使用table.append_constraint(PrimaryKeyConstraint(...))
    • Column.bind(通过column.table.bind获取)
    • Column.metadata(通过column.table.metadata获取)
    • Column.sequence(使用column.default)
    • ForeignKey(约束= some_parent)(现在是私人_constraint)

  • [schema] ForeignKey上的use_alter标志现在是可以使用DDL()事件系统手动构建的操作的快捷选项。A side effect of this refactor is that ForeignKeyConstraint objects with use_alter=True will not be emitted on SQLite, which does not support ALTER for foreign keys.

  • [schema] ForeignKey and ForeignKeyConstraint objects now correctly copy() all their public keyword arguments.


的PostgreSQL ¶ T0>

  • [postgresql] New dialects: pg8000, zxjdbc, and pypostgresql on py3k.

  • [postgresql] The “postgres” dialect is now named “postgresql” ! 连接字符串如下所示:

    postgresql:// scott:tiger @ localhost / test postgresql + pg8000:// scott:tiger @ localhost / test


    • 有一个“postgres.py”虚拟方言,它允许旧的URL工作,即postgres:// scott:tiger @ localhost / test
    • 可以从旧的“数据库”模块导入“postgres”名称,即“从sqlalchemy.databases导入postgres”以及“方言”,“从sqlalchemy.dialects.postgres导入基地为pg”,将发送弃用警告。
    • 特殊表达式参数现在被命名为“postgresql_returning”和“postgresql_where”,但是较旧的“postgres_returning”和“postgres_where”名称仍然适用于弃用警告。

  • [postgresql] “postgresql_where” now accepts SQL expressions which can also include literals, which will be quoted as needed.

  • [postgresql] The psycopg2 dialect now uses psycopg2’s “unicode extension” on all new connections, which allows all String/Text/etc. 类型来跳过需要后处理字节串到unicode(一个昂贵的步骤,由于其体积)。其他本地返回unicode的方言(pg8000,zxjdbc)也会跳过unicode后期处理。

  • [postgresql] 添加了新的ENUM类型,它作为模式级结构存在并扩展了泛型枚举类型。自动将自身与表及其父元数据相关联,以根据需要发出适当的CREATE TYPE / DROP TYPE命令,支持unicode标签,支持反射。


  • [postgresql] INTERVAL支持与PG接受的参数相对应的可选的“precision”参数。

  • [postgresql] 使用新的dialect.initialize()功能设置版本相关的行为。

  • [postgresql] somewhat better support for % signs in table/column names; psycopg2 can’t handle a bind parameter name of %(foobar)s however and SQLA doesn’t want to add overhead just to treat that one non-existent use case.


  • [postgresql] Inserting NULL into a primary key + foreign key column will allow the “not null constraint” error to raise, not an attempt to execute a nonexistent “col_id_seq” sequence.


  • [postgresql] autoincrement SELECT statements, i.e. those which select from a procedure that modifies rows, now work with server-side cursor mode (the named cursor isn’t used for such statements.)

  • [postgresql] postgresql dialect can properly detect pg “devel” version strings, i.e. “8.5devel”


  • [postgresql] psycopg2现在尊重语句选项“stream_results”。该选项将覆盖连接设置“server_side_cursors”。如果为true,则服务器端游标将用于该语句。如果为false,即使连接上的“server_side_cursors”为真,它们也不会被使用。


MySQL的¶ T0>

  • [mysql] New dialects: oursql, a new native dialect, MySQL Connector/Python, a native Python port of MySQLdb, and of course zxjdbc on Jython.

  • [mysql] VARCHAR / NVARCHAR不会在没有长度的情况下渲染,在传递给MySQL之前产生一个错误。不影响CAST,因为无论如何,在MySQL CAST中不允许使用VARCHAR,在这种情况下,方言呈现CHAR / NCHAR。

  • [mysql] all the _detect_XXX() functions now run once underneath dialect.initialize()

  • [mysql] somewhat better support for % signs in table/column names; MySQLdb can’t handle % signs in SQL when executemany() is used, and SQLA doesn’t want to add overhead just to treat that one non-existent use case.


  • [mysql] the BINARY and MSBinary types now generate “BINARY” in all cases. 省略“length”参数将会生成没有长度的“BINARY”。使用BLOB生成一个没有长度的二进制列。

  • [mysql] 不推荐使用MSEnum / ENUM的“quoting ='quoted'”参数。最好依靠自动引用。

  • [mysql] 如果给定的标签名是unicode对象,ENUM现在将子类化为新的泛型类型,并且还隐式处理unicode值。

  • [mysql] 如果“nullable = False”未传递给Column(),并且没有默认值,则TIMESTAMP类型的列现在默认为NULL。这与所有其他类型是一致的,在TIMESTAMP的情况下,由于MySQL对TIMESTAMP列的默认可空性“切换”,显式地呈现“NULL”。


源码¶ T0>

  • [sqlite] DATE, TIME and DATETIME types can now take optional storage_format and regexp argument. 可以使用storage_format来使用自定义字符串格式来存储这些类型。regexp允许使用自定义正则表达式来匹配来自数据库的字符串值。

  • [sqlite] Time and DateTime types now use by a default a stricter regular expression to match strings from the database. 如果使用以旧格式存储的数据,请使用regexp参数。

  • [sqlite] __legacy_microseconds__ on SQLite Time and DateTime types is not supported anymore. 您应该使用storage_format参数。

  • [sqlite] Date, Time and DateTime types are now stricter in what they accept as bind parameters: Date type only accepts date objects (and datetime ones, because they inherit from date), Time only accepts time objects, and DateTime only accepts date and datetime objects.

  • [sqlite] Table() supports a keyword argument “sqlite_autoincrement”, which applies the SQLite keyword “AUTOINCREMENT” to the single integer primary key column when generating DDL. 将防止生成单独的PRIMARY KEY约束。



  • [mssql] MSSQL + Pyodbc + FreeTDS now works for the most part, with possible exceptions regarding binary data as well as unicode schema identifiers.

  • [mssql] “has_window_funcs”标志被删除。LIMIT / OFFSET用法将一直使用ROW NUMBER,如果在较早版本的SQL Server上,则操作失败。行为是完全一样的,除了SQL服务器而不是方言引发错误,并且不需要标志设置来启用它。

  • [mssql] “auto_identity_insert”标志被删除。当INSERT语句覆盖已知有序列的列时,此功能始终生效。和“has_window_funcs”一样,如果底层的驱动程序不支持这个,那么在任何情况下你都不能做这个操作,所以没有标志是没有意义的。

  • [mssql] 使用新的dialect.initialize()功能设置版本相关的行为。

  • [mssql] removed references to sequence which is no longer used. mssql中的隐式标识与任何其他方言中的隐式序列的工作方式相同。显式序列通过使用“default = Sequence()”来启用。有关更多信息,请参阅MSSQL方言文档。

预言¶ T0>

  • [oracle] 单元测试通过cx_oracle 100%!

  • [oracle] 支持cx_Oracle的“native unicode”模式,不需要设置NLS_LANG。使用cx_oracle的最新版本5.0.2或更高版本。

  • [oracle] 将NCLOB类型添加到基类型中。

  • [oracle] use_ansi=False won’t leak into the FROM/WHERE clause of a statement that’s selecting from a subquery that also uses JOIN/OUTERJOIN.

  • [oracle] 在方言中加入了原生的INTERVAL类型。由于在YEAR TO MONTH中缺少cx_oracle支持,所以目前只支持DAY TO SECOND间隔类型。


  • [oracle] usage of the CHAR type results in cx_oracle’s FIXED_CHAR dbapi type being bound to statements.

  • [oracle] the Oracle dialect now features NUMBER which intends to act justlike Oracle’s NUMBER type. 它是表反射返回的主要数值类型,并尝试根据精度/比例参数返回Decimal()/ float / int。


  • [oracle] func.char_length是LENGTH 的一个通用函数

  • [oracle] ForeignKey() which includes onupdate= will emit a warning, not emit ON UPDATE CASCADE which is unsupported by oracle

  • [oracle] the keys() method of RowProxy() now returns the result column names normalized to be SQLAlchemy case insensitive names. 这意味着对于不区分大小写的名称,它们将是小写的,而DBAPI通常将它们作为大写名称返回。这允许行键()与进一步的SQLAlchemy操作兼容。

  • [oracle] 使用新的dialect.initialize()功能设置版本相关的行为。

  • [oracle] using types.BigInteger with Oracle will generate NUMBER(19)


  • 大小写敏感“功能将在反射过程中检测到全小写的区分大小写的列名称,并将”quote = True“添加到生成的列,以便保持正确的引用。[oracle]

火鸟¶ T0>

  • RowProxy()的keys()方法现在返回结果列名称normalized,以便成为SQLAlchemy不区分大小写的名称。[firebird] 这意味着对于不区分大小写的名称,它们将是小写的,而DBAPI通常将它们作为大写名称返回。这允许行键()与进一步的SQLAlchemy操作兼容。

  • [firebird] 使用新的dialect.initialize()功能来设置版本依赖的行为

  • [firebird] “case sensitivity” feature will detect an all-lowercase case-sensitive column name during reflect and add “quote=True” to the generated Column, so that proper quoting is maintained.

杂项¶ T0>

  • [release] [major] 有关整套功能描述,请参阅http://docs.sqlalchemy.org/en/latest/changelog_migration_06.html这个文件是一个正在进行的工作。

  • [release] [major] 最近0.5版本及以下的所有bug修复和功能增强也包含在0.6以内。

  • [release] [major] Platforms targeted now include Python 2.4/2.5/2.6, Python 3.1, Jython2.5.

  • [engines] transaction isolation level may be specified with create_engine(... isolation_level=”...”); available on postgresql and sqlite.


  • [engines] Connection has execution_options(), generative method which accepts keywords that affect how the statement is executed w.r.t. DBAPI。目前支持“stream_results”,导致psycopg2为该语句使用服务器端游标,以及“autocommit”,这是select()和text()中“autocommit”选项的新位置。select()和text()也有.execution_options()以及ORM Query()。

  • [engines] 修复了入口点驱动方言的导入,不依靠愚蠢的tb_info技巧来确定导入错误状态


  • [engines] 将first()方法添加到ResultProxy,返回第一行并立即关闭结果集

  • [engines] RowProxy objects are now pickleable, i.e. the object returned by result.fetchone(), result.fetchall() etc.

  • [engines] RowProxy no longer has a close() method, as the row no longer maintains a reference to the parent. 调用父ResultProxy的close(),或者使用autoclose。

  • [engines] ResultProxy internals have been overhauled to greatly reduce method call counts when fetching columns. 在获取较大的结果集时可以提供很大的速度提升(高达100%以上)。当提取没有应用类型级别处理的列,以及使用结果作为元组(而不是字典)时,这种改进更大。Many thanks to Elixir’s Gaëtan de Menten for this dramatic improvement !


  • [engines] Databases which rely upon postfetch of “last inserted id” to get at a generated sequence value (i.e. MySQL, MS-SQL) now work correctly when there is a composite primary key where the “autoincrement” column is not the first primary key column in the table.

  • [engines] the last_inserted_ids() method has been renamed to the descriptor “inserted_primary_key”.

  • [engines] setting echo=False on create_engine() now sets the loglevel to WARN instead of NOTSET. 这样即使日志记录为“sqlalchemy.engine”,也可以禁用特定引擎的日志记录。请注意,“echo”的默认设置是None


  • [engines] ConnectionProxy now has wrapper methods for all transaction lifecycle events, including begin(), rollback(), commit() begin_nested(), begin_prepared(), prepare(), release_savepoint(), etc.

  • [engines] Connection pool logging now uses both INFO and DEBUG log levels for logging. INFO用于主要事件,例如无效连接,所有获取/返回记录的DEBUG。echo_pool可以像echo一样使用False,None,True或者“debug”。

  • [engines] All pyodbc-dialects now support extra pyodbc-specific kw arguments ‘ansi’, ‘unicode_results’, ‘autocommit’.


  • [engines] “threadlocal”引擎已被重写和简化,现在支持SAVEPOINT操作。

  • [engines]

    • result.last_inserted_ids()已被弃用。使用result.inserted_primary_key
    • dialect.get_default_schema_name(连接)现在是通过dialect.default_schema_name公开的。
    • 从engine.transaction()和engine.run_callable()的“连接”参数被删除 - 连接本身现在有这些方法。所有四种方法都接受传递给给定可调用的* args和** kwargs,以及操作连接。

  • [reflection/inspection] Table reflection has been expanded and generalized into a new API called “sqlalchemy.engine.reflection.Inspector”. Inspector对象提供有关各种模式信息的细粒度信息,包括表名,列名,视图定义,序列,索引等。扩展空间

  • [reflection/inspection] 视图现在可以反映为普通的表格对象。使用相同的表构造函数,注意“有效的”主键和外键约束不是反射结果的一部分;如果需要,必须明确指定。

  • [reflection/inspection] The existing autoload=True system now uses Inspector underneath so that each dialect need only return “raw” data about tables and other objects - Inspector is the single place that information is compiled into Table objects so that consistency is at a maximum.

  • [ddl] the DDL system has been greatly expanded. DDL()类现在扩展了更通用的DDLElement(),它构成了许多新的构造的基础:

    • AddConstraint()
    • DropConstraint()
    • 的CreateIndex()
    • DropIndex()
    • CreateSequence()
    • DropSequence()


  • [ddl] The signature of the “on” callable passed to DDL() and DDLElement() is revised as follows:

    关键字参数。在创建/删除之前/之后的元数据的情况下,将为其发出CREATE / DROP DDL的表对象的列表作为kw参数“表”被传递。这对于依赖于特定表的存在的元数据级DDL是必需的。

  • [dialect] [refactor] Dialect modules are now broken into database dialects plus DBAPI implementations. 现在,连接网址最好使用dialect + driver:// ...,即“mysql + mysqldb:// scott:tiger @ localhost / test”来指定。有关示例,请参阅0.6文档。

  • [dialect] [refactor] 外部方言的setuptools入口现在称为“sqlalchemy.dialects”。

  • [dialect] [refactor] the “owner” keyword argument is removed from Table. 使用“模式”来表示任何名称空间要预先添加到表名称。

  • [dialect] [refactor] server_version_info成为一个静态属性

  • [dialect] [refactor] dialects receive an initialize() event on initial connection to determine connection properties.

  • [dialect] [refactor] dialects receive a visit_pool event have an opportunity to establish pool listeners.

  • [dialect] [refactor] 缓存的TypeEngine类是缓存的每个方言类而不是per-dialect。

  • [dialect] [refactor] new UserDefinedType should be used as a base class for new types, which preserves the 0.5 behavior of get_col_spec().

  • [dialect] [refactor] 所有类型的result_processor()方法现在接受第二个参数“coltype”,它是cursor.description中的DBAPI类型参数。这个参数可以帮助某些类型决定结果值的最有效处理。

  • [dialect] [refactor] 已弃用Dialect.get_params()已被移除。

  • [dialect] [refactor] Dialect.get_rowcount() has been renamed to a descriptor “rowcount”, and calls cursor.rowcount directly. 在某些调用中需要硬连线的方言应该重写提供不同行为的方法。

  • [dialect] [refactor] DefaultRunner和子类已被删除。这个对象的工作已经简化并移入ExecutionContext。支持序列的方言应该在其执行上下文实现中添加一个fire_sequence()方法。


  • [dialect] [refactor] Functions and operators generated by the compiler now use (almost) regular dispatch functions of the form “visit_” and “visit__fn” to provide customed processing. 这代替了在编译器子类中使用简单的访问者方法复制“函数”和“操作符”字典的需要,并且还允许编译器子类完全控制渲染,因为完整的_Function或_BinaryExpression对象被传入。 T0>

  • [types] The construction of types within dialects has been totally overhauled. 方言现在将公共可用类型定义为大写字母名称,而内部实现类型使用下划线标识符(即私人)。用SQL和DDL表示类型的系统已经被移至编译器系统。这样做的结果是大多数方言中的类型对象数量要少得多。关于这种方言作者的体系结构的详细文档在lib / sqlalchemy / dialects_type_migration_guidelines.txt中。

  • [types] 类型不再对默认参数进行猜测。特别是Numeric,Float,NUMERIC,FLOAT,DECIMAL,除非指定,否则不会产生任何长度或比例。

  • [types] types.Binary is renamed to types.LargeBinary, it only produces BLOB, BYTEA, or a similar “long binary” type. 已经添加了新的基本BINARY和VARBINARY类型,以不可知的方式访问这些MySQL / MS-SQL特定类型。


  • [types] String/Text/Unicode types now skip the unicode() check on each result column value if the dialect has detected the DBAPI as returning Python unicode objects natively. 这个检查在第一次连接时发出,使用“SELECT CAST”一些文本“AS VARCHAR(10)”或者等价的,然后检查返回的对象是否是一个Python unicode。这使得native-unicode DBAPI具有巨大的性能提升,包括pysqlite / sqlite3,psycopg2和pg8000.

  • [types] 大多数类型结果处理器已经被检查可能的速度改进。具体而言,以下通用类型已被优化,导致速度的改进:Unicode,PickleType,Interval,TypeDecorator,Binary。此外,以下特定于dbapi的实现已得到改进:Sqlite上的时间,日期和DateTime,Postgresql上的ARRAY,MySQL上的时间,MySQL上的数字(as_decimal = False),MySQL上的python和pypostgresql,cx_oracle上的DateTime以及cx_oracle上的基于LOB的类型¶ T0>

  • [types] Reflection of types now returns the exact UPPERCASE type within types.py, or the UPPERCASE type within the dialect itself if the type is not a standard SQL type. 这意味着反射现在返回关于反射类型的更准确的信息。

  • [types] 添加了一个新的Enum泛型类型。Enum是一个模式感知对象,用于支持需要特定DDL的数据库才能使用枚举或等价的对象;在PG的情况下,它处理CREATE TYPE的细节,并且在没有本地枚举支持的其他数据库上,将通过生成VARCHAR +内联CHECK约束来强制执行枚举。


  • [types] The Interval type includes a “native” flag which controls if native INTERVAL types (postgresql + oracle) are selected if available, or not. 还添加了“day_precision”和“second_precision”参数,这些参数适当地传播到这些本机类型。与。相关


  • [types] The Boolean type, when used on a backend that doesn’t have native boolean support, will generate a CHECK constraint “col IN (0, 1)” along with the int/smallint- based column type. 如果需要,可以通过create_constraint = False关闭。请注意,MySQL没有本地布尔型 CHECK约束支持,所以该功能在该平台上不可用。


  • [types] PickleType now uses == for comparison of values when mutable=True, unless the “comparator” argument with a comparsion function is specified to the type. 如果没有覆盖__eq __()或者没有提供比较函数,那么被腌制的对象将根据标识进行比较(这违背了mutable = True的目的)。

  • [types] Numeric和Float的默认“precision”和“scale”参数已被删除,现在默认为None。除非提供这些值,否则默认情况下,NUMERIC和FLOAT将不带默认值。

  • [types] AbstractType.get_search_list()被移除 - 用于的游戏不再是必需的。

  • [types] 添加了一个通用的BigInteger类型,编译为BIGINT或NUMBER(19)。


  • [types] sqlsoup has been overhauled to explicitly support an 0.5 style session, using autocommit=False, autoflush=True. SQLSoup的默认行为现在需要通常使用commit()和rollback(),它们已被添加到其接口中。explcit Session或scoped_session可以传递给构造函数,允许重写这些参数。

  • [types] sqlsoup db..update() and delete() now call query(cls).update() and delete(), respectively.

  • [types] sqlsoup now has execute() and connection(), which call upon the Session methods of those names, ensuring that the bind is in terms of the SqlSoup object’s bind.

  • [types] sqlsoup objects no longer have the ‘query’ attribute - it’s not needed for sqlsoup’s usage paradigm and it gets in the way of a column that is actually named ‘query’.

  • [types] The signature of the proxy_factory callable passed to association_proxy is now (lazy_collection, creator, value_attr, association_proxy), adding a fourth argument that is the parent AssociationProxy argument. 允许内置集合的可序列化和子类化。


  • [types] association_proxy now has basic comparator methods .any(), .has(), .contains(), ==, !=, thanks to Scott Torborg.