{ "info": { "author": "Florian Bruggisser", "author_email": "florian@nexpose.ch", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4" ], "description": "pg4nosql\n========\n\n|Build Status| |Code Climate| |Latest Version| |Development Status|\n|Python Versions| |License|\n\nA simple psycopg2 based wrapper for nosql like database interaction with\npython.\n\nWhy another wrapper?\n--------------------\n\nThe wrapper was developed to work with JSON postgres storage like a real\nNoSQL DB (e.g. MongoDB). After a long research with google there was no\nlibrary found which helps to work with JSON and PostgreSQL so I decided\nto develop one.\n\nThe strength of the wrapper is that you still can have multiple\nrelational colums in your table.\n\nInstallation\n------------\n\nUsing `Python Package Index `__ (PIP)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nJust run the command: ``pip install pg4nosql``\n\n*During alpha stage the api will change with each build. So try to stay\nwith one version if you want to use it.*\n\nThe hacky way\n~~~~~~~~~~~~~\n\n1. `download `__ or\n clone this repository\n2. run the command ``python setup.py install``\n\nChangelog\n---------\n\n- Version ``0.4.2``\n- fixed python 3.3 iterator return\n- Version ``0.4.1``\n- Query from view\n- fixed some bugs\n- Version ``0.4.0``\n- adds join query statements\n- adds update method\n- adds save method on result item\n- Version ``0.3.7``\n- adds the support for non-json database tables\n- Version ``0.3.6``\n- id datatype can be set on table creation\n- Version ``0.3.3``\n- project cleanup\n- Version ``0.3.1``\n- auto-commit for very operation as default\n- save does not affect saving object anymore\n- bug fixes\n- Version ``0.2.4``\n- a lot of bug fixes\n- Version ``0.2.0``\n- added port argument\n- replaced dictionary argument with \\*\\*keyword syntax\n- switched result.relational with result.json\n- add bracket syntax to get database or table\n- renamed table.get\\_or\\_create to match codestyle\n\nExample\n-------\n\nThese examples show the funcionality of the wrapper. There are some\nfunctions which are not covered by the examples (like removing of a\ntable) but the importent ones are explained.\n\nDataschema Creation\n~~~~~~~~~~~~~~~~~~~\n\nTo create the dataschema you can use normal database tools if you want.\nA document table has two fields:\n\n- ``id`` with data type **serial**\n- ``json`` with data type **JSON** which represents the document\n\nBut pg4nosql also provides methods to create your database schema on the\nfly. This is useful to create tables and databases software controlled.\n\nThis example shows how to create a database and their tables. The cities\ntable is special because it also contains relational data like a normal\ntable would:\n\n.. code:: python\n\n # create pg4nosql client\n pg4nosql = PostgresNoSQLClient(host='localhost')\n\n # create demo database\n demo_db = pg4nosql['demo']\n\n # create document only table\n users = demo_db['users']\n\n # create document & relational table\n cities = demo_db.get_or_create_table('cities', size='real NOT NULL')\n\nRow Identifier Type\n^^^^^^^^^^^^^^^^^^^\n\nBy default the ``id`` row type is ``SERIAL`` but in some cases it is\nnecessary to define the type yourself. This is possible with the\n``row_identifier_type`` argument.\n\n.. code:: python\n\n # create document table with bigserial\n big_users = demo_db.create_table('big_users',\n row_identifier_type='BIGSERIAL')\n\nInsert Data\n~~~~~~~~~~~\n\nTo insert data into the table you just hand over a dictionary or an\nobject which is json serializable. If there are relational columns\ndefined you can set those by the table name as keyword and the value:\n\n.. code:: python\n\n # store data into users table\n users.put({'name': 'Florian', 'age': 24})\n users.put({'name': 'Markus', 'age': 24})\n users.put({'name': 'Sara', 'age': 22})\n users.put({'name': 'Thomas', 'age': 25})\n\n # store data into cities table\n cities.put({'name': 'Zurich'}, size=87.88)\n cities.put({'name': 'Berlin'}, size=891.8)\n cities.put({'name': 'Bern'}, size=51.6)\n cities.put({'name': 'London'}, size=1572)\n\nIf you work **without json documents**, there is just a normal\n``insert`` method to store new records into a table.\n\n.. code:: python\n\n # store data into cities table\n users.insert(age=25, name=\"Florian\")\n\nLazy Commit\n^^^^^^^^^^^\n\nIf you want to store or save multiple entries you can set the\n``auto_commit`` argument to ``False`` and commit it yourself.\n\n.. code:: python\n\n # store data with lazy commit\n for i in range(0, 255):\n users.put({'name': 'Test', 'age': i}, auto_commit=False)\n\n # lazy commit data\n users.commit()\n\nQuery Data\n~~~~~~~~~~\n\nTo get your data back you can run a query over it. This works like\nnormal SQL WHERE queries. For **JSON** data you have to use the ``json``\ncolumn:\n\n.. code:: python\n\n # query all users which are 24 years old\n users_24 = users.query(\"json->>'age'='24'\")\n\nAnd here the result of the user query:\n\n.. code:: json\n\n [ \n \"{'json': {u'age': 24, u'name': u'Florian'}, 'id': 1}\",\n \"{'json': {u'age': 24, u'name': u'Markus'}, 'id': 2}\"\n ]\n\nYou can also combine relational and JSON queries together like this:\n\n.. code:: python\n\n # query all cities which start with be and are bigger than 100 km\n big_ber_cities = cities.query(\"json->>'name' LIKE 'Ber%'\"\n \"AND size > 100\")\n\nHere the result of this query:\n\n.. code:: json\n\n [ \n \"{'json': {u'name': u'Berlin'}, 'id': 2, 'size': 891.8}\"\n ]\n\nQuery with Join\n~~~~~~~~~~~~~~~\n\nIt is also possible to create simple *joined* queries with the function\n``query_join``. Consider a datamodel with an ``user`` table and an\n``address`` table. This two tables are connected through a *foreign key*\n``fk_user``.\n\nThe called table get's the identifier ``a`` and the joined table the\nidentifier ``b``.\n\n.. code:: python\n\n # get all users with their address\n users = user.query_join('address', 'a.id = b.fk_user')\n\nQuery from View\n~~~~~~~~~~~~~~~\n\nTo query data from a view you have to get the view from the database and\nthen it has the same query method like a table.\n\n.. code:: python\n\n # get view\n self.user_view = self.database.get_view('user_view')\n\n # query data\n records = self.user_view.query()\n\nQuery Data Access\n~~~~~~~~~~~~~~~~~\n\nTo **access** the **JSON** fields of the result there is an attribute\ncalled ``json``:\n\n.. code:: python\n\n # get first city of the result array\n first_city = big_ber_cities[0]\n\n # read JSON attribute\n city_name = first_city.json['name']\n\nTo **access** the **relational** fields of the result you have to use\n**square brackets** (``[]``) on the result:\n\n.. code:: python\n\n # read relational attribute\n city_size = first_city['size']\n\nThere is also a default field called ``id`` which contains the default\nrow identifier for easy access:\n\n.. code:: python\n\n # get id of row\n city_id = first_city.id\n\nUpdate Data\n~~~~~~~~~~~\n\nWith those access methods you can also write into the result and change\nthe values of the fields. To save it just call ``save(obj)`` on the\ntable object.\n\n.. code:: python\n\n # change florian's age\n florian = users_24[0]\n florian.json['age'] = 25\n\n users.save(florian)\n\nThe same works also with the ``relational`` fields:\n\n.. code:: python\n\n # make zurich a bit bigger\n zurich = cities.query_one(\"data->>'name'='Zurich'\")\n zurich['size'] = 90\n\n cities.save(zurich)\n\nWith the release ``0.4.0`` it is also possible to save the database\nobject directly:\n\n.. code:: python\n\n # make zurich a bit bigger\n zurich = cities.query_one(\"data->>'name'='Zurich'\")\n zurich['size'] = 90\n\n zurich.save()\n\n**Without json documents**, there is just a normal ``update`` method to\nupdate new records into a table.\n\n.. code:: python\n\n # store data into cities table\n florian = users_24[0]\n florian['name'] = 'Markus'\n users.update(florian)\n\nDirect Execution\n~~~~~~~~~~~~~~~~\n\nIt is also possible to directly execute sql statements as you are used\nto. The execute function is declared on the database object and on the\ntable object.\n\n.. code:: python\n\n # run simple sql query\n my_data = demo_db.execute('SELECT * FROM cities')\n\nClose Connection\n~~~~~~~~~~~~~~~~\n\nFinally don't forget to close the connection to the database.\n\n.. code:: python\n\n # close db\n demo_db.close()\n\nAbout\n-----\n\nThe wrapper has been written for a science project and is still an early\nbeta version! Idea and implementation by Florian (cansik)\n\nMIT License Copyright (c) 2015\n\n.. |Build Status| image:: https://travis-ci.org/cansik/pg4nosql.svg\n :target: https://travis-ci.org/cansik/pg4nosql\n.. |Code Climate| image:: https://codeclimate.com/github/cansik/pg4nosql/badges/gpa.svg\n :target: https://codeclimate.com/github/cansik/pg4nosql\n.. |Latest Version| image:: https://img.shields.io/pypi/v/pg4nosql.svg\n :target: https://pypi.python.org/pypi/pg4nosql\n.. |Development Status| image:: https://img.shields.io/pypi/status/pg4nosql.svg\n :target: https://pypi.python.org/pypi/pg4nosql\n.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/pg4nosql.svg\n :target: https://pypi.python.org/pypi/pg4nosql\n.. |License| image:: https://img.shields.io/pypi/l/pg4nosql.svg\n :target: https://github.com/cansik/pg4nosql/blob/master/LICENSE.txt", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/cansik/pg4nosql/tarball/0.4.0", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cansik/pg4nosql", "keywords": "postgres,no,sql,wrapper,database,json", "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "pg4nosql", "package_url": "https://pypi.org/project/pg4nosql/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pg4nosql/", "project_urls": { "Download": "https://github.com/cansik/pg4nosql/tarball/0.4.0", "Homepage": "https://github.com/cansik/pg4nosql" }, "release_url": "https://pypi.org/project/pg4nosql/0.4.2/", "requires_dist": null, "requires_python": null, "summary": "A simple psycopg2 based wrapper for nosql like database interaction with python.", "version": "0.4.2" }, "last_serial": 2152742, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "30ef56e9a822639a0c7563b3e4f14fa6", "sha256": "42c37c49d3e203da1ca24c019b91abac4729121768483363687da8829625450a" }, "downloads": -1, "filename": "pg4nosql-0.1.1.tar.gz", "has_sig": false, "md5_digest": "30ef56e9a822639a0c7563b3e4f14fa6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2897, "upload_time": "2015-07-24T09:15:12", "url": "https://files.pythonhosted.org/packages/fa/77/ca5cefa54151cf45bc718a3702cbcf2fc944aa33ddec36ec3d565eabaf16/pg4nosql-0.1.1.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "edf6e92ab7e1641b0fc72faf96d362bb", "sha256": "a73b772990b3439bbf4e29535d34e2de8468ba7e878a2b0c321314c06d1c3354" }, "downloads": -1, "filename": "pg4nosql-0.2.1.tar.gz", "has_sig": false, "md5_digest": "edf6e92ab7e1641b0fc72faf96d362bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3045, "upload_time": "2015-07-27T09:43:17", "url": "https://files.pythonhosted.org/packages/c9/b9/88c85799d890360c4d7db11e987353029a8b4f73f4dbeeb815cf937e3728/pg4nosql-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "fc2af2a77ee656a04553030eef1b2e7f", "sha256": "d4bb8b7058c44df7fb50e0c286127abd2f1d9ea0492ce74b7cd8335a561043c6" }, "downloads": -1, "filename": "pg4nosql-0.2.2.tar.gz", "has_sig": false, "md5_digest": "fc2af2a77ee656a04553030eef1b2e7f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3035, "upload_time": "2015-07-27T09:45:27", "url": "https://files.pythonhosted.org/packages/50/9c/e1894438d53ade3a39e356f496864ea6bc575fb341951d3cd21ff0e96b40/pg4nosql-0.2.2.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "fe4f44a214a185347a19dc779027ee49", "sha256": "face1e757913dedaa9f6f5da50e407951dc6ca6a8350b9164d083a2c56e2768c" }, "downloads": -1, "filename": "pg4nosql-0.2.4.tar.gz", "has_sig": false, "md5_digest": "fe4f44a214a185347a19dc779027ee49", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3211, "upload_time": "2015-07-28T08:10:08", "url": "https://files.pythonhosted.org/packages/57/bf/d7064a12f9250b3d1d0fb8a5885440ee94ffeda8d6a3a0b793482b0c44ca/pg4nosql-0.2.4.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "ff5131ef22fc4ae66290470f010ab9c9", "sha256": "687dd9db5f6a4a3d28ae6af0d936fc64b5e58e252c8caa1587a98f52756ad569" }, "downloads": -1, "filename": "pg4nosql-0.3.1.tar.gz", "has_sig": false, "md5_digest": "ff5131ef22fc4ae66290470f010ab9c9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3334, "upload_time": "2015-08-11T13:44:57", "url": "https://files.pythonhosted.org/packages/0a/33/b6af53aafec56f16c9cfcafe68b520220a6b01149094507257dc4b7ddbe8/pg4nosql-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "8e81763b9fa05d757a324039c977b726", "sha256": "daef1c13aa84687ec6618ece0042a588c2c1efbe141581fa3db59d65602d905c" }, "downloads": -1, "filename": "pg4nosql-0.3.2.tar.gz", "has_sig": false, "md5_digest": "8e81763b9fa05d757a324039c977b726", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5732, "upload_time": "2015-08-18T09:23:23", "url": "https://files.pythonhosted.org/packages/1a/65/4569af0872742fd4deeb7ea961896da56c44bce7c7c2fd8d5bb7f5ba7291/pg4nosql-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "11f349507a27713c04002ddd69f05f4d", "sha256": "dc13684f66c0809d9c97a258f22726463f6b2396a176fdf71df8682d3a2219f5" }, "downloads": -1, "filename": "pg4nosql-0.3.3.tar.gz", "has_sig": false, "md5_digest": "11f349507a27713c04002ddd69f05f4d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5899, "upload_time": "2015-08-18T09:33:57", "url": "https://files.pythonhosted.org/packages/64/02/edb2c9f43501e919f3fcf1164d4bdafb73c6ae3db71b6e7f3f400118bd44/pg4nosql-0.3.3.tar.gz" } ], "0.3.4": [ { "comment_text": "", "digests": { "md5": "b3a8052380e0c602cd2af90fd9f0a7cc", "sha256": "9c723a526c2f7a65fdc27221f1f9d14b49af180596ff5b92094d8d849a207852" }, "downloads": -1, "filename": "pg4nosql-0.3.4.tar.gz", "has_sig": false, "md5_digest": "b3a8052380e0c602cd2af90fd9f0a7cc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5916, "upload_time": "2015-08-19T07:45:53", "url": "https://files.pythonhosted.org/packages/e0/17/1bee88e1daad93b466409ac5aff7c16f67140b4d9d2ad0fc79140ca5d19b/pg4nosql-0.3.4.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "38ec2a076dc90585efc31895d5a2c281", "sha256": "2475650e02b5997b31e36ecbcd1c60ffff46c2893ff11006c13c3f8668e75185" }, "downloads": -1, "filename": "pg4nosql-0.3.6.tar.gz", "has_sig": false, "md5_digest": "38ec2a076dc90585efc31895d5a2c281", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6257, "upload_time": "2015-08-24T06:09:55", "url": "https://files.pythonhosted.org/packages/8c/63/2deb044e4467cc628460eb373605e367c961a017105eaf3b70cbb16b4102/pg4nosql-0.3.6.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "739b05c6332f9ee65f704a063e380531", "sha256": "cd3dad7c209009ab04df42691d2bd7a39ba4bb099fd043efc1154519acd5757a" }, "downloads": -1, "filename": "pg4nosql-0.3.7.tar.gz", "has_sig": false, "md5_digest": "739b05c6332f9ee65f704a063e380531", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6702, "upload_time": "2015-09-09T19:44:45", "url": "https://files.pythonhosted.org/packages/44/58/619ab67d31f9fe1e649904403a3d65f7747abd247bf16c89e65e9a2972ca/pg4nosql-0.3.7.tar.gz" } ], "0.3.8": [ { "comment_text": "", "digests": { "md5": "d6dee87654fae0058e46dc39edbd7892", "sha256": "7446972ad012effc6934314902dba14aa8d27898f991ccdb103170ffdec88504" }, "downloads": -1, "filename": "pg4nosql-0.3.8.tar.gz", "has_sig": false, "md5_digest": "d6dee87654fae0058e46dc39edbd7892", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6613, "upload_time": "2015-09-10T07:03:40", "url": "https://files.pythonhosted.org/packages/8d/6c/eecd79566ae12c77a8e60136f5fa39e82e25079232ccdc7a65306238660d/pg4nosql-0.3.8.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "f4dea0b038ad0c4774c1a06588f683b9", "sha256": "69ab000df387801dc4e10bbb1e2a70a964120a7cd8f8802c542063f27ebabdd1" }, "downloads": -1, "filename": "pg4nosql-0.4.0.tar.gz", "has_sig": false, "md5_digest": "f4dea0b038ad0c4774c1a06588f683b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6757, "upload_time": "2015-09-14T12:20:44", "url": "https://files.pythonhosted.org/packages/ee/20/191c9b496f026165ae68f0dcf6a923cf074b2dd300dc0e553d4f0ae12169/pg4nosql-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "9241c1b42efa722a473ff18ac4988fb6", "sha256": "39b81692f70e55981fb8dbc447bec9527b936571935656b2fedd3a06c5e66630" }, "downloads": -1, "filename": "pg4nosql-0.4.1.tar.gz", "has_sig": false, "md5_digest": "9241c1b42efa722a473ff18ac4988fb6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7361, "upload_time": "2015-10-30T14:18:17", "url": "https://files.pythonhosted.org/packages/b3/8e/53dd3074f8afeffdf6bb2d52bb5ccf88c731345e9768e28a1c61bc6abdb3/pg4nosql-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "08b6dc1e648c6e2677028e5b7218d569", "sha256": "fa09ff9ff67343d24d97f7dd5377ea477f68cfe7a1ebad4eb0685135e4196226" }, "downloads": -1, "filename": "pg4nosql-0.4.2.tar.gz", "has_sig": false, "md5_digest": "08b6dc1e648c6e2677028e5b7218d569", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7392, "upload_time": "2015-10-30T14:50:25", "url": "https://files.pythonhosted.org/packages/08/6a/acfa6166ab2c26d1a5c3d9682d9858cb7f7e5334870acbc3fb31e469a21e/pg4nosql-0.4.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "08b6dc1e648c6e2677028e5b7218d569", "sha256": "fa09ff9ff67343d24d97f7dd5377ea477f68cfe7a1ebad4eb0685135e4196226" }, "downloads": -1, "filename": "pg4nosql-0.4.2.tar.gz", "has_sig": false, "md5_digest": "08b6dc1e648c6e2677028e5b7218d569", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7392, "upload_time": "2015-10-30T14:50:25", "url": "https://files.pythonhosted.org/packages/08/6a/acfa6166ab2c26d1a5c3d9682d9858cb7f7e5334870acbc3fb31e469a21e/pg4nosql-0.4.2.tar.gz" } ] }