-
Notifications
You must be signed in to change notification settings - Fork 32
docs: Adding documentation for GA #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c263f83
changes to docs for sphinx
asthamohta a89d722
Merge branch 'googleapis:master' into docs
asthamohta 00f2beb
remvoing warnings
asthamohta a27af9d
Merge branch 'docs' of github.com:asthamohta/python-spanner-django in…
asthamohta 6b3f305
adding sample code
asthamohta 35b2bad
linting
asthamohta 9cabe18
modifying import settings
asthamohta 45f9841
settings changes
asthamohta e198050
line accidently deleted in creation.py
asthamohta 2bb067b
lint_setup_py test
asthamohta cd65164
adding new lines and making changes to read me
asthamohta 63e51ee
Merge branch 'master' into docs
vi3k6i5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,37 @@ | ||
| Cloud Spanner support for Django | ||
| ================================ | ||
|
|
||
| `Cloud Spanner`_ is the world's first fully managed relational database service | ||
| to offer both strong consistency and horizontal scalability for | ||
| mission-critical online transaction processing (OLTP) applications. With Cloud | ||
| Spanner you enjoy all the traditional benefits of a relational database; but | ||
| unlike any other relational database service, Cloud Spanner scales horizontally | ||
| to hundreds or thousands of servers to handle the biggest transactional | ||
| workloads. | ||
|
|
||
|
|
||
| - `Client Library Documentation`_ | ||
| - `Product Documentation`_ | ||
|
|
||
| .. _Cloud Spanner: https://cloud.google.com/spanner/ | ||
| .. _Client Library Documentation: https://googleapis.dev/python/django-google-spanner/latest/index.html | ||
| .. _Product Documentation: https://cloud.google.com/spanner/docs | ||
|
|
||
| Quick Start | ||
| ----------- | ||
|
|
||
| In order to use this library, you first need to go through the following steps: | ||
|
|
||
| 1. `Select or create a Cloud Platform project.`_ | ||
| 2. `Enable billing for your project.`_ | ||
| 3. `Enable the Google Cloud Spanner API.`_ | ||
| 4. `Setup Authentication.`_ | ||
|
|
||
| .. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project | ||
| .. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project | ||
| .. _Enable the Google Cloud Spanner API.: https://cloud.google.com/spanner | ||
| .. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html | ||
|
|
||
| This package provides a `3rd-party database backend | ||
| <https://docs.djangoproject.com/en/2.2/ref/databases/#using-a-3rd-party-database-backend>`__ | ||
| for using `Cloud Spanner <https://cloud.google.com/spanner>`__ with the `Django | ||
|
|
@@ -11,10 +42,40 @@ under the hood. | |
| Installation | ||
| ------------ | ||
|
|
||
| To use this library, you'll need a Google Cloud Platform project with the Cloud | ||
| Spanner API enabled. For details on enabling the API and authenticating with | ||
| GCP, see the `Cloud Spanner Python client library quickstart guide | ||
| <https://github.com/googleapis/python-spanner/#quick-start>`__. | ||
| Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to | ||
| create isolated Python and Django environments. The basic problem it addresses is one of | ||
| dependencies and versions, and indirectly permissions. | ||
|
|
||
| With `virtualenv`_, it's possible to install this library without needing system | ||
| install permissions, and without clashing with the installed system | ||
| dependencies. | ||
|
|
||
| .. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ | ||
|
|
||
|
|
||
| Mac/Linux | ||
| ~~~~~~~~~ | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| pip install virtualenv | ||
| virtualenv <your-env> | ||
| source <your-env>/bin/activate | ||
| <your-env>/bin/pip install python-spanner-django | ||
| <your-env>/bin/pip install google-cloud-spanner | ||
|
|
||
|
|
||
| Windows | ||
| ~~~~~~~ | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| pip install virtualenv | ||
| virtualenv <your-env> | ||
| <your-env>\Scripts\activate | ||
| <your-env>\Scripts\pip.exe install python-spanner-django | ||
| <your-env>\Scripts\pip.exe install google-cloud-spanner | ||
|
|
||
|
|
||
| Supported versions | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
@@ -93,52 +154,104 @@ configured: | |
| } | ||
|
|
||
|
|
||
| Set credentials and project environment variables | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| You'll need to download a service account JSON key file and point to it using an environment variable: | ||
|
|
||
| .. code:: shell | ||
|
|
||
| export GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json | ||
| export GOOGLE_CLOUD_PROJECT=gcloud_project | ||
|
|
||
|
|
||
| Apply the migrations | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Please run: | ||
|
|
||
| .. code:: shell | ||
|
|
||
| $ python3 manage.py migrate | ||
|
|
||
| and that'll take a while to run. After this you should be able to see the tables and indices created in your Cloud Spanner console. | ||
|
|
||
| Now run your server | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
| After those migrations are completed, that will be all. Please continue on with the guides. | ||
|
|
||
| Create an Django admin user | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| First you’ll need to create a user who can login to the admin site. Run the following command: | ||
|
|
||
| .. code:: shell | ||
|
|
||
| $ python3 manage.py createsuperuser | ||
|
|
||
| which will then produce a prompt which will allow you to create your super user | ||
|
|
||
| .. code:: shell | ||
|
|
||
| Username: admin | ||
| Email address: [email protected] | ||
| Password: ********** | ||
| Password (again): ********** | ||
| Superuser created successfully. | ||
|
|
||
|
|
||
| Login as admin | ||
| ~~~~~~~~~~~~~~ | ||
| Let’s run the server | ||
|
|
||
| .. code:: shell | ||
|
|
||
| python3 manage.py runserver | ||
|
|
||
| Then visit http://127.0.0.1:8000/admin/ | ||
|
|
||
| Create and register your first model | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Please follow the guides in https://docs.djangoproject.com/en/2.2/intro/tutorial02/#creating-models | ||
| to create and register the model to the Django’s automatically-generated admin site. | ||
|
|
||
| How it works | ||
| ------------ | ||
|
|
||
| Overall design | ||
| ~~~~~~~~~~~~~~ | ||
|
|
||
| .. figure:: ./assets/overview.png | ||
| :alt: | ||
| .. figure:: https://raw.githubusercontent.com/googleapis/python-spanner-django/master/assets/overview.png | ||
| :alt: "Overall Design" | ||
|
|
||
| Internals | ||
| ~~~~~~~~~ | ||
|
|
||
| .. figure:: ./assets/internals.png | ||
| :alt: | ||
|
|
||
| .. figure:: https://raw.githubusercontent.com/googleapis/python-spanner-django/master/assets/internals.png | ||
| :alt: "Internals" | ||
|
|
||
|
|
||
| Executing a query | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. code:: python | ||
|
|
||
| from google.cloud.spanner_dbapi import connect | ||
| Here is an example of how to add a row for Model Author, save it and later query it using Django | ||
|
|
||
| connection = connect('<instance_id>', '<database_id>') | ||
| cursor = connection.cursor() | ||
|
|
||
| cursor.execute( | ||
| "SELECT *" | ||
| "FROM Singers" | ||
| "WHERE SingerId = 15" | ||
| ) | ||
| .. code:: shell | ||
|
|
||
| results = cursor.fetchall() | ||
| >>> author_kent = Author( first_name="Arthur", last_name="Kent", rating=Decimal("4.1"),) | ||
| >>> author_kent.save() | ||
| >>> qs1 = Author.objects.all().values("first_name", "last_name") | ||
|
|
||
|
|
||
| Contributing | ||
| ------------ | ||
| HOW TO CONTRIBUTE | ||
| ----------------- | ||
|
|
||
| Contributions to this library are always welcome and highly encouraged. | ||
|
|
||
| See [CONTRIBUTING][contributing] for more information on how to get started. | ||
| See `CONTRIBUTING <https://github.com/googleapis/python-spanner-django/blob/master/CONTRIBUTING.md>`_ for more information on how to get started. | ||
|
|
||
| Please note that this project is released with a Contributor Code of Conduct. | ||
| By participating in this project you agree to abide by its terms. See the `Code | ||
| of Conduct <code-of-conduct.md>`_ for more information. | ||
| By participating in this project you agree to abide by its terms. See the `Code | ||
| of Conduct <https://github.com/googleapis/python-spanner-django/blob/master/CODE_OF_CONDUCT.md>`_ for more information. | ||
|
|
||
| Current limitations | ||
| ------------------- | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Base API | ||
| ===================== | ||
|
|
||
| .. automodule:: django_spanner.base | ||
| :members: | ||
| :inherited-members: | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Compiler API | ||
| ===================== | ||
|
|
||
| .. automodule:: django_spanner.compiler | ||
| :members: | ||
| :inherited-members: | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Creation API | ||
| ===================== | ||
|
|
||
| .. automodule:: django_spanner.creation | ||
| :members: | ||
| :inherited-members: | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Expressions API | ||
| ===================== | ||
|
|
||
| .. automodule:: django_spanner.expressions | ||
| :members: | ||
| :inherited-members: | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Functions API | ||
| ===================== | ||
|
|
||
| .. automodule:: django_spanner.functions | ||
| :members: | ||
| :inherited-members: | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.