{ "info": { "author": "cirlmcesc", "author_email": "cirlmcesc_ma@163.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# mysqlorm\n\n\nTL:DR\n-----\nA simple ORM MySQL operation Library, running on Python3.\nAutomatic long connection\uff0csupport chain call, more secure statement generation and the MySQL query can be constructed more elegantly.\n\n\nInstallation\n------------\nInstall via pip\n\n```\n(sudo) pip(3) install mysqlorm\n```\n\n\nUsage\n-----\nBegin by importing the mysqlorm module:\n\n```python\nfrom mysqlorm import ORMModel, MySQLConnect\n```\n\nYou need to link the database before use\uff1a\n\n```python\nmysql_connect_config = {\n \"host\": \"host\",\n \"user\": \"user\",\n \"passwd\": \"passwd\",\n \"db\": \"db\",\n}\nMySQLConnect.connect(mysql_connect_config)\n```\n\nCreate a class to inherit ormmodel and set `table_name` attribute:\n(If no `table_name` attribute is set, use the lowercase class name by default.)\n\n```python\nclass ExampleModel(ORMModel):\n table_name = \"exampletable\"\n```\n\nHow to use\n----------\n\n* Insert:\n\n ```python\n ExampleModel.insert({\"field1\": \"value1\", \"field2\", \"value2\"}) # single insert\n ExampleModel.insert(( # batch insert, can use tuple or list\n {\"field1\": \"value1\", \"field2\", \"value2\"}, \n {\"field1\": \"value1\", \"field2\", \"value2\"}))\n ```\n\n* Where:\n\n Support call chaining.\n The `where` method can pass 2 or 3 parameters.\n If two parameters are passed, the comparison symbol uses the equal sign by default.\n Call chaining use `and` connection condition, you must use `orWhere` method to `or` condition\n\n ```python\n ExampleModel.where(\"field\", \"value\").where(\"field\", \">\", \"value\")\n ExampleModel.where(\"field\", \"value\").orWhere(\"field\", \">\", \"value\")\n ```\n\n Support batch afferent condition, can use tuple or list.\n Use `and` connection condition\n\n ```python\n ExampleModel.where(((\"filed1\", \"value1\"), (\"filed2\", \"value2\")))\n ```\n\n Support aggregation condition query.\n Or you can use lambda method.\n\n ```python\n def condition(query):\n return query.where(\"field\", \"value\").where(\"field1\", \">\", \"value\")\n\n ExampleModel.where(condition).orWhere(\n lambda query: return query.where(\"field\", \"value\").where(\"field1\", \"<\", \"value\")\n )\n ```\n\n The `like` condition uses the \"LOCATE()\" implementation,\n because the `%` symbol is a special symbol in Python will cause some problems. \n So do not pass in the `where` method the parameter with the `%` symbol.\n\n ```python\n ExampleModel.where(\"file\", 'like', \"value\")\n ```\n\n You can use `whereIn` and `whereNotIn` method.\n Can use tuple or list.\n\n ```python\n ExampleModel.whereIn(\"field\", TupleOrList).whereNotIn(\"field\", TupleOrList)\n ```\n\n You can use `whereBetween` and `whereNotBetween`.\n\n ```python\n ExampleModel.whereBetween(\"field\", \"from_condition\", \"to_condition\"\n ).whereNotBetween(\"field\", \"from_condition\", \"to_condition\")\n ```\n\n You can use `whereNull` and `whereNotNull`.\n\n ```python\n ExampleModel.whereNull(\"field1\").whereNotNull(\"field2\")\n ```\n\n* Query:\n\n You can use `select` method to defining query fields.\n If a parameter is not passed, use by default `*`.\n The default is to query `id`.\n Or can not use `select` method.\n\n ```python\n query = ExampleModel.select(\"field1\", \"field2\", \"field3\")# n field parameters can be passed in.\n ```\n\n All queries support the `where` method conditional queries.\n\n ```python\n query.where(\"field\", \"value\")\n ```\n\n You can use `when` method.\n Execute the query when the value is true or skip.\n The second parameter can be a function, like the use of the `where` method.\n\n ```python\n import random\n a = random.choice(range(1, 10))\n b = random.choice(range(1, 10))\n query.when(a != b, condition).when(a == b, lambda query: return query.where(\"field\", \"value\"))\n ```\n\n You can use `orderBy` method to sort resault.\n The `orderBy` method can pass 1 or 2 parameters.\n If one parameter passed, use 'ASC' by default.\n\n ```python\n query.orderBy(\"field\")\n ```\n\n You can use `groupBy` method\n But you must pay attention to the problems caused by `sql_mode=only_full_group_by`\n\n ```python\n query.groupBy(\"field\")\n ```\n\n You can use `limit` method\n The `where` method can pass 1 or 2 parameters.\n If one parameter is passed, offer use 0 by default.\n\n ```python\n query.limit(0, 10)\n ```\n\n The query returns are all model instances.\n Can easy to operate on a single instance.\n\n ```python\n query.all() # to get all data\n query.find(1) # to find data from id\n query.get() # to get data what query according to conditions\n query.first() # to get first raw data what query according to conditions\n ```\n\n* Update:\n\n ```python\n # The `update` method supports the `where` conditions.\n ExampleModel.update({\"field1\": \"value1\", \"field2\", \"value2\"}) # batch update\n ExampleModel.where(\"field\", \"value\").update({\"field1\": \"value1\"})\n ```\n\n* Delete:\n\n ```python\n # The `delete` method supports the `where` conditions.\n ExampleModel.where(\"field\", \"value\").delete()\n ```\n\n* ORMModel:\n\n ORMModel instances can be operated on a variety of operations.\n You can get a ormmodel instance in this way:\n\n ```python\n example = ExampleModel(attributes=attr) # attr must be a dict that matches the database field\n ```\n\n You can use the `save` method to insert data.\n\n ```python\n example.save()\n ```\n\n You can use the `save` method to update data or use the `delete` method to delete data.\n But the instances must from query resault.\n\n ```python\n example = ExampleModel.find(1)\n example.field = \"new value\"\n example.save() # update data\n example.delete() # delete data\n ```\n\n Converting ormmodel instances to dict with `dict` method\n\n ```python\n example.dict()\n ```\n\nTODO\n----\n* Perfect the join table query.\n* Add more functions for ormmodel.\n* Increase the association between ormmodel.", "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/cirlmcesc/mysqlorm", "keywords": "mysql orm", "license": "", "maintainer": "", "maintainer_email": "", "name": "mysqlorm", "package_url": "https://pypi.org/project/mysqlorm/", "platform": "", "project_url": "https://pypi.org/project/mysqlorm/", "project_urls": { "Homepage": "https://github.com/cirlmcesc/mysqlorm" }, "release_url": "https://pypi.org/project/mysqlorm/0.2/", "requires_dist": null, "requires_python": "", "summary": "A simple ORM MySQL operation Library, running on Python3.", "version": "0.2" }, "last_serial": 4087741, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "860ee856c5abe008fffe81fe9a5abbb7", "sha256": "d1c66987fe1aaeb933fb5eb789aa597594a32841c7990b6becf2bb6a72d8e983" }, "downloads": -1, "filename": "mysqlorm-0.1.tar.gz", "has_sig": false, "md5_digest": "860ee856c5abe008fffe81fe9a5abbb7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8965, "upload_time": "2018-07-21T03:12:07", "url": "https://files.pythonhosted.org/packages/b9/87/de4ceb4bc786fef21eaba451e7586d8c14cfa655d414b16cefc1ca0d5071/mysqlorm-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "891ae3f66db0b470984efc143983dfcd", "sha256": "03265d61c5a077f1f79fe382a297f2d433f45210b97e1629411fd267a5b1ffb6" }, "downloads": -1, "filename": "mysqlorm-0.2.tar.gz", "has_sig": false, "md5_digest": "891ae3f66db0b470984efc143983dfcd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9108, "upload_time": "2018-07-21T03:46:43", "url": "https://files.pythonhosted.org/packages/ae/5f/b7f7d28739acf47100342e3a5ade3f47164943a6b4f3443887a500396949/mysqlorm-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "891ae3f66db0b470984efc143983dfcd", "sha256": "03265d61c5a077f1f79fe382a297f2d433f45210b97e1629411fd267a5b1ffb6" }, "downloads": -1, "filename": "mysqlorm-0.2.tar.gz", "has_sig": false, "md5_digest": "891ae3f66db0b470984efc143983dfcd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9108, "upload_time": "2018-07-21T03:46:43", "url": "https://files.pythonhosted.org/packages/ae/5f/b7f7d28739acf47100342e3a5ade3f47164943a6b4f3443887a500396949/mysqlorm-0.2.tar.gz" } ] }