Skip to content

Commit 5be2e08

Browse files
committed
10 and 11
1 parent 392ebee commit 5be2e08

File tree

4 files changed

+61
-52
lines changed

4 files changed

+61
-52
lines changed

docs/examples/usage/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pytest_plugins = ["pytest_databases.docker.postgres", "pytest_databases.docker.mysql"]
1+
pytest_plugins = ["pytest_databases.docker.postgres", "pytest_databases.docker.mysql", "pytest_databases.docker.oracle"]

docs/examples/usage/test_drivers_and_querying_10.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55

66

77
def test_example_10_duckdb_config() -> None:
8-
DuckDBConfig()
9-
config_persistent = DuckDBConfig(pool_config={"database": "analytics.duckdb"})
10-
assert config_persistent.pool_config["database"] == "analytics.duckdb"
8+
from sqlspec import SQLSpec
9+
10+
spec = SQLSpec()
11+
# In-memory
12+
config = DuckDBConfig()
13+
14+
# Persistent
15+
config = DuckDBConfig(pool_config={"database": "analytics.duckdb"})
16+
17+
with spec.provide_session(config) as session:
18+
# Create table from Parquet
19+
session.execute("""
20+
CREATE TABLE users AS
21+
SELECT * FROM read_parquet('users.parquet')
22+
""")
23+
24+
# Analytical query
25+
session.execute("""
26+
SELECT date_trunc('day', created_at) as day,
27+
count(*) as user_count
28+
FROM users
29+
GROUP BY day
30+
ORDER BY day
31+
""")
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
# Test module converted from docs example - code-block 11
22
"""Minimal smoke test for drivers_and_querying example 11."""
33

4-
from sqlspec.adapters.oracledb import OracleDBConfig
4+
from pytest_databases.docker.oracle import OracleService
55

66

7-
def test_example_11_oracledb_config() -> None:
8-
config = OracleDBConfig(pool_config={"user": "myuser", "password": "mypassword", "dsn": "localhost:1521/ORCLPDB"})
9-
assert "dsn" in config.pool_config
7+
def test_example_11_oracledb_config(oracle_service: OracleService) -> None:
8+
from sqlspec import SQLSpec
9+
from sqlspec.adapters.oracledb import OracleSyncConfig
10+
11+
spec = SQLSpec()
12+
config = OracleSyncConfig(
13+
pool_config={
14+
"user": oracle_service.user,
15+
"password": oracle_service.password,
16+
"host": oracle_service.host,
17+
"port": oracle_service.port,
18+
"service_name": oracle_service.service_name,
19+
}
20+
)
21+
22+
with spec.provide_session(config) as session:
23+
create_table_sql = """CREATE TABLE employees (
24+
employee_id NUMBER PRIMARY KEY,
25+
first_name VARCHAR2(50),
26+
last_name VARCHAR2(50)
27+
)"""
28+
session.execute(create_table_sql)
29+
session.execute("""
30+
INSERT INTO employees (employee_id, first_name, last_name) VALUES (100, 'John', 'Doe')
31+
""")
32+
33+
session.execute("SELECT * FROM employees WHERE employee_id = :id", id=100)

docs/usage/drivers_and_querying.rst

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,10 @@ DuckDB (Analytical Database)
185185

186186
In-process analytical database optimized for OLAP workloads.
187187

188-
.. code-block:: python
189-
190-
from sqlspec.adapters.duckdb import DuckDBConfig
191-
192-
# In-memory
193-
config = DuckDBConfig()
194-
195-
# Persistent
196-
config = DuckDBConfig(
197-
pool_config={"database": "analytics.duckdb"}
198-
)
199-
200-
with spec.provide_session(config) as session:
201-
# Create table from Parquet
202-
session.execute("""
203-
CREATE TABLE users AS
204-
SELECT * FROM read_parquet('users.parquet')
205-
""")
206-
207-
# Analytical query
208-
result = session.execute("""
209-
SELECT date_trunc('day', created_at) as day,
210-
count(*) as user_count
211-
FROM users
212-
GROUP BY day
213-
ORDER BY day
214-
""")
188+
.. literalinclude:: /examples/test_drivers_and_querying_10.py
189+
:language: python
190+
:lines: 8-34
191+
:dedent: 2
215192

216193
**Features**:
217194

@@ -225,23 +202,10 @@ Oracle Database
225202

226203
Oracle database support with python-oracledb.
227204

228-
.. code-block:: python
229-
230-
from sqlspec.adapters.oracledb import OracleDBConfig
231-
232-
config = OracleDBConfig(
233-
pool_config={
234-
"user": "myuser",
235-
"password": "mypassword",
236-
"dsn": "localhost:1521/ORCLPDB",
237-
}
238-
)
239-
240-
with spec.provide_session(config) as session:
241-
result = session.execute(
242-
"SELECT * FROM employees WHERE employee_id = :id",
243-
id=100
244-
)
205+
.. literalinclude:: /examples/test_drivers_and_querying_11.py
206+
:language: python
207+
:lines: 8-33
208+
:dedent: 2
245209

246210
**Features**:
247211

0 commit comments

Comments
 (0)