{ "info": { "author": "Eric Russell, Anant Asthana", "author_email": "eric-r@pobox.com,anant.asty@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# hstore-field\n\nhstore-field is not compatible with django1.5+\n\nhstore-field is a library which integrates the \n[`hstore`](http://www.postgresql.org/docs/9.0/interactive/hstore.html)\nextension of PostgreSQL into Django, assuming one is using Django 1.3+, \nPostgreSQL 9.0+, and Psycopg 2.3+.\n\nhstore-field draws some inspiration from \n[jordanm/django-hstore](http://github.com/jordanm/django-hstore) and \n[niwibe/django-orm-extensions](https://github.com/niwibe/django-orm-extensions), \nbut it uses a completely different mechanism for extending Django, which has the \nfollowing advantages:\n\n 1. Does not require a custom database backend (at the cost of not supporting \n indexes on hstore fields)\n 1. Does not require a custom QuerySet class, making it fully compatible with \n GeoDjango or any other extension that does subclass QuerySet\n 1. Supports range lookup types in queries (i.e., `__lt`, `__gt`, etc...)\n 1. Mostly compatible with South (see limitations below for specifics)\n\n## Limitations\n\n- Because we're not using a custom database backend, hstore-field does not \n support indexes on hstore fields.\n- Only numbers, strings, and dates may be stored in an hstore dictionary. \n Hstore-field will convert numbers and dates to strings for you when you write \n to the field, but it *will not convert them back* into their original types when \n the hstore dictionary is retrieved from the database. You can make a custom\n class serialize to hstore by giving it a `to_hstore` method, which must return \n a string.\n- Hstore-field will automatically try to install configure hstore on any \n database you connect to, using the `connection_created` signal. If you connect \n to multiple databases, this could present a problem.\n- Adding an HStoreField with `null=False` to an existing model using South is \n problematic, because South cannot emit the correct SQL for the default. One\n workaround is to add the column by putting the SQL directly in the migration\n \n ```python\n def forwards(self, orm):\n db.execute('ALTER TABLE \"[table]\" ADD COLUMN \"[column]\" hstore NOT NULL DEFAULT hstore(array[]::varchar[]);')\n ```\n \n Another alternative is to add the field with `null=True`, populate the field, \n then set `null=False`. This is actually considered good practice in general, \n because default values can cause unexpected problems.\n\n## Running the tests\n\n```\n$ python manage.py test test_hstore_field \n```\n \n For this to work\n 1. hstore must be installed in your PostgreSQL contrib folder\n 1. If you are running PostgreSQL 9.0, the directory containing `pg_config` \n must be on your `PATH`\n\n## Usage\n\nModel definition is straightforward:\n\n```python\nfrom django.db import models\nfrom hstore_field import fields\n\nclass Item (models.Model):\n name = models.CharField(max_length=64)\n data = fields.HStoreField()\n```\n\nYou then treat the `data` field as a dictionary of string pairs:\n\n```python\ninstance = Item.objects.create(name='something', data={'a': '1', 'b': '2'})\nassert instance.data['a'] == '1'\n\nempty = Item.objects.create(name='empty')\nassert empty.data == {}\n\nempty.data['a'] = '1'\nempty.save()\nassert Item.objects.get(name='something').data['a'] == '1'\n```\n\nYou can issue queries against hstore keys using the `HQ` class (similar to the `Q` class)\n\n```python\nfrom hstore_field.query import HQ\n\n# return only objects whose dictionary contains a given key...\nItem.objects.filter(HQ(data__contains='a'))\n\n# ...or that contain all keys in a given list (or tuple)\nItem.objects.filter(HQ(data__contains=['a', 'b']))\n```\n\nYou can also query against hstore values:\n\n```python\n# find by exact value\nItem.objects.filter(HQ(data__a='1'])) # equivalent to Item.objects.filter(HQ(data__a__exact='1']))\n\n# subset by list of values\nItem.objects.filter(HQ(data__a__in=['1', '2']))\n\n# subset by range query using integer\nItem.objects.filter(HQ(data__a__lt=1))\n\n# subset by range query using float\nItem.objects.filter(HQ(data__a__gt=1.1))\n\n# subset by range query as timestamp\nItem.objects.filter(HQ(data__a__lte=datetime.datetime(2012, 1, 1, 0, 15)))\n\n# subset by range query as date\nItem.objects.filter(HQ(data__a__gte=datetime.date(2012, 1, 1)))\n\n# subset by range query as time\nItem.objects.filter(HQ(data__a__lte=datetime.time(7, 15)))\n```\n\nNote that, when issuing a range query against an hstore key using a non-string \ntype, any non-null values for that key that cannot be cast to the appropriate \ntype will cause the query to fail. \n\n`HQ` objects may be combined using `&`, `|`, and `~`, just like `Q` objects. But\nthey may only be combined with other `HQ` objects, and not with any `Q` objects. \nTo combine an `HQ` object with a `Q` object, you must first wrap the `HQ` object \nin a `Q` object. For example:\n\n```python\nItem.objects.filter(HQ(data__a__lt=10) & HQ(data__b__lt=20)) # YES!\n\nItem.objects.filter(Q(HQ(data__a__lt=10)) & Q(data__name=\"foo\")) # YES!\n\nItem.objects.filter(HQ(data__a__lt=10) & Q(data__name=\"foo\")) # NO!\n```\n\nRange queries are not especially fast, because they require a table scan and for \nevery record's hstore->key to be cast from string to another type. However, \nit is much faster than shipping the entire table to the application layer as\nDjango model objects and filtering them there (3-6 times faster in limited testing).\n\nSupport for indexing hstore values as numbers and/or dates is planned for a \nfuture release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/anantasty/hstore-field", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "hstore-field", "package_url": "https://pypi.org/project/hstore-field/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/hstore-field/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/anantasty/hstore-field" }, "release_url": "https://pypi.org/project/hstore-field/1.0.3/", "requires_dist": null, "requires_python": null, "summary": "Support for PostgreSQL's hstore for Django.", "version": "1.0.3" }, "last_serial": 913003, "releases": { "1.0.3": [ { "comment_text": "built for Linux-3.11.0-13-generic-x86_64-with-glibc2.4", "digests": { "md5": "2dcff932451d558d96209a1edf18e24d", "sha256": "d9fde3284967e194c0fb3e1cc002eb8d67a958b9af799707472d7878722f8737" }, "downloads": -1, "filename": "hstore-field-1.0.3.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "2dcff932451d558d96209a1edf18e24d", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 11968, "upload_time": "2013-11-06T20:25:48", "url": "https://files.pythonhosted.org/packages/d2/03/5bb0a36dc5ee4d3630a4bb666ac28158959caf921a5f123595ae4f70d322/hstore-field-1.0.3.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "4f50abc43e11ade0607c69f9028f6cfd", "sha256": "6629b3902d6679bfa64aa874b319017b054ac2462b735ac7042e59100e60ab8c" }, "downloads": -1, "filename": "hstore-field-1.0.3.tar.gz", "has_sig": false, "md5_digest": "4f50abc43e11ade0607c69f9028f6cfd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7935, "upload_time": "2013-11-06T20:52:36", "url": "https://files.pythonhosted.org/packages/b9/27/61200512384cddbbaedc16f5c2d993d945b8052b8336150fba34646ab3f6/hstore-field-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "built for Linux-3.11.0-13-generic-x86_64-with-glibc2.4", "digests": { "md5": "2dcff932451d558d96209a1edf18e24d", "sha256": "d9fde3284967e194c0fb3e1cc002eb8d67a958b9af799707472d7878722f8737" }, "downloads": -1, "filename": "hstore-field-1.0.3.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "2dcff932451d558d96209a1edf18e24d", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 11968, "upload_time": "2013-11-06T20:25:48", "url": "https://files.pythonhosted.org/packages/d2/03/5bb0a36dc5ee4d3630a4bb666ac28158959caf921a5f123595ae4f70d322/hstore-field-1.0.3.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "4f50abc43e11ade0607c69f9028f6cfd", "sha256": "6629b3902d6679bfa64aa874b319017b054ac2462b735ac7042e59100e60ab8c" }, "downloads": -1, "filename": "hstore-field-1.0.3.tar.gz", "has_sig": false, "md5_digest": "4f50abc43e11ade0607c69f9028f6cfd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7935, "upload_time": "2013-11-06T20:52:36", "url": "https://files.pythonhosted.org/packages/b9/27/61200512384cddbbaedc16f5c2d993d945b8052b8336150fba34646ab3f6/hstore-field-1.0.3.tar.gz" } ] }