|
| 1 | +# Django Async Orm |
| 2 | +Django module that brings async to django ORM. |
| 3 | + |
| 4 | +# Installing |
| 5 | +``` |
| 6 | +python -m pip install django-async-orm |
| 7 | +``` |
| 8 | + |
| 9 | +then add `django_async_orm` to your `INSTALLED_APPS` list: |
| 10 | + |
| 11 | +```python |
| 12 | +INSTALLED_APPS = [ |
| 13 | + ..., |
| 14 | + 'django_async_orm' |
| 15 | +] |
| 16 | +``` |
| 17 | +# Usage |
| 18 | + |
| 19 | +Django Async Orm will patch all your existing models to add `async_*` prefixed methods. |
| 20 | +To be |
| 21 | + |
| 22 | +example: |
| 23 | + |
| 24 | +```python |
| 25 | +class MyModel(models.Model): |
| 26 | + name = models.CharField(max_length=250) |
| 27 | + |
| 28 | +``` |
| 29 | + |
| 30 | +you can use it as follow: |
| 31 | + |
| 32 | +```python |
| 33 | +async def get_model(): |
| 34 | + return await MyModel.objects.async_get(name="something") |
| 35 | +``` |
| 36 | + |
| 37 | +you can also iterate over a query set with `async for`: |
| 38 | + |
| 39 | +```python |
| 40 | +async def all_models(): |
| 41 | + all_result_set = await MyModel.objects.async_all() |
| 42 | + async for obj in all_result_set: |
| 43 | + print(obj) |
| 44 | +``` |
| 45 | + |
| 46 | +Some wrappers are also available for template rendering, form validation and login/logout |
| 47 | + |
| 48 | + |
| 49 | +#### Async login |
| 50 | +```python |
| 51 | +from django_async_orm.wrappers import async_login |
| 52 | + |
| 53 | +async def my_async_view(request): |
| 54 | + await async_login(request) |
| 55 | + ... |
| 56 | +``` |
| 57 | + |
| 58 | +#### Form validation |
| 59 | +```python |
| 60 | + |
| 61 | +from django_async_orm.wrappers import async_form_is_valid |
| 62 | +async def a_view(request): |
| 63 | + form = MyForm(request.POST) |
| 64 | + is_valid_form = await async_form_is_valid(form) |
| 65 | + if is_valid_form: |
| 66 | + ... |
| 67 | + |
| 68 | +``` |
| 69 | + |
| 70 | + |
| 71 | +# Django ORM support: |
| 72 | + |
| 73 | +This is an on going projects, not all model methods are ported. |
| 74 | + |
| 75 | +### Manager: |
| 76 | + |
| 77 | +| methods | supported | comments | |
| 78 | +|----------------------------|------------|----------| |
| 79 | +| `Model.objects.async_get` | ✅ | | |
| 80 | +| `Model.objects.async_create` | ✅ | | |
| 81 | +| `Model.objects.async_bulk_create` | ✅ | | |
| 82 | +| `Model.objects.async_bulk_update` | ✅ | | |
| 83 | +| `Model.objects.async_get_or_create` | ✅ | | |
| 84 | +| `Model.objects.async_update_or_create` | ✅ | | |
| 85 | +| `Model.objects.async_earliest` | ✅ | | |
| 86 | +| `Model.objects.async_latest` | ✅ | | |
| 87 | +| `Model.objects.async_first` | ✅ | | |
| 88 | +| `Model.objects.async_last` | ✅ | | |
| 89 | +| `Model.objects.async_in_bulk` | ✅ | | |
| 90 | +| `Model.objects.async_delete` | ✅ | | |
| 91 | +| `Model.objects.async_update` | ✅ | | |
| 92 | +| `Model.objects.async_exists` | ✅ | | |
| 93 | +| `Model.objects.async_explain` | ✅ | | |
| 94 | +| `Model.objects.async_raw` | ✅ | | |
| 95 | +| `Model.objects.async_all` | ✅ | | |
| 96 | +| `Model.objects.async_filter` | ✅ | | |
| 97 | +| `Model.objects.async_exclude` | ✅ | | |
| 98 | +| `Model.objects.async_complex_filter` | ✅ | | |
| 99 | +| `Model.objects.async_union` | ✅ | | |
| 100 | +| `Model.objects.async_intersection` | ✅ | | |
| 101 | +| `Model.objects.async_difference` | ✅ | | |
| 102 | +| `Model.objects.async_select_for_update` | ✅ | | |
| 103 | +| `Model.objects.async_prefetch_related` | ✅ | | |
| 104 | +| `Model.objects.async_annotate` | ✅ | | |
| 105 | +| `Model.objects.async_order_by` | ✅ | | |
| 106 | +| `Model.objects.async_distinct` | ✅ | | |
| 107 | +| `Model.objects.async_difference` | ✅ | | |
| 108 | +| `Model.objects.async_extra` | ✅ | | |
| 109 | +| `Model.objects.async_reverse` | ✅ | | |
| 110 | +| `Model.objects.async_defer` | ✅ | | |
| 111 | +| `Model.objects.async_only` | ✅ | | |
| 112 | +| `Model.objects.async_using` | ✅ | | |
| 113 | +| `Model.objects.async_resolve_expression` | ✅ | | |
| 114 | +| `Model.objects.async_ordered` | ✅ | | |
| 115 | +| `__aiter__` | ✅ | | |
| 116 | +| `__repr__` | ✅ | | |
| 117 | + |
| 118 | + |
| 119 | +### Model: |
| 120 | + |
| 121 | +| methods | supported | comments | |
| 122 | +|----------------------------|------------|----------| |
| 123 | +| `Model.async_save` | ❌ | | |
| 124 | +| `Model.async_update` | ❌ | | |
| 125 | +| `Model.async_delete` | ❌ | | |
| 126 | +| `...` | ❌ | | |
| 127 | + |
| 128 | + |
| 129 | +### User Model |
| 130 | +| methods | supported | comments | |
| 131 | +|----------------------------|------------|----------| |
| 132 | +| `UserModel.is_authenticated` | ❌ | | |
| 133 | +| `UserModel.is_super_user` | ❌ | | |
| 134 | +| `...` | ❌ | | |
| 135 | + |
| 136 | + |
| 137 | +### Foreign object lazy loading: |
| 138 | +Not supported ❌ |
| 139 | + |
| 140 | + |
| 141 | +### Wrappers: |
| 142 | +| methods | supported | comments | |
| 143 | +|----------------------------|------------|----------| |
| 144 | +| `wrappers.async_render` | ✅ | | |
| 145 | +| `wrappers.async_login` | ✅ | | |
| 146 | +| `wrappers.async_logout` | ✅ | | |
| 147 | + |
| 148 | + |
| 149 | + |
0 commit comments