{ "info": { "author": "Seeberg", "author_email": "soren.seeberg@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6" ], "description": "# MrDatabase v. 0.9.8\nDatabasing as easy as it gets!\n\n## Simple Code Examples\n\n### Installation\n\n`pip install mrdatabase`\n\n### Create a Database\n\nWhen creating an instance of MrDatabase, it will check if the path points to an existing sqlite .db file. If it does not, it will create it.\n\n```python\nfrom mr_database import MrDatabase\n\ndb = MrDatabase('some/path/my.db')\n```\n\nMost connecting and disconnecting actions with the database is handled by the internals of MrDatabase.\n\n### Tables (DDL)\n\nCreating a new table class is super easy. This class works both as schema and record factory. Simply create a class that inherits from ```Table```. Add fields as class variables. Each field must be an instance of ```Column```. Voil\u00c3\u00a0, the table is ready!\n\n```python\nfrom mr_database import Column\nfrom mr_database import Table\nfrom mr_database import DataTypes\n\nclass City(Table):\n\n id = Column(DataTypes.integer, pk=True)\n postalCode = Column(DataTypes.smallint, default=9999)\n cityName = Column(DataTypes.varchar(40), default='New York')\n```\n\nWith a table class in hand, creating or dropping a table in the database is as easy as shown below!\n\n```python\ndb.create_table(City)\ndb.drop_table(City)\n```\n\n### Type Hinting\n\nIf you want Python 3 style type hints on your record intances, you will have to be a bit more verbose in how you define the table class.\n\nYou will have to make an `__init__` method, initialize the super class and add each of the attributes, with type hint and set the default value from the class level ```Column``` objects. It may sound complicated, but if you look below, it's quite doable. Type hinting can be extremely helpful. Especially if you use an editor like PyCharm.\n\n```Python\nclass City(Table):\n\n id = Column(DataTypes.integer, pk=True)\n postalCode = Column(DataTypes.smallint, default=9999)\n cityName = Column(DataTypes.varchar(40), default='New York')\n\n def __init__(self):\n super().__init__()\n\n self.id: int = City.id.default\n self.postalCode: int = City.postalCode.default\n self.cityName: str = City.cityName.default\n```\n\n### Records (DML)\nTo insert, update or delete records in the database, you need record objects representing what you want to manipulate.\n\nIf you have setup an integer primary key on your table, the pimary key attribute will auto increment when inserting records. When you insert, the id of your record object will be updated with the assigned id.\n\nYou can create new record objects like the `city1` example, where you make an instance of a table class, or you can fetch existing ones from the database using `db.select_record` or `db.select_records`. Lastly you can call `.clone()` on the record you want to copy. This method returns a `copy.deepcopy` if the record in question.\n\n```python\ncity1 = City()\ncity1.postal_code = 10115\ncity1.city_name = 'Berlin'\n\ncities = db.select_records(City) # all cities\ncities = db.select_records(City, condition='postalCode > 4000') # all cities with a postal code > 4000\na_city = db.select_record(City, condition='cityName=\"Berlin\"') # just Berlin\n\ncity2 = city1.clone() # clone (copy.deepcopy)\n\ndb.insert_record(city1)\ndb.update_record(city1)\ndb.delete_record(city1)\n```\n\n### Batching\nBy default, mutating actions like `insert_record` and `update_record`, commit changes to the database one action at a time. This is very easy to work with, but for heavy work loads, this can be quite taxing on performance. If you need to execute many mutating actions you can batch actions together to dramatically improve performance.\n\nTo set it up, you use the `DatabaseConnection` context manager. You pass it the `db` object and set `con_type=ConType.batch`. All database actions called within the `DatabaseConnection` will use the database connection managed by `DatabaseConnection`.\n\n```python\nfrom mr_database import DatabaseConnection\nfrom mr_database import ConType\n\nwith DatabaseConnection(db, con_type=ConType.batch):\n for clone_number in range(10000):\n new_person = person_1.clone()\n new_person.firstName += f'_{clone_number}'\n db.insert_record(new_person)\n```\n\nThe example above inserts 10.000 clones of a ```Person()``` record. It takes less than 500 ms on a standard laptop ano 2017.\n\n\n# Release Notes\n\n### Version 0.9.8\n- Renaming project name from mr_database to mrdatabase \n\n### Version 0.9.7\n- Renaming project name from MrDatabase to mr_database \n\n### Version 0.9.6 Alpha\n- Added pytest code for most functionality\n- Added MrDatabase.table_exists\n- Renamed get_referenced_record to get_join_record\n- Renamed get_referenced_record_all to select_join_record_all\n- Moved demo code into /samples/ module\n- Updated .gitignore to reflect changes\n- Updated documentation (batching)\n- Run_tests.bat now assumes python.exe is on PATH\n- Preparing a pypi package (setup.py, cleaning project, etc.)\n\n### Version 0.9.5 Alpha\n- Added code example of how to do batching of sql commands (10K rows in less than half a sec)\n- Added documentation of how to do batching of sql commands\n- Added .clone() to record objects (based on copy.deepcopy)\n- Experimented with script generation, but performance is too terrible\n- Refactored database_connection (now DatabaseConnection) to better distinguish between mutation, query and batch.\n- Added ConType enum class (mutation, query, batch)\n- Cleanup, simplification and optimization of Table class\n- Cleanup, simplification and optimization of MrDatabase class\n- Added autoincrementation for integer primary keys\n- Changed the pyside samples to use the new DatabaseConnection\n- Added record instance type hint example to documentation\n\n\n### Version 0.9.4 Alpha\n- Added code examples to README.md\n- Renamed `MrDatabase.get_next_id` to `MrDatabase.increment_id`\n- changed `MrDatabase()` to simply take a path instead of path and db name as separate arguments\n- created unified namespace for imports\n\n### Version 0.9.3 Alpha\n- property name is no longer required to be passed in as argument\n\n### Version 0.9.2 Alpha\n- Fixed demo_blob.py\n\n### Version 0.9.1 Alpha\n- Simplified Table definition\n- Converted all query generation to use f-strings\n\n### Version 0.9.0 Alpha\n- Initial Commit\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/SorenSeeberg/MrDatabase", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "MrDatabase", "package_url": "https://pypi.org/project/MrDatabase/", "platform": "", "project_url": "https://pypi.org/project/MrDatabase/", "project_urls": { "Homepage": "https://github.com/SorenSeeberg/MrDatabase" }, "release_url": "https://pypi.org/project/MrDatabase/0.9.8/", "requires_dist": null, "requires_python": "", "summary": "Databasing as easy as it gets!", "version": "0.9.8" }, "last_serial": 3947087, "releases": { "0.9.8": [ { "comment_text": "", "digests": { "md5": "650ffddc2743c3b650e8612242c3b4a4", "sha256": "2e40e3103287bf574d2d41d3c8b0a261d2871f920c990b880af3e7df58796dc0" }, "downloads": -1, "filename": "MrDatabase-0.9.8-py3-none-any.whl", "has_sig": false, "md5_digest": "650ffddc2743c3b650e8612242c3b4a4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 25472, "upload_time": "2018-06-10T10:25:45", "url": "https://files.pythonhosted.org/packages/eb/21/f3793d63df59168c0eb76721726a4ff90529dd29a08cf84e535918f8a29a/MrDatabase-0.9.8-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ea63780528df911336f98892689301c", "sha256": "f83fa80c168e9d9fa1ebc20f8c03e7e5455a66f5d3bc20301ac23b5356cba641" }, "downloads": -1, "filename": "MrDatabase-0.9.8.tar.gz", "has_sig": false, "md5_digest": "8ea63780528df911336f98892689301c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14938, "upload_time": "2018-06-10T10:25:46", "url": "https://files.pythonhosted.org/packages/98/68/285b6eda082c8d6b63d7fcdc667220c4160796b88e279bddd8c72773f7d3/MrDatabase-0.9.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "650ffddc2743c3b650e8612242c3b4a4", "sha256": "2e40e3103287bf574d2d41d3c8b0a261d2871f920c990b880af3e7df58796dc0" }, "downloads": -1, "filename": "MrDatabase-0.9.8-py3-none-any.whl", "has_sig": false, "md5_digest": "650ffddc2743c3b650e8612242c3b4a4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 25472, "upload_time": "2018-06-10T10:25:45", "url": "https://files.pythonhosted.org/packages/eb/21/f3793d63df59168c0eb76721726a4ff90529dd29a08cf84e535918f8a29a/MrDatabase-0.9.8-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ea63780528df911336f98892689301c", "sha256": "f83fa80c168e9d9fa1ebc20f8c03e7e5455a66f5d3bc20301ac23b5356cba641" }, "downloads": -1, "filename": "MrDatabase-0.9.8.tar.gz", "has_sig": false, "md5_digest": "8ea63780528df911336f98892689301c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14938, "upload_time": "2018-06-10T10:25:46", "url": "https://files.pythonhosted.org/packages/98/68/285b6eda082c8d6b63d7fcdc667220c4160796b88e279bddd8c72773f7d3/MrDatabase-0.9.8.tar.gz" } ] }