Skip to content

Commit 9964b07

Browse files
committed
Use templates for links, stop manually word wrapping
1 parent 46faa67 commit 9964b07

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

docs/advanced/column-types.md

+13-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# Column Types
22

3-
In the tutorial, we stored scalar data types in our tables, like strings, numbers and timestamps. In practice, we often
4-
work with more complicated types that need to be converted to a data type our database supports.
3+
In the tutorial, we stored scalar data types in our tables, like strings, numbers and timestamps. In practice, we often work with more complicated types that need to be converted to a data type our database supports.
54

65
## Customising String Field Lengths
76

8-
As we discussed in [`TEXT` or `VARCHAR`](../tutorial/create-db-and-table.md#text-or-varchar), a `str` field type will be
9-
created as a `VARCHAR`, which has varying maximum-lengths depending on the database engine you are using.
7+
As we discussed in [`TEXT` or `VARCHAR`](../tutorial/create-db-and-table.md#text-or-varchar), a `str` field type will be created as a `VARCHAR`, which has varying maximum-lengths depending on the database engine you are using.
108

11-
For cases where you know you only need to store a certain length of text, string field maximum length can be reduced
12-
using the `max_length` validation argument to `Field()`:
9+
For cases where you know you only need to store a certain length of text, string field maximum length can be reduced using the `max_length` validation argument to `Field()`:
1310

1411
```Python hl_lines="11"
1512
{!./docs_src/advanced/column_types/tutorial001.py[ln:1-12]!}
@@ -25,35 +22,28 @@ using the `max_length` validation argument to `Field()`:
2522

2623
/// warning
2724

28-
Database engines behave differently when you attempt to store longer text than the character length of the `VARCHAR`
29-
column. Notably:
25+
Database engines behave differently when you attempt to store longer text than the character length of the `VARCHAR` column. Notably:
3026

3127
* SQLite does not enforce the length of a `VARCHAR`. It will happily store up to 500-million characters of text.
3228
* MySQL will emit a warning, but will also truncate your text to fit the size of the `VARCHAR`.
3329
* PostgreSQL will respond with an error code, and your query will not be executed.
3430

3531
///
3632

37-
However if you need to store much longer strings than `VARCHAR` can allow, databases provide `TEXT` or `CLOB`
38-
(**c**haracter **l**arge **ob**ject) column types. We can use these by specifying an SQLAlchemy column type to the field
39-
with the `sa_type` keyword argument:
33+
However if you need to store much longer strings than `VARCHAR` can allow, databases provide `TEXT` or `CLOB` (**c**haracter **l**arge **ob**ject) column types. We can use these by specifying an SQLAlchemy column type to the field with the `sa_type` keyword argument:
4034

4135
```Python hl_lines="12"
4236
{!./docs_src/advanced/column_types/tutorial001.py[ln:5-45]!}
4337
```
4438

4539
/// tip
4640

47-
`Text` also accepts a character length argument, which databases use to optimise the storage of a particular field.
48-
Some databases support `TINYTEXT`, `SMALLTEXT`, `MEDIUMTEXT` and `LONGTEXT` column types - ranging from 255 bytes to
49-
4 gigabytes. If you know the maximum length of data, specifying it like `Text(1000)` will automatically select the
50-
best-suited, supported type for your database engine.
41+
`Text` also accepts a character length argument, which databases use to optimise the storage of a particular field. Some databases support `TINYTEXT`, `SMALLTEXT`, `MEDIUMTEXT` and `LONGTEXT` column types - ranging from 255 bytes to 4 gigabytes. If you know the maximum length of data, specifying it like `Text(1000)` will automatically select the best-suited, supported type for your database engine.
5142

5243
///
5344

5445

55-
With this approach, we can use [any kind of SQLAlchemy type](https://docs.sqlalchemy.org/en/20/core/type_basics.html).
56-
For example, if we were building a mapping application, we could store spatial information:
46+
With this approach, we can use [any kind of SQLAlchemy type](https://docs.sqlalchemy.org/en/20/core/type_basics.html). For example, we can store pickled objects in the database:
5747

5848
```Python
5949
{!./docs_src/advanced/column_types/tutorial002.py!}
@@ -121,40 +111,37 @@ Note that while the column types for these are `VARCHAR`, values are not convert
121111

122112
### IP Addresses
123113

124-
IP Addresses from the <a href="https://docs.python.org/3/library/ipaddress.html" class="external-link" target="_blank">Python `ipaddress` module</a> are stored as text.
114+
IP Addresses from the [Python `ipaddress` module](https://docs.python.org/3/library/ipaddress.html){.external-link target=_blank} are stored as text.
125115

126116
```Python hl_lines="5 11"
127117
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
128118
```
129119

130120
### Filesystem Paths
131121

132-
Paths to files and directories using the <a href="https://docs.python.org/3/library/pathlib.html" class="external-link" target="_blank">Python `pathlib` module</a> are stored as text.
122+
Paths to files and directories using the [Python `pathlib` module](https://docs.python.org/3/library/pathlib.html){.external-link target=_blank} are stored as text.
133123

134124
```Python hl_lines="2 12"
135125
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
136126
```
137127

138128
/// tip
139129

140-
The stored value of a Path is the basic string value: `str(Path('../path/to/file'))`. If you need to store the full path
141-
ensure you call `absolute()` on the path before setting it in your model.
130+
The stored value of a Path is the basic string value: `str(Path('../path/to/file'))`. If you need to store the full path ensure you call `absolute()` on the path before setting it in your model.
142131

143132
///
144133

145134
### UUIDs
146135

147-
UUIDs from the <a href="https://docs.python.org/3/library/uuid.html" class="external-link" target="_blank">Python `uuid`
148-
module</a> are stored as `UUID` types in supported databases (just PostgreSQL at the moment), otherwise as a `CHAR(32)`.
136+
UUIDs from the [Python `uuid` module](https://docs.python.org/3/library/uuid.html){.external-link target=_blank} are stored as native `UUID` types in supported databases (just PostgreSQL at the moment), otherwise as a `CHAR(32)`.
149137

150138
```Python hl_lines="3 10"
151139
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
152140
```
153141

154142
### Email Addresses
155143

156-
Email addresses using <a href="https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.EmailStr" class="external-link" target="_blank">Pydantic's `EmailStr` type</a>
157-
are stored as strings.
144+
Email addresses using [Pydantic's `EmailStr` type](https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.EmailStr){.external-link target=_blank} are stored as strings.
158145

159146
```Python hl_lines="5 14"
160147
{!./docs_src/advanced/column_types/tutorial003.py[ln:1-15]!}
@@ -163,6 +150,4 @@ are stored as strings.
163150

164151
## Custom Pydantic types
165152

166-
As SQLModel is built on Pydantic, you can use any custom type as long as it would work in a Pydantic model. However, if
167-
the type is not a subclass of [a type from the table above](#supported-types), you will need to specify an SQLAlchemy
168-
type to use.
153+
As SQLModel is built on Pydantic, you can use any custom type as long as it would work in a Pydantic model. However, if the type is not a subclass of [a type from the table above](#supported-types), you will need to specify an SQLAlchemy type to use.

0 commit comments

Comments
 (0)