Skip to content

Commit d70cb28

Browse files
authored
Docs: updated README.rst file (#563)
1 parent 7d193d3 commit d70cb28

File tree

4 files changed

+89
-143
lines changed

4 files changed

+89
-143
lines changed

README.rst

+88-102
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,35 @@ ORM plugin for using Cloud Spanner as a `database backend
55
<https://docs.djangoproject.com/en/2.2/ref/databases/#using-a-3rd-party-database-backend>`__
66
for Django.
77

8+
How it works
9+
------------
10+
11+
Overall design
12+
~~~~~~~~~~~~~~
13+
14+
.. figure:: ./assets/overview.png
15+
:alt:
16+
17+
Internals
18+
~~~~~~~~~
19+
20+
.. figure:: ./assets/internals.png
21+
:alt:
22+
823

924
Installation
1025
------------
1126

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
27+
Using this library requires a Google Cloud Platform project with the Cloud
28+
Spanner API enabled. See the Spanner Python client `documentation
1429
<https://github.com/googleapis/python-spanner/#quick-start>`__ for details.
1530

16-
Use the version of ``django-google-spanner`` that corresponds to your version
31+
The version of ``django-google-spanner`` must correspond to your version
1732
of Django. For example, ``django-google-spanner`` 2.2.x works with Django
18-
2.2.y. (This is the only supported version at this time.)
33+
2.2.y (Note: this is the only supported version at this time).
1934

20-
The minor release number of Django doesn't correspond to the minor release
21-
number of ``django-google-spanner``. Use the latest minor release of each.
35+
The minor release numbers of Django may not correspond to the minor release
36+
numbers of ``django-google-spanner``. Use the latest minor release of each.
2237

2338
To install from PyPI:
2439

@@ -36,15 +51,14 @@ To install from source:
3651
pip3 install -e .
3752
3853
39-
Usage
40-
-----
54+
Configuring ``settings.py``
55+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
4156

42-
After `installation <#Installation>`__, you'll need to edit your Django
43-
``settings.py`` file:
57+
After `installation <#Installation>`__, you'll have to update your Django
58+
``settings.py`` file as follows.
4459

4560
- Add ``django_spanner`` as the very first entry in the ``INSTALLED_APPS``
46-
setting
47-
61+
settings:
4862

4963
.. code:: python
5064
@@ -53,49 +67,43 @@ After `installation <#Installation>`__, you'll need to edit your Django
5367
...
5468
]
5569
56-
- Edit the ``DATABASES`` setting to point to an EXISTING database
57-
58-
Format
59-
~~~~~~
70+
- Edit the ``DATABASES`` settings to point to an EXISTING database, as shown in the following example:
6071

61-
.. code:: python
62-
63-
DATABASES = {
64-
'default': {
65-
'ENGINE': 'django_spanner',
66-
'PROJECT': '<project_id>',
67-
'INSTANCE': '<instance_id>',
68-
'NAME': '<database_name>',
69-
# Only include this if you need to specify where to retrieve the
70-
# service account JSON for the credentials to connect to Cloud Spanner.
71-
'OPTIONS': {
72-
'credentials_uri': '<credentials_uri>',
73-
},
74-
},
75-
}
76-
77-
Database configurations
78-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79-
80-
.. code:: python
81-
82-
DATABASES = {
83-
'default': {
84-
'ENGINE': 'django_spanner',
85-
'PROJECT': 'appdev-soda-spanner-staging', # Or the GCP project-id
86-
'INSTANCE': 'django-dev1', # Or the Cloud Spanner instance
87-
'NAME': 'db1', # Or the Cloud Spanner database to use
88-
}
89-
}
72+
.. code:: python
9073
91-
Execute a query
92-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74+
DATABASES = {
75+
'default': {
76+
'ENGINE': 'django_spanner',
77+
'PROJECT': '<GCP_project_id>',
78+
'INSTANCE': '<instance_id>',
79+
'NAME': '<database_name>',
80+
}
81+
}
82+
83+
- In order to retrieve the Cloud Spanner credentials from a JSON file, the ``credentials_uri`` parameter can also be supplied in the ``OPTIONS`` field:
84+
85+
.. code:: python
86+
87+
DATABASES = {
88+
'default': {
89+
'ENGINE': 'django_spanner',
90+
'PROJECT': '<GCP_project_id>',
91+
'INSTANCE': '<instance_id>',
92+
'NAME': '<database_name>',
93+
'OPTIONS': {
94+
'credentials_uri': '<credentials_uri>',
95+
},
96+
},
97+
}
98+
99+
Executing a query
100+
~~~~~~~~~~~~~~~~~
93101

94102
.. code:: python
95103
96104
from google.cloud.spanner_dbapi import connect
97105
98-
connection = connect("instance-id", "database-id")
106+
connection = connect('<instance_id>', '<database_id>')
99107
cursor = connection.cursor()
100108
101109
cursor.execute(
@@ -107,16 +115,8 @@ Execute a query
107115
results = cur.fetchall()
108116
109117
110-
Limitations
111-
-----------
112-
113-
Transaction management isn't supported
114-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115-
116-
``django-google-spanner`` always works in ``autocommit`` mode, which is
117-
Django's default behavior even for backends that support manual transaction
118-
management. Transactions cannot be controlled manually with calls like
119-
``django.db.transaction.atomic()``.
118+
Current limitations
119+
-------------------
120120

121121
``AutoField`` generates random IDs
122122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -139,34 +139,34 @@ these IDs are not monotonically increasing. This means that sorting
139139
models by ID isn't guaranteed to return them in the order in which they
140140
were created.
141141

142-
``ForeignKey`` constraints aren't created
143-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142+
``ForeignKey`` constraints aren't created (`#313 <https://github.com/googleapis/python-spanner-django/issues/313>`__)
143+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144144

145-
Spanner doesn't support ``ON DELETE CASCADE`` when creating foreign-key
146-
constraints so ``django-google-spanner`` `doesn't support foreign key
147-
constraints
148-
<https://github.com/googleapis/python-spanner-django/issues/313>`__.
145+
Spanner does not support ``ON DELETE CASCADE`` when creating foreign-key
146+
constraints, so this is not supported in ``django-google-spanner``.
149147

150148
Check constraints aren't supported
151149
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152150

153-
Spanner doesn't support ``CHECK`` constraints so one isn't created for
151+
Spanner does not support ``CHECK`` constraints so one isn't created for
154152
`PositiveIntegerField
155153
<https://docs.djangoproject.com/en/stable/ref/models/fields/#positiveintegerfield>`__
156154
and `CheckConstraint
157155
<https://docs.djangoproject.com/en/stable/ref/models/constraints/#checkconstraint>`__
158156
can't be used.
159157

160-
``DecimalField`` isn't supported
161-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158+
No native support for ``DecimalField``
159+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162160

163-
Spanner doesn't support a NUMERIC data type that allows storing high
164-
precision decimal values without the possibility of data loss.
161+
Spanner's support for `Decimal <https://www.python.org/dev/peps/pep-0327/>`__
162+
types is limited to
163+
`NUMERIC <https://cloud.google.com/spanner/docs/data-types#numeric_types>`__
164+
precision. Higher-precision values can be stored as strings instead.
165165

166166
``Variance`` and ``StdDev`` database functions aren't supported
167167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168168

169-
Spanner doesn't support these functions.
169+
Spanner does not support these functions.
170170

171171
``Meta.order_with_respect_to`` model option isn't supported
172172
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -177,7 +177,7 @@ This feature uses a column name that starts with an underscore
177177
Random ``QuerySet`` ordering isn't supported
178178
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179179

180-
Spanner doesn't support it. For example:
180+
Spanner does not support it and will throw an exception. For example:
181181

182182
::
183183

@@ -189,13 +189,11 @@ Spanner doesn't support it. For example:
189189
Schema migrations
190190
~~~~~~~~~~~~~~~~~
191191

192-
Spanner has some limitations on schema changes which you must respect:
192+
There are some limitations on schema changes to consider:
193193

194-
- Renaming tables and columns isn't supported.
195-
- A column's type can't be changed.
194+
- No support for renaming tables and columns;
195+
- A column's type can't be changed;
196196
- A table's primary key can't be altered.
197-
- Migrations aren't atomic since ``django-google-spanner`` doesn't support
198-
transactions.
199197

200198
``DurationField`` arithmetic doesn't work with ``DateField`` values (`#253 <https://github.com/googleapis/python-spanner-django/issues/253>`__)
201199
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -207,20 +205,23 @@ the column type:
207205
or ``TIMESTAMP_SUB``
208206
- ``DATE`` columns (``DateField``) require ``DATE_ADD`` or ``DATE_SUB``
209207

210-
Django doesn't provide a way to determine which database function to
211-
use. ``DatabaseOperations.combine_duration_expression()`` arbitrary uses
208+
Django does not provide ways to determine which database function to
209+
use. ``DatabaseOperations.combine_duration_expression()`` arbitrarily uses
212210
``TIMESTAMP_ADD`` and ``TIMESTAMP_SUB``. Therefore, if you use a
213-
``DateField`` in a ``DurationField`` expression, you'll see an error
214-
like: "No matching signature for function TIMESTAMP\_ADD for argument
215-
types: DATE, INTERVAL INT64 DATE\_TIME\_PART."
211+
``DateField`` in a ``DurationField`` expression, you'll likely see an error
212+
such as:
216213

217-
Computations that yield FLOAT64 values can't be assigned to INT64 columns
218-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214+
::
219215

220-
Spanner `doesn't support
221-
this <https://github.com/googleapis/python-spanner-django/issues/331>`__.
216+
"No matching signature for function TIMESTAMP\_ADD for argument types:
217+
DATE, INTERVAL INT64 DATE\_TIME\_PART."
222218

223-
For example, if ``integer`` is ``IntegerField``:
219+
Computations that yield FLOAT64 values cannot be assigned to INT64 columns
220+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221+
222+
Spanner does not support this (`#331
223+
<https://github.com/googleapis/python-spanner-django/issues/331>`__) and will
224+
throw an error:
224225

225226
::
226227

@@ -233,26 +234,11 @@ For example, if ``integer`` is ``IntegerField``:
233234
Addition with null values crash
234235
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235236

236-
For example:
237+
Additions cannot include ``None`` values. For example:
237238

238239
::
239240

240241
>>> Book.objects.annotate(adjusted_rating=F('rating') + None)
241242
...
242243
google.api_core.exceptions.InvalidArgument: 400 Operands of + cannot be literal
243244
NULL ...
244-
245-
How it works
246-
------------
247-
248-
Overall design
249-
~~~~~~~~~~~~~~
250-
251-
.. figure:: ./assets/overview.png
252-
:alt:
253-
254-
Internals
255-
~~~~~~~~~
256-
257-
.. figure:: ./assets/internals.png
258-
:alt:

docs/api-reference.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
API Reference
22
=============
33

4-
The following classes and methods constitute the Spanner DB API connection.
4+
The following classes and methods constitute the Django Spanner API.
55

66
[this page is under construction]

docs/connection-usage.rst

-32
This file was deleted.

docs/index.rst

-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
.. include:: README.rst
22

3-
Usage Documentation
4-
-------------------
5-
.. toctree::
6-
:maxdepth: 1
7-
:titlesonly:
8-
9-
connection-usage
10-
113
API Documentation
124
-----------------
135
.. toctree::

0 commit comments

Comments
 (0)