Skip to content

Commit 426d9b5

Browse files
committed
adding new sqlalchemy code examples
1 parent 4b6ffa0 commit 426d9b5

File tree

127 files changed

+1252
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1252
-264
lines changed

content/pages/examples/sqlalchemy/sqlalchemy-dialects-mssql.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: sqlalchemy.dialects mssql code examples
1+
title: sqlalchemy.dialects mssql Example Code
22
category: page
33
slug: sqlalchemy-dialects-mssql-examples
44
sortorder: 500031000
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
title: sqlalchemy.dialects.mysql pymysql Example Code
2+
category: page
3+
slug: sqlalchemy-dialects-mysql-pymysql-examples
4+
sortorder: 500031005
5+
toc: False
6+
sidebartitle: sqlalchemy.dialects.mysql pymysql
7+
meta: Python example code for the pymysql callable from the sqlalchemy.dialects.mysql module of the SQLAlchemy project.
8+
9+
10+
pymysql is a callable within the sqlalchemy.dialects.mysql module of the SQLAlchemy project.
11+
12+
13+
## Example 1 from databases
14+
[databases](https://github.com/encode/databases)
15+
([project homepage](https://www.encode.io/databases/)
16+
and
17+
[PyPI page](https://pypi.org/project/databases/) provides
18+
[asyncio](https://docs.python.org/3/library/asyncio.html) support
19+
with an [SQLALchemy](/sqlalchemy.html) Core interface for common
20+
[relational databases](/databases.html) such as [MySQL](/mysql.html),
21+
[PostgreSQL](/postgresql.html) and [SQLite](/sqlite.html). This is
22+
handy for integrating with asynchronous I/O
23+
[web frameworks](/web-frameworks.html) like [Sanic](/sanic.html).
24+
The project is open sourced under the
25+
[BSD 3-Clause "New" or "Revised" License](https://github.com/encode/databases/blob/master/LICENSE.md).
26+
27+
[**databases / databases / backends / mysql.py**](https://github.com/encode/databases/blob/master/databases/backends/mysql.py)
28+
29+
```python
30+
# mysql.py
31+
import getpass
32+
import logging
33+
import typing
34+
import uuid
35+
36+
import aiomysql
37+
~~from sqlalchemy.dialects.mysql import pymysql
38+
from sqlalchemy.engine.interfaces import Dialect, ExecutionContext
39+
from sqlalchemy.engine.result import ResultMetaData, RowProxy
40+
from sqlalchemy.sql import ClauseElement
41+
from sqlalchemy.types import TypeEngine
42+
43+
from databases.core import LOG_EXTRA, DatabaseURL
44+
from databases.interfaces import ConnectionBackend, DatabaseBackend, TransactionBackend
45+
46+
logger = logging.getLogger("databases")
47+
48+
49+
class MySQLBackend(DatabaseBackend):
50+
def __init__(
51+
self, database_url: typing.Union[DatabaseURL, str], **options: typing.Any
52+
) -> None:
53+
self._database_url = DatabaseURL(database_url)
54+
self._options = options
55+
~~ self._dialect = pymysql.dialect(paramstyle="pyformat")
56+
self._dialect.supports_native_decimal = True
57+
self._pool = None
58+
59+
def _get_connection_kwargs(self) -> dict:
60+
url_options = self._database_url.options
61+
62+
kwargs = {}
63+
min_size = url_options.get("min_size")
64+
max_size = url_options.get("max_size")
65+
ssl = url_options.get("ssl")
66+
67+
if min_size is not None:
68+
kwargs["minsize"] = int(min_size)
69+
if max_size is not None:
70+
kwargs["maxsize"] = int(max_size)
71+
if ssl is not None:
72+
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
73+
74+
for key, value in self._options.items():
75+
if key == "min_size":
76+
key = "minsize"
77+
elif key == "max_size":
78+
key = "maxsize"
79+
kwargs[key] = value
80+
81+
82+
## ... source file continues with no further pymysql examples...
83+
84+
```
85+

content/pages/examples/sqlalchemy/sqlalchemy-dialects-mysql.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: sqlalchemy.dialects mysql code examples
1+
title: sqlalchemy.dialects mysql Example Code
22
category: page
33
slug: sqlalchemy-dialects-mysql-examples
44
sortorder: 500031001

content/pages/examples/sqlalchemy/sqlalchemy-dialects-oracle.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: sqlalchemy.dialects oracle code examples
1+
title: sqlalchemy.dialects oracle Example Code
22
category: page
33
slug: sqlalchemy-dialects-oracle-examples
44
sortorder: 500031002

content/pages/examples/sqlalchemy/sqlalchemy-dialects-postgresql-array.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
title: sqlalchemy.dialects.postgresql ARRAY code examples
1+
title: sqlalchemy.dialects.postgresql ARRAY Example Code
22
category: page
33
slug: sqlalchemy-dialects-postgresql-array-examples
4-
sortorder: 500031005
4+
sortorder: 500031006
55
toc: False
66
sidebartitle: sqlalchemy.dialects.postgresql ARRAY
77
meta: Python example code for the ARRAY constant from the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.

content/pages/examples/sqlalchemy/sqlalchemy-dialects-postgresql-base-pgtypecompiler.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
title: sqlalchemy.dialects.postgresql.base PGTypeCompiler code examples
1+
title: sqlalchemy.dialects.postgresql.base PGTypeCompiler Example Code
22
category: page
33
slug: sqlalchemy-dialects-postgresql-base-pgtypecompiler-examples
4-
sortorder: 500031013
4+
sortorder: 500031015
55
toc: False
66
sidebartitle: sqlalchemy.dialects.postgresql.base PGTypeCompiler
77
meta: Python example code for the PGTypeCompiler class from the sqlalchemy.dialects.postgresql.base module of the SQLAlchemy project.

content/pages/examples/sqlalchemy/sqlalchemy-dialects-postgresql-bigint.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
title: sqlalchemy.dialects.postgresql BIGINT code examples
1+
title: sqlalchemy.dialects.postgresql BIGINT Example Code
22
category: page
33
slug: sqlalchemy-dialects-postgresql-bigint-examples
4-
sortorder: 500031006
4+
sortorder: 500031007
55
toc: False
66
sidebartitle: sqlalchemy.dialects.postgresql BIGINT
77
meta: Python example code for the BIGINT constant from the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.

content/pages/examples/sqlalchemy/sqlalchemy-dialects-postgresql-bit.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
title: sqlalchemy.dialects.postgresql BIT code examples
1+
title: sqlalchemy.dialects.postgresql BIT Example Code
22
category: page
33
slug: sqlalchemy-dialects-postgresql-bit-examples
4-
sortorder: 500031007
4+
sortorder: 500031008
55
toc: False
66
sidebartitle: sqlalchemy.dialects.postgresql BIT
77
meta: Python example code for the BIT constant from the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.

content/pages/examples/sqlalchemy/sqlalchemy-dialects-postgresql-double-precision.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
title: sqlalchemy.dialects.postgresql DOUBLE_PRECISION code examples
1+
title: sqlalchemy.dialects.postgresql DOUBLE_PRECISION Example Code
22
category: page
33
slug: sqlalchemy-dialects-postgresql-double-precision-examples
4-
sortorder: 500031008
4+
sortorder: 500031009
55
toc: False
66
sidebartitle: sqlalchemy.dialects.postgresql DOUBLE_PRECISION
77
meta: Python example code for the DOUBLE_PRECISION constant from the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.

content/pages/examples/sqlalchemy/sqlalchemy-dialects-postgresql-excludeconstraint.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
title: sqlalchemy.dialects.postgresql ExcludeConstraint code examples
1+
title: sqlalchemy.dialects.postgresql ExcludeConstraint Example Code
22
category: page
33
slug: sqlalchemy-dialects-postgresql-excludeconstraint-examples
4-
sortorder: 500031009
4+
sortorder: 500031010
55
toc: False
66
sidebartitle: sqlalchemy.dialects.postgresql ExcludeConstraint
77
meta: Python example code for the ExcludeConstraint class from the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.

0 commit comments

Comments
 (0)