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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: extract-sqlite
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Add your description here
5
5
  Author: 6vi7ms
6
6
  Author-email: 6vi7ms <6vi7ms@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "extract-sqlite"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "extract-sqlite"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -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.option("--db", "-d", required=True, type=click.Path(exists=True), help="เส้นทางไปยังไฟล์ SQLite database")
9
- @click.option("--output", "-o", default="output.xlsx", help="ชื่อไฟล์ Excel ที่ต้องการส่งออก (ค่าเริ่มต้น: output.xlsx)")
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
- """ส่งออกข้อมูลทุกตารางจาก SQLite database ไปเป็นไฟล์ Excel โดยแยกตามชื่อ Sheet"""
12
- click.echo(f"กำลังเชื่อมต่อกับฐานข้อมูล: {db}")
13
- conn = sqlite3.connect(db)
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] # Excel จำกัดชื่อ Sheet ที่ 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