{ "info": { "author": "Beproud", "author_email": "righ.m9@gmail.com,crohaco@beproud.jp", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: SQL", "Topic :: Software Development" ], "description": "It enables SQL files to be imported as python modules.\n\n.. image:: https://circleci.com/gh/beproud/sql-importer.svg?style=svg\n :target: https://circleci.com/gh/beproud/sql-importer\n\nRequirements\n============\n- Python 2.7\n- Python 3.6\n\nInstall\n=======\n\n.. code:: bash\n\n $ pip install sql-importer\n\nUsage\n=====\n- You have to make `__init__.py` at the same directory which sql files have been placed on.\n- And write like the following to the `__init__.py`:\n\n .. code:: python\n\n ## if using django:\n # from django.db import connection\n\n import os\n from sql_importer import init\n init(os.path.dirname(__file__), globals(), connection, sql_type='postgresql')\n\n- That's all, you can import sql files (removed `.sql` suffix) as python modules.\n\n - Example: `testing/sql/sum_sales.sql` exists.\n\n .. code:: SQL\n\n SELECT SUM(price) AS sum_sales FROM sales\n WHERE\n sales_from >= :'sales_from'\n AND sales_to < :'sales_to'\n ;\n\n .. code:: python\n\n from datetime import date\n from testing import sql\n sql.sum_sales.query(sales_from=date(2017, 5, 22), sales_to=date(2017, 12, 26))\n\n - `sql` object has 2 methods, both method execute the sql and receive variables as keyword arguments.\n\n :query: It returns records. it expects only what has one or more results like `select` query.\n :execute: It returns number of records affected by the SQL.\n\n- Now `sql_type` argument allows `postgresql`.\n\n - If you want to use the other sql_type, please make the issue on https://github.com/beproud/sql-importer .\n\nDemo\n====\n\nstart up\n--------\n\n.. code:: bash\n\n $ git clone git@github.com:beproud/sql-importer.git\n $ cd sql-importer\n $ docker-compose up\n\n\npreparation\n-----------\n\n.. code:: bash\n\n $ docker exec -it sqlimporter_app_1 /bin/bash\n # python -m venv venv # only first time\n # source venv/bin/activate\n\nTry\n---\n\n.. code:: bash\n\n (venv) # ls tests/postgresql/sql\n __init__.py __init__.pyc __pycache__\tclear.sql create_table.sql delete.sql drop_table.sql insert.sql select.sql update.sql\n\n (venv) # python\n\n.. code:: python\n\n >>> from tests.postgresql import sql\n >>> sql.\n sql.clear sql.create_table sql.drop_table sql.init( sql.os sql.select\n sql.connection sql.delete sql.host sql.insert sql.psycopg2 sql.update\n\n >>> sql.create_table.execute()\n -1\n >>> sql.insert.execute(name='apple', price=100)\n 1\n >>> list(sql.select.query())\n [{'name': 'apple', 'price': 100}]\n >>> sql.delete.execute(name='orange')\n 0\n >>> sql.delete.execute(name='apple')\n 1\n >>> list(sql.select.query())\n []\n\nUnittest\n--------\n\n.. code:: bash\n\n (venv) # tox\n\n\n- This library is tested by only latest `postgresql`.\n\nContributors\n============\n- aodag ( https://github.com/aodag )\n- crohaco ( https://github.com/righ )\n\nLinks\n=====\n- https://github.com/beproud/sql-importer\n- https://pypi.python.org/pypi/sql-importer\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "sql", "license": "", "maintainer": "", "maintainer_email": "", "name": "sql-importer", "package_url": "https://pypi.org/project/sql-importer/", "platform": "", "project_url": "https://pypi.org/project/sql-importer/", "project_urls": null, "release_url": "https://pypi.org/project/sql-importer/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "it enables sql files to be imported as a python module.", "version": "1.0.0" }, "last_serial": 3559448, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "a20b9fbebabd550ea538cb89ef612e60", "sha256": "3262a261a13a4a9a02b879d7761069bb08c3eb29ac2a309aa1b5211fac20f587" }, "downloads": -1, "filename": "sql-importer-0.0.0.tar.gz", "has_sig": false, "md5_digest": "a20b9fbebabd550ea538cb89ef612e60", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1006, "upload_time": "2017-12-26T03:59:07", "url": "https://files.pythonhosted.org/packages/d3/d0/42dc411d49bbf5d47bfe80681a01f3d38a84078e4782bbca0a51cb46df6c/sql-importer-0.0.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "4462f71ed0326eed304fdc24b3c4e232", "sha256": "7aa705f5745d37fc39d14716c6e4600aa506a316604e5f5bed7fe92798bd5cbd" }, "downloads": -1, "filename": "sql-importer-1.0.0.tar.gz", "has_sig": false, "md5_digest": "4462f71ed0326eed304fdc24b3c4e232", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4759, "upload_time": "2018-02-07T06:45:16", "url": "https://files.pythonhosted.org/packages/06/d7/5398d35a2c0db61932933a849bd86354b274b6f3f2b9c2e95ef001e79f17/sql-importer-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4462f71ed0326eed304fdc24b3c4e232", "sha256": "7aa705f5745d37fc39d14716c6e4600aa506a316604e5f5bed7fe92798bd5cbd" }, "downloads": -1, "filename": "sql-importer-1.0.0.tar.gz", "has_sig": false, "md5_digest": "4462f71ed0326eed304fdc24b3c4e232", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4759, "upload_time": "2018-02-07T06:45:16", "url": "https://files.pythonhosted.org/packages/06/d7/5398d35a2c0db61932933a849bd86354b274b6f3f2b9c2e95ef001e79f17/sql-importer-1.0.0.tar.gz" } ] }