# knadh/goyesql architecture

> Architecture diagram of the GitHub repository knadh/goyesql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/knadh/goyesql
- Repository: https://github.com/knadh/goyesql

## Overview

##### Main Components

a) Input Layer:
- SQL File Reader Component
- Raw SQL Query Files (*.sql)
- Support for both file system and embedded files (stuffbin)

b) Parser Components:
- Scanner Component (based on scanner.go)
- Line Parser Component (based on parser_line.go)
- Query Tag Parser

c) Query Management Layer:
- Query Map Storage
- Tag Storage System
- Query Preparation System

d) Integration Layer:
- SQL/SQLx Connection Handler
- Statement Preparation System
- Struct Scanner Component

##### Flow Representation

Start at the top with two parallel input paths:
**[SQL Files] ----→ [File Reader]**
**[Embedded Binary] ----→ [Bytes Reader]**
- ↓
- [Scanner]
- ↓
- [Line Parser] ←→ [Tag Parser]
- ↓
**[Query Map Builder]**
- ↓
**[Statement Preparation]**
- ↓
**[Struct Scanner]**

##### Important Details

a) Query Processing:
- How queries are parsed and separated
- Tag extraction and storage
- Query preparation flow

b) Integration Points:
- Connection with sql.DB/sqlx.DB
- Prepared statement creation
- Struct scanning capability

##### Notes Section

A notes section explaining:
- The project's compatibility break from original goyesql
- Support for both sql and sqlx
- Embedded file support through stuffbin

Remember to emphasize:
- The separation of concerns between parsing and preparation
- The flexibility of the tag system
- The integration capabilities with both sql and sqlx
- The support for both file-based and embedded queries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SF[SQL Files]:::file
        EB[Embedded Binary]:::file
    end

    subgraph "Parser Layer"
        FR[File Reader]:::component
        BR[Bytes Reader]:::component
        SC[Scanner]:::component
        LP[Line Parser]:::component
        TP[Tag Parser]:::component
    end

    subgraph "Query Management"
        QM[Query Map Storage]:::storage
        TS[Tag Storage]:::storage
        QP[Query Preparation]:::component
    end

    subgraph "Integration Layer"
        SH[SQL/SQLx Handler]:::integration
        PS[Prepared Statements]:::integration
        SS[Struct Scanner]:::integration
    end

    %% Flow connections
    SF --> FR
    EB --> BR
    FR --> SC
    BR --> SC
    SC --> LP
    LP <--> TP
    LP --> QM
    TP --> TS
    QM --> QP
    QP --> PS
    PS --> SS
    SH --> PS

    %% Click events
    click SC "https://github.com/knadh/goyesql/blob/master/scanner.go"
    click LP "https://github.com/knadh/goyesql/blob/master/parser_line.go"
    click SH "https://github.com/knadh/goyesql/blob/master/sqlx/sqlx.go"
    click QM "https://github.com/knadh/goyesql/blob/master/goyesql.go"
    click SF "https://github.com/knadh/goyesql/tree/master/tests/samples"

    %% Styling
    classDef file fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff
    classDef component fill:#85d885,stroke:#000,stroke-width:2px
    classDef storage fill:#f7e359,stroke:#000,stroke-width:2px
    classDef integration fill:#808080,stroke:#000,stroke-width:2px,color:#fff

    %% Legend
    subgraph Legend
        L1[Files]:::file
        L2[Components]:::component
        L3[Storage]:::storage
        L4[Integration]:::integration
    end
```
