{ "info": { "author": "Leonard Mivinci XJJ", "author_email": "1366723936@qq.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "```\n _ __ ___ _____ ___ _ __ _ __ ___\n| '_ ` _ \\| __ \\/ _ \\| `__/| '_ ` _ \\\n| | | | | | |___| |_| | | | | | | | |\n|_| |_| |_|_| \\___/|_| |_| |_| |_|\n```\n\n![](https://img.shields.io/badge/Python-3%2B-yellowgreen) ![](https://img.shields.io/badge/MySQL-5.5%2B-yellowgreen) ![](https://img.shields.io/badge/build-passing-brightgreen) ![](https://img.shields.io/badge/license-MIT-blue)\n\n**mporm** is an ORM tool written in Python with only the fundamental CRUD API for MySQL(5.5+) [\u7b80\u4f53\u4e2d\u6587](https://github.com/Mivinci/mporm/blob/master/README_zh.md)\n\n
\n\n## Overview\n\n### Features\n\n- [x] gorm-like API\n- [x] Automatically use `uuid` as field `id`\n- [x] Automatically set `created_at` and `updated_at`\n\n### Install\n\n```bash\npip3 install mporm\n```\n\n### Quick Start\n\n```python\nfrom mporm import ORM, DSN, Model, StrField, IntField\n\nORM.load(DSN(user=\"xxxx\", password=\"xxxx\"))\n\n\nclass Hero(Model):\n name = StrField()\n age = IntField()\n\nHero.create()\n\n# CRUD\nHero.add(name=\"Thor\", age=1000)\nHero.where(name=\"Thor\").set(age=1001).update()\nHero.where(name=\"Thor\").find()\nHero.where(name=\"Thor\").delete()\n\nHero.drop()\n```\n\n### Connect to Database\n\n**mporm** can only connect MySQL database, and has two different ways to load configs of database\n\n##### Load By DSN\n\nThe minimum code that loads by dsn is wriiten as\n\n```python\nfrom mporm import ORM, DSN\n\nORM.load(DSN(user=\"xxxx\", password=\"xxxx\"))\n```\n\nBecause mporm will automatically set other configs as `host` = \"localhost\", `port` = 3306, `database` = \"test\", `charset` = \"utf8\"\n\nOf course you can fill all the configs by yourself\n\n##### Load From Toml File\n\nYou can write all the configs in a toml file like\n\n```toml\n[database]\nuser = \"xxxx\"\npassword = \"xxxx\"\nhost = \"xxxx\"\nport = 3306\ndatabase = \"xxxx\"\ncharset = \"xxxx\"\n```\n\nThen use `load_file` method\n\n```python\nfrom mporm import ORM\n\nORM.load_file(\"path/to/toml\")\n```\n\n**Note** that if you use the second way, remember **all the 6** configs needs to be written in the toml file.\n\n### Table Prefix\n\nYou can define a model with an attribute `__prefix__` , for example:\n\n```python\nfrom mporm import Model\n\nclass Hero(Model):\n __prefix__ = \"Marvel\"\n ...\n\nHero.create() \n```\n\nThis will create a new table named \"marvel_hero\"\n\n
\n\n## CRUD Interfaces\n\nWe have defined a model like\n\n```python\nclass Hero(Model):\n __prefix__ = \"Marvel\"\n name = StrField()\n age = IntField()\n```\n\n### Insert\n\nThere are two methods you can choose from:\n\n```python\nHero.new(name=\"Thor\", age=1000).insert()\n```\n\nor simply use\n\n```python\nHero.add(name=\"Thor\", age=1000)\n```\n\nThe SQL statement that'll be executed is\n\n```sql\ninsert into `marvel_hero` (name, age) values ('Thor', 1000);\n```\n\n### Select\n\n#### Query\n\n```python\nHero.first()\n## select * from `marvel_hero` order by created_at limit 1;\n\nHero.last()\n## select * from `marvel_hero` order by created_at desc limit 1;\n\nHero.take()\n## select * from `marvel_hero` limit 1;\n```\n\nPlus they can take an argument\n\n```python\nHero.first(10)\n## select * from `marvel_hero` order by created_at limit 10;\n\nHero.last(10)\n## select * from `marvel_hero` order by created_at desc limit 10;\n\nHero.take(10)\n## select * from `marvel_hero` limit 10;\n```\n\n#### Where\n\n```python\nHero.where(name=\"Thor\", age=1000).find()\n## select * from `marvel_hero` where name = 'Thor' and age = 1000;\n\nHero.where(name=\"Thor\", age=1000).findone()\n## select * from `marvel_hero` where name = 'Thor' and age = 1000 limit 1;\n```\n\nOf course, Specified Fields Selecting is available\n\n```python\nHero.where(name=\"Thor\", age=1000).select(\"name\").find()\n## select name from `marvel_hero` where name = 'Thor' and age = 1000;\n```\n\nOr you can simply use\n\n```python\nHero.where(name=\"Thor\", age=1000).filter(\"name\")\n## select name from `marvel_hero` where name = 'Thor' and age = 1000;\n```\n\n#### Count\n\n```python\nHero.where(name=\"Thor\").count()\n## select count(id) from `marvel_hero` where name = 'Thor';\n```\n\nAlso custom count field is available\n\n```python\nHero.where(name=\"Thor\").count(\"age\")\n## select count(age) from `marvel_hero` where name = 'Thor';\n```\n\n#### Advanced\n\n##### Order\n\n```python\nHero.where(name=\"Thor\").order(\"age\", desc=True).find()\n## select * from `marvel_hero` where name = 'Thor' order by age desc;\n```\n\n##### Limit\n\n```python\nHero.where(name=\"Thor\").limit(10).find()\n## select * from `marvel_hero` where name = 'Thor' limit 10;\n```\n\n##### Offset\n\n```python\nHero.where(name=\"Thor\").offset(10).find()\n## select * from `marvel_hero` where name = 'Thor' offset 10;\n```\n\nOf course, you can use them like chains\n\n```python\nHero.where(name=\"Thor\").order(\"age\").limit(10).offset(10).select(\"name\", \"age\").find()\n## select name, age from `marvel_hero` where name = 'Thor' order by age asc limit 10 offset 10;\n```\n\n### Update\n\n```python\nHero.where(name=\"Thor\").set(age=1001).update()\n## update `marvel_hero` set age=1001 where name = 'Thor';\n```\n\n### Delete\n\n```python\nHero.where(name=\"Thor\").delete()\n## delete from `marvel_hero` where name = \"Thor\";\n```\n\n**Note** that the methods `insert()` `update()` `delete()` return the amount of rows that're affected and method `find()` returns a `list-typed` query result and not to mention, the method `findone()` returns a `dict-typed` query result.\n\n## Todo\n\n- [ ] where-like\n\n- [ ] where-or\n- [ ] Where-<>\n- [ ] custom sql statement execution\n\n## Contribute\n\nYou can do anything to help deliver a better MPORM.\n\n## License\n\n@ XJJ, 2019~datetime.now()\n\nReleased under the [MIT License](https://github.com/Mivinci/mporm/blob/master/LICENSE)\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/mivinci/mporm", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "mporm", "package_url": "https://pypi.org/project/mporm/", "platform": "", "project_url": "https://pypi.org/project/mporm/", "project_urls": { "Homepage": "https://github.com/mivinci/mporm" }, "release_url": "https://pypi.org/project/mporm/0.0.2/", "requires_dist": [ "PyMySQL", "toml" ], "requires_python": "", "summary": "MySQL ORM in Python", "version": "0.0.2" }, "last_serial": 5722107, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d4633ba4cf3d8e941f14b4ee23d04612", "sha256": "fe02fa23c310a34f85acea80ff7388bad9bbf1ca23bdc8e216738cf444bd6519" }, "downloads": -1, "filename": "mporm-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d4633ba4cf3d8e941f14b4ee23d04612", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11675, "upload_time": "2019-08-23T18:20:29", "url": "https://files.pythonhosted.org/packages/1a/cc/7b56cd3e3f7882b1132841a44b2a02af2333cbc85626c2e02009a1ab79a0/mporm-0.0.1-py3-none-any.whl" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "7033541996321daf32c67bef43b52404", "sha256": "084dd7a4a31b92944f4efcfebae47418880c51997db75f3a6d7d6349066c5e36" }, "downloads": -1, "filename": "mporm-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7033541996321daf32c67bef43b52404", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11694, "upload_time": "2019-08-23T18:31:04", "url": "https://files.pythonhosted.org/packages/f8/30/0e680b8904f7c01f73964cc38a26815e80e7dcf1b977a38c62ec50c34c9d/mporm-0.0.2-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7033541996321daf32c67bef43b52404", "sha256": "084dd7a4a31b92944f4efcfebae47418880c51997db75f3a6d7d6349066c5e36" }, "downloads": -1, "filename": "mporm-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7033541996321daf32c67bef43b52404", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11694, "upload_time": "2019-08-23T18:31:04", "url": "https://files.pythonhosted.org/packages/f8/30/0e680b8904f7c01f73964cc38a26815e80e7dcf1b977a38c62ec50c34c9d/mporm-0.0.2-py3-none-any.whl" } ] }