Added some utility functions

This commit is contained in:
Konsta Vesterinen
2013-05-18 09:47:46 +03:00
parent 3839a5b42a
commit 92880f9105
3 changed files with 36 additions and 2 deletions

View File

@@ -4,7 +4,14 @@ Changelog
Here you can see the full list of changes between each SQLAlchemy-Utils release.
0.12.0 (2013-05-08)
0.12.1 (2013-05-18)
^^^^^^^^^^^^^^^^^^^
- Added utility functions remove_property and primary_keys
0.12.0 (2013-05-17)
^^^^^^^^^^^^^^^^^^^
- Added ProxyDict

View File

@@ -24,7 +24,7 @@ class PyTest(Command):
setup(
name='SQLAlchemy-Utils',
version='0.12.0',
version='0.12.1',
url='https://github.com/kvesteri/sqlalchemy-utils',
license='BSD',
author='Konsta Vesterinen',

View File

@@ -174,3 +174,30 @@ def escape_like(string, escape_char='*'):
.replace('%', escape_char + '%')
.replace('_', escape_char + '_')
)
def remove_property(class_, name):
"""
**Experimental function**
Remove property from declarative class
"""
mapper = class_.mapper
table = class_.__table__
columns = class_.mapper.c
column = columns[name]
del columns._data[name]
del mapper.columns[name]
columns._all_cols.remove(column)
mapper._cols_by_table[table].remove(column)
mapper.class_manager.uninstrument_attribute(name)
del mapper._props[name]
def primary_keys(class_):
"""
Returns all primary keys for given declarative class.
"""
for column in class_.__table__.c:
if column.primary_key:
yield column