{"id":15041206,"url":"https://github.com/immmdreza/simple-json-db","last_synced_at":"2025-04-14T19:44:15.254Z","repository":{"id":37956361,"uuid":"495527948","full_name":"immmdreza/simple-json-db","owner":"immmdreza","description":"A simple database based on json for python, Strongly typed, easy and friendly ...","archived":false,"fork":false,"pushed_at":"2022-07-08T14:21:49.000Z","size":1031,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T08:11:07.815Z","etag":null,"topics":["database","db","json","python","serialization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/immmdreza.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2022-05-23T18:27:31.000Z","updated_at":"2024-09-21T14:02:33.000Z","dependencies_parsed_at":"2022-07-30T06:48:03.850Z","dependency_job_id":null,"html_url":"https://github.com/immmdreza/simple-json-db","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immmdreza%2Fsimple-json-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immmdreza%2Fsimple-json-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immmdreza%2Fsimple-json-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immmdreza%2Fsimple-json-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/immmdreza","download_url":"https://codeload.github.com/immmdreza/simple-json-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248949907,"owners_count":21188171,"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":["database","db","json","python","serialization"],"created_at":"2024-09-24T20:45:45.511Z","updated_at":"2025-04-14T19:44:15.233Z","avatar_url":"https://github.com/immmdreza.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-json-db\n\nThis is a simple json database.\nThe package provides a simple ORM between python objects and\njson objects with a well type-hinted schema.\n\n```py\nengine = AppEngine()\n\nasync with engine.students as students:\n    students.add_range(Student(\"John\", \"Doe\"), Student(\"Jane\", \"Doe\"))\n\nasync for student in engine.students:\n    print(student.first_name, student.last_name)\n    # Can you guess ? )\n```\n\nThis package maps your python objects to json and then you can save, get,\nmodify or delete them using async methods.\n\n_This package is for tiny and simple projects. with a low amount of data._\n\n## Installation\n\nThe package is available at [PYPI](https://pypi.org/project/json-entity) as json-entity.\n\n## Intro\n\nLet's see how you can get started with the package.\n\nSee also our [Wiki](https://github.com/immmdreza/simple-json-db/wiki).\n\nYou can take a look at [src/examples](src/examples), if you're not on reading mode.\n\n## Quick Start\n\nThis data base consist of 3 main elements:\n\n1- **Model**\n\n    It's obvious that you should have a model for your data to save, update, or ...\n    \n    Since this library works with json, your model can contain everything\n    that JSON can.\n\n2- **Collection**\n\n    You have a collection of data for every model, therefor,\n    The relation between Model and Collection is one to one.\n\n3- **Engine**\n\n    This is where all collections are operate.\n\nSo, Every `Engine` has some `Collection`s where each collection\ncontains a set of an unique `Model`.\n\n### Let's create a model\n\nModels are simple python class.\n\n```py\nfrom sjd import TEntity, Engine, properties as props\n\n@props.auto_collect()\nclass Person(TEntity):\n    def __init__(self, first_name: int, last_name: str, age: int):\n        self.first_name = first_name\n        self.last_name = last_name\n        self.age = age\n```\n\nUsing `auto_collect()` method,\nthe model will automatically collect properties form `__init__` method.\n\n### Creating collection ?\n\nIt's really not necessary to create a collection by your own!\nAnd maybe you better )\n\nLet us do that for ya ( Of course you can create customized Collections ).\n\n### Setup engine\n\nNow you need to setup database's engine and define your collections there.\n\n```py\n# ---- sniff ----\n\nclass AppEngine(Engine):\n    __db_path__ = \"my_database\"\n    persons = Engine.set(Person)\n```\n\nThat's all you need to do for now.\n\n### Fire up\n\nNow it's time for some fireworks 🎇.\n\n_Since the package is `async`, you'll need an event loop for it._\n\n```py\nimport asyncio\n\n# ---- sniff ----\n\nasync def main():\n    ...\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\nNow you can work with database inside main function.\n\n```py\nasync def main():\n\n    engine = AppEngine()\n    collection = engine.persons\n\n    async with collection:\n        collection.add_range(\n            Person(\"John\", \"Doe\", 20),\n            Person(\"Jane\", \"Doe\", 21),\n            Person(\"Jack\", \"jones\", 22),\n            Person(\"Jill\", \"jones\", 23),\n        )\n\n```\n\nIterate over all persons in the collection\n\n```py\nasync for person in collection:\n    print(person.first_name, person.last_name, person.age)\n```\n\nYou can do more advanced query stuff with `queryable context`.\n\n```py\nasync with collection.get_queryable() as persons:\n    async for person in persons.where(lambda p: p.age \u003e 21):\n        print(person.first_name, person.last_name, person.age)\n```\n\nOr get only one directly.\n\n```py\ntarget = await collection.get_first_async(lambda s: s.first_name, \"John\")\n```\n\nYou can easily update your data:\n\n```py\nasync with collection.get_queryable() as persons:\n    async for person in persons.where(lambda p: p.last_name == \"jones\"):\n        person.last_name = \"Jones\"\n\nawait collection.save_changes_async()\n```\n\nOr even delete them ...\n\n```py\nasync with collection.get_queryable() as persons:\n    async for person in persons.where(lambda p: p.last_name == \"Doe\"):\n        collection.delete(person)\n\nawait collection.save_changes_async()\n```\n\nThere're a lot more! see [src/examples](src/examples).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimmmdreza%2Fsimple-json-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimmmdreza%2Fsimple-json-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimmmdreza%2Fsimple-json-db/lists"}