# cbaldelomar/extractsql architecture

> Architecture diagram of the GitHub repository cbaldelomar/extractsql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cbaldelomar/extractsql
- Repository: https://github.com/cbaldelomar/extractsql

## Overview

ExtractSQL is a command-line SQL Server export utility. The user supplies connection details, a SQL script, and an output format; the CLI prepares the destination and delegates extraction, which executes the script and streams the first result set to a CSV/delimited-text or Excel writer. The README also documents batching, multi-step scripts, timestamped naming, and configurable delimiters. The graph reflects the sampled runtime calls; README-described behavior is included where its implementation was not fully shown.

Main entry points: [`extractsql/extract.py`](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/extract.py) (Extraction orchestrator), [`extractsql/main.py`](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/main.py) (Argument handling), [`extractsql/tocsv.py`](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/tocsv.py) (CSV and text writer), [`extractsql/toexcel.py`](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/toexcel.py) (Excel writer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command line"]
  node_cli["Argument handling<br/>[main.py]"]
  node_version["Version metadata<br/>[__version__.py]"]
end

subgraph group_prep["Extraction setup"]
  node_helpers["Connection and file helpers<br/>[utils.py]"]
  node_constants["Export defaults<br/>[constants.py]"]
end

subgraph group_execution["Query execution"]
  node_extract["Extraction orchestrator<br/>[extract.py]"]
end

subgraph group_export["Export formats"]
  node_csv["CSV and text writer<br/>[tocsv.py]"]
  node_excel["Excel writer<br/>[toexcel.py]"]
end

node_user(("CLI user"))
node_queryfile["SQL script"]
node_sqlserver[("SQL Server")]
node_output["Exported file"]

node_user -->|"provides options"| node_cli
node_cli -->|"reads version"| node_version
node_cli -->|"prepares output"| node_helpers
node_cli -->|"starts extraction"| node_extract
node_queryfile -->|"provides SQL"| node_extract
node_extract -->|"reads and configures"| node_helpers
node_extract -->|"connects and queries"| node_sqlserver
node_extract -->|"dispatches flat files"| node_csv
node_extract -->|"dispatches xlsx"| node_excel
node_csv -->|"writes batches"| node_output
node_excel -->|"writes sheets"| node_output

click node_cli "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/main.py"
click node_version "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/__version__.py"
click node_helpers "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/utils.py"
click node_constants "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/constants.py"
click node_extract "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/extract.py"
click node_csv "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/tocsv.py"
click node_excel "https://github.com/cbaldelomar/extractsql/blob/main/extractsql/toexcel.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_version,node_user toneBlue
class node_helpers,node_constants,node_sqlserver toneAmber
class node_extract toneMint
class node_csv,node_excel toneRose
class node_queryfile,node_output toneIndigo
```

## Components

### Command line

- [Argument handling](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/main.py): `extractsql/main.py`
- [Version metadata](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/__version__.py): `extractsql/__version__.py`

### Extraction setup

- [Connection and file helpers](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/utils.py): `extractsql/utils.py`
- [Export defaults](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/constants.py): `extractsql/constants.py`

### Query execution

- [Extraction orchestrator](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/extract.py): `extractsql/extract.py`

### Export formats

- [CSV and text writer](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/tocsv.py): `extractsql/tocsv.py`
- [Excel writer](https://github.com/cbaldelomar/extractsql/blob/main/extractsql/toexcel.py): `extractsql/toexcel.py`

### Other components

- **CLI user**
- **SQL script**
- **SQL Server**
- **Exported file**

## Connections

- CLI user → Argument handling: provides options (evidence: `README.md`)
- Argument handling → Version metadata: reads version (evidence: `extractsql/main.py`)
- Argument handling → Connection and file helpers: prepares output (evidence: `extractsql/main.py`)
- Argument handling → Extraction orchestrator: starts extraction (evidence: `extractsql/main.py`)
- SQL script → Extraction orchestrator: provides SQL (evidence: `extractsql/extract.py`)
- Extraction orchestrator → Connection and file helpers: reads and configures (evidence: `extractsql/extract.py`)
- Extraction orchestrator → SQL Server: connects and queries (evidence: `extractsql/extract.py`)
- Extraction orchestrator → CSV and text writer: dispatches flat files (evidence: `extractsql/extract.py`)
- Extraction orchestrator → Excel writer: dispatches xlsx (evidence: `extractsql/extract.py`)
- CSV and text writer → Exported file: writes batches (evidence: `extractsql/tocsv.py`)
- Excel writer → Exported file: writes sheets (evidence: `extractsql/toexcel.py`)
