Skip to content

Commit

Permalink
docs: run blacken docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mause authored Dec 16, 2024
1 parent 93d3f42 commit 205dbc6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ repos:
rev: "1.19.1"
hooks:
- id: blacken-docs
args:
- --line-length
- '80'
additional_dependencies:
- black==22.12.0
77 changes: 44 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ DuckDB Engine also has a conda feedstock available, the instructions for the use
Once you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search

```python
from sqlalchemy import Column, Integer, Sequence, String, create_engine
from sqlalchemy import (
Column,
Integer,
Sequence,
String,
create_engine,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import Session

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

id = Column(Integer, Sequence("fakemodel_id_sequence"), primary_key=True)
id = Column(
Integer,
Sequence("fakemodel_id_sequence"),
primary_key=True,
)
name = Column(String)


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

create_engine(
'duckdb:///:memory:',
"duckdb:///:memory:",
connect_args={
'read_only': False,
'config': {
'memory_limit': '500mb'
}
}
"read_only": False,
"config": {"memory_limit": "500mb"},
},
)
```

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

```python
breakpoint()
import pandas as pd
from sqlalchemy import text, __version__ as sqla_version
from sqlalchemy.engine import create_engine

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

df = pd.DataFrame([{'id': 0}])
df = pd.DataFrame([{"id": 0}])

if sqla_version.startswith('1.3.'):
if sqla_version.startswith("1.3."):
# with SQLAlchemy 1.3
conn.execute("register", ("dataframe_name", df))
else:
# with SQLAlchemy 1.4+
conn.execute(text("register(:name, :df)"), {"name": "dataframe_name", "df": df})
conn.execute(
text("register(:name, :df)"),
{"name": "dataframe_name", "df": df},
)

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

```python
import sqlalchemy
engine = sqlalchemy.create_engine('duckdb:////path/to/duck.db')
metadata = sqlalchemy.MetaData()
user_id_seq = sqlalchemy.Sequence('user_id_seq')

engine = sqlalchemy.create_engine("duckdb:///:memory:")
metadata = sqlalchemy.MetaData(engine)
user_id_seq = sqlalchemy.Sequence("user_id_seq")
users_table = sqlalchemy.Table(
'users',
metadata,
sqlalchemy.Column(
'id',
sqlalchemy.Integer,
user_id_seq,
server_default=user_id_seq.next_value(),
primary_key=True,
),
"users",
metadata,
sqlalchemy.Column(
"id",
sqlalchemy.Integer,
user_id_seq,
server_default=user_id_seq.next_value(),
primary_key=True,
),
)
metadata.create_all(bind=engine)
```
Expand All @@ -144,9 +155,10 @@ The `pandas.read_sql()` method can read tables from `duckdb_engine` into DataFra
```python notest
import pandas as pd
import sqlalchemy
engine = sqlalchemy.create_engine('duckdb:////path/to/duck.db')
df = pd.read_sql('users', engine) ### Works as expected
df = pd.read_sql('users', engine, chunksize=25) ### Throws an exception

engine = sqlalchemy.create_engine("duckdb:////path/to/duck.db")
df = pd.read_sql("users", engine) ### Works as expected
df = pd.read_sql("users", engine, chunksize=25) ### Throws an exception
```

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


class AlembicDuckDBImpl(DefaultImpl):
"""Alembic implementation for DuckDB."""

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

create_engine(
'duckdb:///:memory:',
"duckdb:///:memory:",
connect_args={
'preload_extensions': ['https'],
'config': {
's3_region': 'ap-southeast-1'
}
}
"preload_extensions": ["https"],
"config": {"s3_region": "ap-southeast-1"},
},
)
```

Expand Down
14 changes: 5 additions & 9 deletions duckdb_engine/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class Struct(TypeEngine):
from sqlalchemy import Table, Column, String, MetaData
Table(
'hello',
"hello",
MetaData(),
Column('name', Struct({'first': String, 'last': String}))
Column("name", Struct({"first": String, "last": String})),
)
```
Expand All @@ -141,11 +141,7 @@ class Map(TypeEngine):
from duckdb_engine.datatypes import Map
from sqlalchemy import Table, Column, String, MetaData
Table(
'hello',
MetaData(),
Column('name', Map(String, String))
)
Table("hello", MetaData(), Column("name", Map(String, String)))
```
"""

Expand Down Expand Up @@ -184,9 +180,9 @@ class Union(TypeEngine):
from sqlalchemy import Table, Column, String, MetaData
Table(
'hello',
"hello",
MetaData(),
Column('name', Union({"name": String, "age": String}))
Column("name", Union({"name": String, "age": String})),
)
```
"""
Expand Down

0 comments on commit 205dbc6

Please sign in to comment.