extract-sqlite 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {extract_sqlite-0.1.0 → extract_sqlite-0.1.1}/PKG-INFO +1 -1
- {extract_sqlite-0.1.0 → extract_sqlite-0.1.1}/pyproject.toml +1 -1
- {extract_sqlite-0.1.0 → extract_sqlite-0.1.1}/pyproject.toml.orig +1 -1
- {extract_sqlite-0.1.0 → extract_sqlite-0.1.1}/src/extract_sqlite/main.py +11 -6
- {extract_sqlite-0.1.0 → extract_sqlite-0.1.1}/README.md +0 -0
- {extract_sqlite-0.1.0 → extract_sqlite-0.1.1}/src/extract_sqlite/__init__.py +0 -0
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import sqlite3
|
|
2
|
+
from pathlib import Path
|
|
2
3
|
|
|
3
4
|
import click
|
|
4
5
|
import pandas as pd
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
@click.command()
|
|
8
|
-
@click.
|
|
9
|
-
@click.option("--output", "-o", default=
|
|
9
|
+
@click.argument("db", type=click.Path(exists=True))
|
|
10
|
+
@click.option("--output", "-o", default=None, help="ชื่อไฟล์ Excel ที่ต้องการส่งออก (ค่าเริ่มต้น: ใช้ชื่อเดียวกับไฟล์ Database)")
|
|
10
11
|
def main(db, output):
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
db_path = Path(db)
|
|
13
|
+
|
|
14
|
+
if output is None:
|
|
15
|
+
output = str(db_path.with_suffix(".xlsx"))
|
|
16
|
+
|
|
17
|
+
click.echo(f"กำลังเชื่อมต่อกับฐานข้อมูล: {db_path}")
|
|
18
|
+
conn = sqlite3.connect(db_path)
|
|
14
19
|
|
|
15
20
|
try:
|
|
16
21
|
tables_query = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';"
|
|
@@ -25,7 +30,7 @@ def main(db, output):
|
|
|
25
30
|
with pd.ExcelWriter(output, engine="openpyxl") as writer:
|
|
26
31
|
for table in tables:
|
|
27
32
|
df = pd.read_sql(f"SELECT * FROM [{table}]", conn)
|
|
28
|
-
sheet_name = table[:31]
|
|
33
|
+
sheet_name = table[:31]
|
|
29
34
|
df.to_excel(writer, sheet_name=sheet_name, index=False)
|
|
30
35
|
click.echo(f" - ส่งออกตาราง '{table}' -> Sheet '{sheet_name}' ({len(df)} แถว)")
|
|
31
36
|
|
|
File without changes
|
|
File without changes
|