{"action":"created","issue":{"url":"https://api.github.com/repos/zzzeek/sqlalchemy/issues/235","repository_url":"https://api.github.com/repos/zzzeek/sqlalchemy","labels_url":"https://api.github.com/repos/zzzeek/sqlalchemy/issues/235/labels{/name}","comments_url":"https://api.github.com/repos/zzzeek/sqlalchemy/issues/235/comments","events_url":"https://api.github.com/repos/zzzeek/sqlalchemy/issues/235/events","html_url":"https://github.com/zzzeek/sqlalchemy/pull/235","id":133228407,"number":235,"title":"Suggestion of a new feature: `index property`","user":{"login":"youknowone","id":69878,"avatar_url":"https://avatars.githubusercontent.com/u/69878?v=3","gravatar_id":"","url":"https://api.github.com/users/youknowone","html_url":"https://github.com/youknowone","followers_url":"https://api.github.com/users/youknowone/followers","following_url":"https://api.github.com/users/youknowone/following{/other_user}","gists_url":"https://api.github.com/users/youknowone/gists{/gist_id}","starred_url":"https://api.github.com/users/youknowone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youknowone/subscriptions","organizations_url":"https://api.github.com/users/youknowone/orgs","repos_url":"https://api.github.com/users/youknowone/repos","events_url":"https://api.github.com/users/youknowone/events{/privacy}","received_events_url":"https://api.github.com/users/youknowone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-02-12T12:23:22Z","updated_at":"2016-03-23T13:50:25Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/zzzeek/sqlalchemy/pulls/235","html_url":"https://github.com/zzzeek/sqlalchemy/pull/235","diff_url":"https://github.com/zzzeek/sqlalchemy/pull/235.diff","patch_url":"https://github.com/zzzeek/sqlalchemy/pull/235.patch"},"body":"Hi,\r\n\r\nI made index property.\r\n\r\nThis patch adds `sqlalchemy.orm.index_property` and `sqlalchemy.orm.json_property`\r\nwhich subscribe an index of a column with `Indexable` type.\r\nThen users can access to these index properties instead of indexable columns which provides simpler interface for both values and queries like hybrid properties.\r\n\r\nAny advice for design or implementation will be appreciated.\r\n\r\nExample usage:\r\n```\r\nclass Member(Base):\r\n    id = Column(Integer, primary_key=True)\r\n    favorite_ids = Column(ARRAY(Integer), default=[DEFAULT_ITEM_ID])\r\n    attributes = Column(MutableDict.as_mutable(JSON), default={})\r\n    \r\n    most_favorite_id = index_property(favorite_ids, 0, use_column_default_for_none=True, default=DEFAULT_ITEM_ID)\r\n    name = json_property(attributes, 'name', cast_type=Text, use_column_default_for_none=True, mutable=True)\r\n\r\n# querying members who changed most favorite item\r\nsession.query(Member).filter(Member.most_favorite_id != DEFAULT_ITEM_ID)\r\n\r\n# querying a member with name 'One'\r\nmember = session.query(Member).filter(Member.name == 'One').first()\r\n# Change the member's name to 'New'\r\nmember.name = 'New'\r\nassert member.attributes['name'] == 'New'\r\n```\r\n\r\nThe problems I couldn't solve well was these stuff:\r\n1. I don't want to set `_is_mutable` to detect it is a mutable column or not. Is there a possible way without this?\r\n2. Because index_property is basically depending on attributes name but getting a column object directly, it is hard to retrieve the attribute name from the column object. currently it iterates mostly all of the columns to find out it. Is there a better way?"},"comment":{"url":"https://api.github.com/repos/zzzeek/sqlalchemy/issues/comments/200352115","html_url":"https://github.com/zzzeek/sqlalchemy/pull/235#issuecomment-200352115","issue_url":"https://api.github.com/repos/zzzeek/sqlalchemy/issues/235","id":200352115,"user":{"login":"zzzeek","id":128223,"avatar_url":"https://avatars.githubusercontent.com/u/128223?v=3","gravatar_id":"","url":"https://api.github.com/users/zzzeek","html_url":"https://github.com/zzzeek","followers_url":"https://api.github.com/users/zzzeek/followers","following_url":"https://api.github.com/users/zzzeek/following{/other_user}","gists_url":"https://api.github.com/users/zzzeek/gists{/gist_id}","starred_url":"https://api.github.com/users/zzzeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzzeek/subscriptions","organizations_url":"https://api.github.com/users/zzzeek/orgs","repos_url":"https://api.github.com/users/zzzeek/repos","events_url":"https://api.github.com/users/zzzeek/events{/privacy}","received_events_url":"https://api.github.com/users/zzzeek/received_events","type":"User","site_admin":false},"created_at":"2016-03-23T13:50:25Z","updated_at":"2016-03-23T13:50:25Z","body":"the PG types extend from a common base type called sqlalchemy.sql.sqltypes.Indexable, you probably want to look into that"}}