1
- django-spanner
2
- ==============
1
+ Cloud Spanner support for Django
2
+ ================================
3
3
4
- ORM plugin for using Cloud Spanner as a database for Django.
4
+ ORM plugin for using Cloud Spanner as a `database backend
5
+ <https://docs.djangoproject.com/en/2.2/ref/databases/#using-a-3rd-party-database-backend> `__
6
+ for Django.
5
7
6
- 🚨THIS CODE IS STILL UNDER DEVELOPMENT🚨
7
- ========================================
8
8
9
- Table of contents
10
- -----------------
11
-
12
- - `Installing it <#installing-it >`__
13
- - `Using it <#using-it >`__
14
-
15
- - `Format <#format >`__
16
- - `Example <#example >`__
9
+ Installation
10
+ ------------
17
11
18
- - `Functional tests <#functional-tests >`__
19
- - `Django integration tests <#django-integration-tests >`__
12
+ To use this library you'll need a Google Cloud Platform project with the Cloud
13
+ Spanner API enabled. See the `Cloud Spanner Python client docs
14
+ <https://github.com/googleapis/python-spanner/#quick-start> `__ for details.
20
15
21
- - `django\_ test\_ suite.sh <#django_test_suitesh >`__
16
+ Use the version of ``python-spanner-django `` that corresponds to your version
17
+ of Django. For example, ``python-spanner-django `` 2.2.x works with Django
18
+ 2.2.y. (This is the only supported version at this time.)
22
19
23
- - ` Environment variables < #environment-variables >`__
24
- - ` Example run < #example-run >`__
20
+ The minor release number of Django doesn't correspond to the minor release
21
+ number of `` python-spanner-django ``. Use the latest minor release of each.
25
22
26
- - ` Parallelization script < #parallelization-script >`__
23
+ To install from PyPI:
27
24
28
- - `Environment variables <#environment-variables >`__
29
- - `Example run <#example-run >`__
25
+ .. code :: shell
30
26
31
- - `Limitations <#limitations >`__
32
- - `How it works <#how-it-works >`__
27
+ pip3 install django-google-spanner
33
28
34
- - `Overall design <#overall-design >`__
35
- - `Internals <#internals >`__
36
29
37
- Installing it
38
- -------------
30
+ To install from source:
39
31
40
- Use the version of django-spanner that corresponds to your version of
41
- Django. For example, django-spanner 2.2.x works with Django 2.2.y. (This
42
- is the only supported version at this time.)
32
+ .. code :: shell
43
33
44
- The minor release number of Django doesn't correspond to the minor
45
- release number of django-spanner. Use the latest minor release of each.
34
+ git clone git@github.com:googleapis/python-spanner-django.git
35
+ cd python-spanner-django
36
+ pip3 install -e .
46
37
47
- .. code :: shell
48
38
49
- pip3 install --user .
39
+ Useage
40
+ ------
50
41
51
- Using it
52
- --------
42
+ After ` installattion < #Installation >`__, you'll need to edit your Django
43
+ `` settings.py `` file:
53
44
54
- After ` installing it < #installing-it >`__, you'll need to edit your
55
- Django `` settings.py `` file:
45
+ - Add `` django_spanner `` as the very first entry in the `` INSTALLED_APPS ``
46
+ setting
56
47
57
- - Add ``django_spanner `` as the very first entry in the
58
- ``INSTALLED_APPS `` setting
59
48
60
49
.. code :: python
61
50
@@ -107,18 +96,19 @@ Limitations
107
96
Transaction management isn't supported
108
97
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109
98
110
- django-spanner always works in Django's default transaction behavior,
111
- ``autocommit `` mode. Transactions cannot be controlled manually with
112
- calls like ``django.db.transaction.atomic() ``.
99
+ ``python-spanner-django `` always works in ``autocommit `` mode, which is
100
+ Django's default behavior even for backends that support manual transaction
101
+ management. Transactions cannot be controlled manually with calls like
102
+ ``django.db.transaction.atomic() ``.
113
103
114
104
``AutoField `` generates random IDs
115
105
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116
106
117
107
Spanner doesn't have support for auto-generating primary key values.
118
- Therefore, django -spanner monkey-patches ``AutoField `` to generate a
119
- random UUID4. It generates a default using ``Field ``'s ``default ``
120
- option which means ``AutoField ``\ s will have a value when a model
121
- instance is created. For example:
108
+ Therefore, `` python -spanner-django `` monkey-patches ``AutoField `` to generate a
109
+ random UUID4. It generates a default using ``Field ``'s ``default `` option which
110
+ means ``AutoField ``\ s will have a value when a model instance is created. For
111
+ example:
122
112
123
113
::
124
114
@@ -136,16 +126,18 @@ were created.
136
126
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137
127
138
128
Spanner doesn't support ``ON DELETE CASCADE `` when creating foreign-key
139
- constraints so django-spanner `doesn't support foreign key
140
- constraints <https://github.com/googleapis/python-spanner-django/issues/313> `__.
129
+ constraints so ``python-spanner-django `` `doesn't support foreign key
130
+ constraints
131
+ <https://github.com/googleapis/python-spanner-django/issues/313> `__.
141
132
142
133
Check constraints aren't supported
143
134
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144
135
145
136
Spanner doesn't support ``CHECK `` constraints so one isn't created for
146
- ```PositiveIntegerField `` <https://docs.djangoproject.com/en/stable/ref/models/fields/#positiveintegerfield>`__
147
- and
148
- ```CheckConstraint `` <https://docs.djangoproject.com/en/stable/ref/models/constraints/#checkconstraint>`__
137
+ `PositiveIntegerField
138
+ <https://docs.djangoproject.com/en/stable/ref/models/fields/#positiveintegerfield> `__
139
+ and `CheckConstraint
140
+ <https://docs.djangoproject.com/en/stable/ref/models/constraints/#checkconstraint> `__
149
141
can't be used.
150
142
151
143
``DecimalField `` isn't supported
@@ -185,7 +177,7 @@ Spanner has some limitations on schema changes which you must respect:
185
177
- Renaming tables and columns isn't supported.
186
178
- A column's type can't be changed.
187
179
- A table's primary key can't be altered.
188
- - Migrations aren't atomic since django -spanner doesn't support
180
+ - Migrations aren't atomic since `` python -spanner-django `` doesn't support
189
181
transactions.
190
182
191
183
``DurationField `` arithmetic doesn't work with ``DateField `` values (`#253 <https://github.com/googleapis/python-spanner-django/issues/253 >`__)
@@ -247,6 +239,3 @@ Internals
247
239
248
240
.. figure :: ./assets/internals.png
249
241
:alt:
250
-
251
- 🚨🚨THIS CODE IS STILL UNDER DEVELOPMENT🚨🚨
252
- ============================================
0 commit comments