{"id":16624370,"url":"https://github.com/dcramer/django-db-routes","last_synced_at":"2025-10-30T00:31:49.700Z","repository":{"id":13928481,"uuid":"16628019","full_name":"dcramer/django-db-routes","owner":"dcramer","description":"work in progress","archived":false,"fork":false,"pushed_at":"2014-02-07T21:42:51.000Z","size":124,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-06T11:18:54.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcramer.png","metadata":{"files":{"readme":"README.rst","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":"2014-02-07T21:27:21.000Z","updated_at":"2023-09-08T16:45:21.000Z","dependencies_parsed_at":"2022-09-23T17:13:07.618Z","dependency_job_id":null,"html_url":"https://github.com/dcramer/django-db-routes","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/dcramer%2Fdjango-db-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-db-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-db-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-db-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcramer","download_url":"https://codeload.github.com/dcramer/django-db-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238913130,"owners_count":19551491,"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":[],"created_at":"2024-10-12T03:46:11.422Z","updated_at":"2025-10-30T00:31:44.442Z","avatar_url":"https://github.com/dcramer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-db-routes\n================\n\nThe gist of the package is that we create a custom connection handler (``django.db.connections``) which\nwill map virtual shards to real databases. Databases end up being ``\u003cclustername\u003e.shard\u003cnumber\u003e``.\n\nPartitioned Models\n------------------\n\n\n::\n\n        DATABASES = {\n            'mycluster': {\n                'NAME': 'mycluster',\n                'SHARDS': 1024,\n                'HOSTS': [\n                    {'HOST': '192.168.0.100'},\n                    {'HOST': '192.168.0.101'},\n                    {'HOST': '192.168.0.102'},\n                    {'HOST': '192.168.0.103'},\n                ],\n            },\n        }\n\n\nExtend the PartitionModel class when creating your models:\n\n::\n\n    from django.db import models\n    from dbroutes.models import PartitionModel\n\n    class MyModel(PartitionModel):\n        user_id = models.PositiveIntegerField()\n\n        class Shards:\n            routing_key = 'user_id'\n            cluster = 'mycluster'\n\nQuery the nodes passing in your ``key``:\n\n::\n\n    objects = MyModel.objects.filter(user_id=1)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-db-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcramer%2Fdjango-db-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-db-routes/lists"}