|
15 | 15 | - **CRUD Operations**: Complete Create, Read, Update, Delete operation support |
16 | 16 | - **Memory Efficient**: Connection pool-based resource management for optimal performance |
17 | 17 |
|
18 | | -## Quick Start |
| 18 | +## Dependencies |
| 19 | + |
| 20 | +- [`github.com/go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql) |
| 21 | +- [`github.com/pardnchiu/go-logger`](https://github.com/pardnchiu/go-logger) |
| 22 | + |
| 23 | + |
| 24 | +## How to use |
19 | 25 |
|
20 | 26 | ### Installation |
21 | 27 | ```bash |
22 | 28 | go get github.com/pardnchiu/golang-mysql-pool |
23 | 29 | ``` |
24 | 30 |
|
25 | | -### Basic Usage |
| 31 | +### Initialization |
26 | 32 | ```go |
27 | 33 | package main |
28 | 34 |
|
29 | 35 | import ( |
30 | 36 | "fmt" |
31 | 37 | "log" |
32 | 38 |
|
33 | | - _ "github.com/go-sql-driver/mysql" |
34 | 39 | mysqlPool "github.com/pardnchiu/golang-mysql-pool" |
35 | 40 | ) |
36 | 41 |
|
@@ -344,71 +349,6 @@ result, err := pool.Write.Exec("UPDATE users SET last_login = NOW() WHERE id = ? |
344 | 349 | - Automatic release of unused connections |
345 | 350 | - Streaming result set processing support |
346 | 351 |
|
347 | | -## Architecture Overview |
348 | | - |
349 | | -```mermaid |
350 | | -graph TB |
351 | | - subgraph "Application Layer" |
352 | | - APP[Application] |
353 | | - QC[Query Builder] |
354 | | - end |
355 | | - |
356 | | - subgraph "Connection Pool Layer" |
357 | | - RP[Read Pool] |
358 | | - WP[Write Pool] |
359 | | - LM[Log Manager] |
360 | | - end |
361 | | - |
362 | | - subgraph "Database Layer" |
363 | | - MR[MySQL Read Instance] |
364 | | - MW[MySQL Write Instance] |
365 | | - end |
366 | | - |
367 | | - APP --> QC |
368 | | - QC --> RP |
369 | | - QC --> WP |
370 | | - QC --> LM |
371 | | - |
372 | | - RP --> MR |
373 | | - WP --> MW |
374 | | - |
375 | | - RP -.-> LM |
376 | | - WP -.-> LM |
377 | | -``` |
378 | | - |
379 | | -## Flow Chart |
380 | | - |
381 | | -```mermaid |
382 | | -flowchart TD |
383 | | - A[Initialize Config] --> B[Create Read Pool] |
384 | | - B --> C[Create Write Pool] |
385 | | - C --> D[Setup Logging] |
386 | | - D --> E[Validate Connections] |
387 | | - |
388 | | - E --> F{Operation Type} |
389 | | - F -->|Query| G[Use Read Pool] |
390 | | - F -->|Write| H[Use Write Pool] |
391 | | - |
392 | | - G --> I[Get Connection] |
393 | | - H --> I |
394 | | - |
395 | | - I --> J{Connection Available?} |
396 | | - J -->|No| K[Wait for Connection] |
397 | | - J -->|Yes| L[Execute SQL] |
398 | | - |
399 | | - K --> I |
400 | | - |
401 | | - L --> M[Log Slow Query] |
402 | | - M --> N[Release Connection] |
403 | | - N --> O[Return Result] |
404 | | - |
405 | | - O --> P{Close Pool?} |
406 | | - P -->|No| F |
407 | | - P -->|Yes| Q[Close All Connections] |
408 | | - Q --> R[Clean Resources] |
409 | | - R --> S[Pool Closed] |
410 | | -``` |
411 | | - |
412 | 352 | ## License |
413 | 353 |
|
414 | 354 | This source code project is licensed under the [MIT](https://github.com/pardnchiu/go-mysql-pool/blob/main/LICENSE) License. |
|
0 commit comments