{"id":18256649,"url":"https://github.com/honmaple/maple-json","last_synced_at":"2025-04-04T18:30:31.538Z","repository":{"id":145149648,"uuid":"76363723","full_name":"honmaple/maple-json","owner":"honmaple","description":"sqlalchemy serializer to json","archived":false,"fork":false,"pushed_at":"2017-08-08T02:47:50.000Z","size":12,"stargazers_count":9,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-20T16:52:09.672Z","etag":null,"topics":["json","serializer","sqlalchemy"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/honmaple.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-13T14:00:51.000Z","updated_at":"2020-10-26T03:10:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc6238d2-1163-4884-b226-2fb3c5f0228f","html_url":"https://github.com/honmaple/maple-json","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honmaple%2Fmaple-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honmaple%2Fmaple-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honmaple%2Fmaple-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/honmaple%2Fmaple-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/honmaple","download_url":"https://codeload.github.com/honmaple/maple-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229087,"owners_count":20904978,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","serializer","sqlalchemy"],"created_at":"2024-11-05T10:23:02.233Z","updated_at":"2025-04-04T18:30:31.532Z","avatar_url":"https://github.com/honmaple.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"* maple-json\n  [[LICENSE][https://img.shields.io/badge/license-BSD-blue.svg]]\n  [[https://www.python.org/download/releases/3.0/][https://img.shields.io/badge/python-3.5-green.svg]]\n\n* Serializer sqlachemy object to json\n  \n** usage\n  it's simple to use(take flask-sqlalchemy as an example)\n\n** multi instances\n   #+BEGIN_SRC python\n   posts = Post.query.all()\n   serializer = Serializer(posts)\n   data = serializer.data\n   #+END_SRC\n\n** single instance\n   #+BEGIN_SRC python\n   post = Post.query.first()\n   serializer = Serializer(post)\n   data = serializer.data\n   #+END_SRC\n\n** exclude some columns\n   #+BEGIN_SRC python\n   serializer = Serializer(post,exclude=['title'])\n   #+END_SRC\n\n** only include some column\n   #+BEGIN_SRC python\n   serializer = Serializer(post,include=['title'])\n   #+END_SRC\n\n** relation depth\n   #+BEGIN_SRC python\n   serializer = Serializer(post,depth=3)\n   #+END_SRC\n   - depth\n     default:2\n\n** add some custom function\n   #+BEGIN_SRC python\n   serializer = Serializer(post,extra=['get_post_count'])\n   #+END_SRC\n   Post\n   #+BEGIN_SRC python\n     class Post(Model):\n         ......\n         def get_post_count(self):\n             return 11\n   #+END_SRC\n\n** Other\n  #+BEGIN_SRC python\n    class PostSerializer(Serializer):\n        count = Field(source = 'get_post_count',args={'name':'hello'},default=20)\n        class Meta:\n            include = []\n            depth = 2\n            include = []\n            exclude = []\n            extra = ['count']\n  #+END_SRC\n\n  \n* Just use sqlalchemy like django orm\n  \n** base query(have finished)\n   - gt\n   - lt\n   - lte\n   - gte\n   - contains\n   - in\n   - exact\n   - iexact\n   - startswith\n   - istartswith\n   - iendswith\n   - endswith\n   - isnull\n   - range\n   - year\n   - month\n   - day\n\n   Example:\n   #+BEGIN_SRC python\n   Post.query.filter_by(title__contains = 'sql').all()\n   Post.query.exclude_by(title__contains = 'sql').all()\n   #+END_SRC\n   \n** relationship query\n   #+BEGIN_SRC python\n   Post.query.filter_by(tags__name__contains = 'sql').all()\n   #+END_SRC\n   \n** other\n   #+BEGIN_SRC python\n   Post.query.filter_by(tags__name__contains = 'sql').or(Post.id == 1,Post.id == 2).all()\n   Post.query.filter_by(tags__name__contains = 'sql').and(Post.id == 1,Post.id == 2).all()\n   Post.query.filter_by(tags__name__contains = 'sql').exists()\n   Post.query.load_only('title')\n   #+END_SRC\n   \n* Use sqlalchemy better\n  take flask-sqlalchemy as an example,you can remove part of the repetitive work by use *Mixin* of 'models.py'\n\n** ModelMixin\n   Increment ID -- id\n\n   #+BEGIN_SRC python\n   post = Post(·····)\n   post.save() \n   post.delete()\n   #+END_SRC\n\n   bulk operation\n   - bulk_insert\n   - bulk_update\n   - bulk_save\n\n** ModelTimeMixin\n   - created_at\n     Data create time\n   - updated_at\n     Data update time\n\n** ModelUserMixin\n   relate to *User*(many to one)\n   #+BEGIN_SRC python\n     class Post(ModelUserMixin, Model):\n\n         user_related_name = 'posts'\n         titile = ...\n   #+END_SRC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhonmaple%2Fmaple-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhonmaple%2Fmaple-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhonmaple%2Fmaple-json/lists"}