Skip to content

Commit 7dded51

Browse files
committed
docs: run blacken docs
1 parent b180deb commit 7dded51

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ repos:
4040
rev: "1.19.1"
4141
hooks:
4242
- id: blacken-docs
43+
args:
44+
- --line-length
45+
- '80'
4346
additional_dependencies:
4447
- black==22.12.0

README.md

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ DuckDB Engine also has a conda feedstock available, the instructions for the use
3636
Once you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search
3737

3838
```python
39-
from sqlalchemy import Column, Integer, Sequence, String, create_engine
39+
from sqlalchemy import (
40+
Column,
41+
Integer,
42+
Sequence,
43+
String,
44+
create_engine,
45+
)
4046
from sqlalchemy.ext.declarative import declarative_base
4147
from sqlalchemy.orm.session import Session
4248

@@ -46,7 +52,11 @@ Base = declarative_base()
4652
class FakeModel(Base): # type: ignore
4753
__tablename__ = "fake"
4854

49-
id = Column(Integer, Sequence("fakemodel_id_sequence"), primary_key=True)
55+
id = Column(
56+
Integer,
57+
Sequence("fakemodel_id_sequence"),
58+
primary_key=True,
59+
)
5060
name = Column(String)
5161

5262

@@ -74,13 +84,11 @@ You can configure DuckDB by passing `connect_args` to the create_engine function
7484
from sqlalchemy.engine import create_engine
7585

7686
create_engine(
77-
'duckdb:///:memory:',
87+
"duckdb:///:memory:",
7888
connect_args={
79-
'read_only': False,
80-
'config': {
81-
'memory_limit': '500mb'
82-
}
83-
}
89+
"read_only": False,
90+
"config": {"memory_limit": "500mb"},
91+
},
8492
)
8593
```
8694

@@ -89,21 +97,23 @@ The supported configuration parameters are listed in the [DuckDB docs](https://d
8997
## How to register a pandas DataFrame
9098

9199
```python
92-
breakpoint()
93100
import pandas as pd
94101
from sqlalchemy import text, __version__ as sqla_version
95102
from sqlalchemy.engine import create_engine
96103

97104
conn = create_engine("duckdb:///:memory:").connect()
98105

99-
df = pd.DataFrame([{'id': 0}])
106+
df = pd.DataFrame([{"id": 0}])
100107

101-
if sqla_version.startswith('1.3.'):
108+
if sqla_version.startswith("1.3."):
102109
# with SQLAlchemy 1.3
103110
conn.execute("register", ("dataframe_name", df))
104111
else:
105112
# with SQLAlchemy 1.4+
106-
conn.execute(text("register(:name, :df)"), {"name": "dataframe_name", "df": df})
113+
conn.execute(
114+
text("register(:name, :df)"),
115+
{"name": "dataframe_name", "df": df},
116+
)
107117

108118
conn.execute(text("select * from dataframe_name"))
109119
```
@@ -118,19 +128,20 @@ The following example demonstrates how to create an auto-incrementing ID column
118128

119129
```python
120130
import sqlalchemy
121-
engine = sqlalchemy.create_engine('duckdb:////path/to/duck.db')
122-
metadata = sqlalchemy.MetaData()
123-
user_id_seq = sqlalchemy.Sequence('user_id_seq')
131+
132+
engine = sqlalchemy.create_engine("duckdb:///:memory:")
133+
metadata = sqlalchemy.MetaData(engine)
134+
user_id_seq = sqlalchemy.Sequence("user_id_seq")
124135
users_table = sqlalchemy.Table(
125-
'users',
126-
metadata,
127-
sqlalchemy.Column(
128-
'id',
129-
sqlalchemy.Integer,
130-
user_id_seq,
131-
server_default=user_id_seq.next_value(),
132-
primary_key=True,
133-
),
136+
"users",
137+
metadata,
138+
sqlalchemy.Column(
139+
"id",
140+
sqlalchemy.Integer,
141+
user_id_seq,
142+
server_default=user_id_seq.next_value(),
143+
primary_key=True,
144+
),
134145
)
135146
metadata.create_all(bind=engine)
136147
```
@@ -144,9 +155,10 @@ The `pandas.read_sql()` method can read tables from `duckdb_engine` into DataFra
144155
```python notest
145156
import pandas as pd
146157
import sqlalchemy
147-
engine = sqlalchemy.create_engine('duckdb:////path/to/duck.db')
148-
df = pd.read_sql('users', engine) ### Works as expected
149-
df = pd.read_sql('users', engine, chunksize=25) ### Throws an exception
158+
159+
engine = sqlalchemy.create_engine("duckdb:////path/to/duck.db")
160+
df = pd.read_sql("users", engine) ### Works as expected
161+
df = pd.read_sql("users", engine, chunksize=25) ### Throws an exception
150162
```
151163

152164
### Unsigned integer support
@@ -162,6 +174,7 @@ This support can be enabling by adding an Alembic implementation class for the `
162174
```python notest
163175
from alembic.ddl.impl import DefaultImpl
164176

177+
165178
class AlembicDuckDBImpl(DefaultImpl):
166179
"""Alembic implementation for DuckDB."""
167180

@@ -180,13 +193,11 @@ Until the DuckDB python client allows you to natively preload extensions, I've a
180193
from sqlalchemy import create_engine
181194

182195
create_engine(
183-
'duckdb:///:memory:',
196+
"duckdb:///:memory:",
184197
connect_args={
185-
'preload_extensions': ['https'],
186-
'config': {
187-
's3_region': 'ap-southeast-1'
188-
}
189-
}
198+
"preload_extensions": ["https"],
199+
"config": {"s3_region": "ap-southeast-1"},
200+
},
190201
)
191202
```
192203

duckdb_engine/datatypes.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ class Struct(TypeEngine):
118118
from sqlalchemy import Table, Column, String, MetaData
119119
120120
Table(
121-
'hello',
121+
"hello",
122122
MetaData(),
123-
Column('name', Struct({'first': String, 'last': String}))
123+
Column("name", Struct({"first": String, "last": String})),
124124
)
125125
```
126126
@@ -141,11 +141,7 @@ class Map(TypeEngine):
141141
from duckdb_engine.datatypes import Map
142142
from sqlalchemy import Table, Column, String, MetaData
143143
144-
Table(
145-
'hello',
146-
MetaData(),
147-
Column('name', Map(String, String))
148-
)
144+
Table("hello", MetaData(), Column("name", Map(String, String)))
149145
```
150146
"""
151147

@@ -184,9 +180,9 @@ class Union(TypeEngine):
184180
from sqlalchemy import Table, Column, String, MetaData
185181
186182
Table(
187-
'hello',
183+
"hello",
188184
MetaData(),
189-
Column('name', Union({"name": String, "age": String}))
185+
Column("name", Union({"name": String, "age": String})),
190186
)
191187
```
192188
"""

0 commit comments

Comments
 (0)