Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a3ccbac

Browse filesBrowse files
authored
docs: reformatted README titles (googleapis#141)
1 parent 05aa31e commit a3ccbac
Copy full SHA for a3ccbac

File tree

Expand file treeCollapse file tree

1 file changed

+25
-28
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-28
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+25-28Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ This project has **Preview** release status. Known limitations are listed [here]
99
- [Cloud Spanner product documentation](https://cloud.google.com/spanner/docs)
1010
- [SQLAlchemy product documentation](https://www.sqlalchemy.org/)
1111

12-
Quick Start
13-
-----------
12+
## Quick Start
1413

1514
In order to use this package, you first need to go through the following steps:
1615

@@ -19,8 +18,7 @@ In order to use this package, you first need to go through the following steps:
1918
3. [Enable the Google Cloud Spanner API.](https://cloud.google.com/spanner)
2019
4. [Setup Authentication.](https://googleapis.dev/python/google-api-core/latest/auth.html)
2120

22-
Installation
23-
-----------
21+
## Installation
2422

2523
To install an in-development version of the package, clone its Git-repository:
2624
```
@@ -32,9 +30,9 @@ python setup.py install
3230
```
3331
During setup the dialect will be registered with entry points.
3432

35-
A Minimal App
36-
-----------
37-
**Create a table**
33+
## A Minimal App
34+
35+
### Create a table
3836
```python
3937
from sqlalchemy import (
4038
Column,
@@ -59,7 +57,8 @@ user = Table(
5957

6058
metadata.create_all(engine)
6159
```
62-
**Insert a row**
60+
61+
### Insert a row
6362
```python
6463
from sqlalchemy import (
6564
MetaData,
@@ -76,7 +75,7 @@ with engine.begin() as connection:
7675
connection.execute(user.insert(), {"user_id": 1, "user_name": "Full Name"})
7776
```
7877

79-
**Read**
78+
### Read
8079
```python
8180
from sqlalchemy import MetaData, Table, create_engine, select
8281

@@ -90,16 +89,16 @@ with engine.begin() as connection:
9089
print(row)
9190
```
9291

93-
Migration
94-
-----------
92+
## Migration
93+
9594
SQLAlchemy uses [Alembic](https://alembic.sqlalchemy.org/en/latest/#) tool to organize database migrations.
9695

9796
**Warning!**
9897
A migration script can produce a lot of DDL statements. If each of the statements are executed separately, performance issues can occur. To avoid these, it's highly recommended to use the [Alembic batch context](https://alembic.sqlalchemy.org/en/latest/batch.html) feature to pack DDL statements into groups of statements.
9998

100-
Features and limitations
101-
-----------
102-
**Interleaved tables**
99+
## Features and limitations
100+
101+
### Interleaved tables
103102
Cloud Spanner dialect includes two dialect-specific arguments for `Table` constructor, which help to define interleave relations:
104103
`spanner_interleave_in` - a parent table name
105104
`spanner_inverleave_on_delete_cascade` - a flag specifying if `ON DELETE CASCADE` statement must be used for the interleave relation
@@ -126,7 +125,7 @@ client = Table(
126125
client.create(engine)
127126
```
128127

129-
**Unique constraints**
128+
### Unique constraints
130129
Cloud Spanner doesn't support direct UNIQUE constraints creation. In order to achieve column values uniqueness UNIQUE indexes should be used.
131130

132131
Instead of direct UNIQUE constraint creation:
@@ -147,7 +146,7 @@ Table(
147146
Index("uix_1", "col1", unique=True),
148147
)
149148
```
150-
**Autocommit mode**
149+
### Autocommit mode
151150
Spanner dialect supports both `SERIALIZABLE` and `AUTOCOMMIT` isolation levels. `SERIALIZABLE` is the default one, where transactions need to be committed manually. `AUTOCOMMIT` mode corresponds to automatically committing of a query right in its execution time.
152151

153152
Isolation level change example:
@@ -158,7 +157,7 @@ eng = create_engine("spanner:///projects/project-id/instances/instance-id/databa
158157
autocommit_engine = eng.execution_options(isolation_level="AUTOCOMMIT")
159158
```
160159

161-
**ReadOnly transactions**
160+
### ReadOnly transactions
162161
By default, transactions produced by a Spanner connection are in ReadWrite mode. However, some applications require an ability to grant ReadOnly access to users/methods; for these cases Spanner dialect supports the `read_only` execution option, which switches a connection into ReadOnly mode:
163162
```python
164163
with engine.connect().execution_options(read_only=True) as connection:
@@ -168,13 +167,13 @@ Note that execution options are applied lazily - on the `execute()` method call,
168167

169168
ReadOnly/ReadWrite mode of a connection can't be changed while a transaction is in progress - first you must commit or rollback it.
170169

171-
**DDL and transactions**
170+
### DDL and transactions
172171
DDL statements are executed outside the regular transactions mechanism, which means DDL statements will not be rolled back on normal transaction rollback.
173172

174-
**Dropping a table**
173+
### Dropping a table
175174
Cloud Spanner, by default, doesn't drop tables, which have secondary indexes and/or foreign key constraints. In Spanner dialect for SQLAlchemy, however, this restriction is omitted - if a table you are trying to delete has indexes/foreign keys, they will be dropped automatically right before dropping the table.
176175

177-
**Data types**
176+
### Data types
178177
Data types table mapping SQLAlchemy types to Cloud Spanner types:
179178

180179
| SQLAlchemy | Spanner |
@@ -193,14 +192,13 @@ Data types table mapping SQLAlchemy types to Cloud Spanner types:
193192
| NUMERIC | NUMERIC |
194193

195194

196-
**Other limitations**
195+
### Other limitations
197196
- WITH RECURSIVE statement is not supported.
198197
- Named schemas are not supported.
199198
- Temporary tables are not supported, real tables are used instead.
200199
- Numeric type dimensions (scale and precision) are constant. See the [docs](https://cloud.google.com/spanner/docs/data-types#numeric_types).
201200

202-
Best practices
203-
-----------
201+
## Best practices
204202
When a SQLAlchemy function is called, a new connection to a database is established and a Spanner session object is fetched. In case of connectionless execution these fetches are done for every `execute()` call, which can cause a significant latency. To avoid initiating a Spanner session on every `execute()` call it's recommended to write code in connection-bounded fashion. Once a `Connection()` object is explicitly initiated, it fetches a Spanner session object and uses it for all the following calls made on this `Connection()` object.
205203

206204
Non-optimal connectionless use:
@@ -216,8 +214,8 @@ with engine.begin() as connection:
216214
```
217215
Connectionless way of use is also deprecated since SQLAlchemy 2.0 and soon will be removed (see in [SQLAlchemy docs](https://docs.sqlalchemy.org/en/14/core/connections.html#connectionless-execution-implicit-execution)).
218216

219-
Running tests
220-
------------
217+
## Running tests
218+
221219
Spanner dialect includes a compliance, migration and unit test suite. To run the tests the `nox` package commands can be used:
222220
```
223221
# Run the whole suite
@@ -226,11 +224,10 @@ $ nox
226224
# Run a particular test session
227225
$ nox -s migration_test
228226
```
229-
**Running tests on Spanner emulator**
227+
### Running tests on Spanner emulator
230228
The dialect test suite can be runned on [Spanner emulator](https://cloud.google.com/spanner/docs/emulator). Several tests, relating to `NULL` values of data types, are skipped when executed on emulator.
231229

232-
Contributing
233-
------------
230+
## Contributing
234231

235232
Contributions to this library are welcome and encouraged. Please report issues, file feature requests, and send pull requests. See [CONTRIBUTING](https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy/blob/main/contributing.md) for more information on how to get
236233
started.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.