plainkitbin-sqlitemd 1.0.0__py3-none-any.whl
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.
- plainkitbin_sqlitemd-1.0.0.dist-info/METADATA +90 -0
- plainkitbin_sqlitemd-1.0.0.dist-info/RECORD +7 -0
- plainkitbin_sqlitemd-1.0.0.dist-info/WHEEL +5 -0
- plainkitbin_sqlitemd-1.0.0.dist-info/entry_points.txt +2 -0
- plainkitbin_sqlitemd-1.0.0.dist-info/licenses/LICENSE +34 -0
- plainkitbin_sqlitemd-1.0.0.dist-info/top_level.txt +1 -0
- sqlitemd.py +130 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plainkitbin-sqlitemd
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Offline SQLite schema exporter for LLM context. Stdlib only, no network at runtime.
|
|
5
|
+
Author: PlainKitBin
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 PlainKitBin
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
11
|
+
copy of this software and associated documentation files (the
|
|
12
|
+
"Software"), to deal in the Software without restriction, including
|
|
13
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
14
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
16
|
+
the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included
|
|
19
|
+
in all copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
22
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
24
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
25
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
26
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
+
|
|
29
|
+
GOVERNING LAW
|
|
30
|
+
This Agreement shall be governed by and construed in accordance with the laws of Japan.
|
|
31
|
+
|
|
32
|
+
EXPORT COMPLIANCE
|
|
33
|
+
You agree to comply with all applicable export and import laws and regulations. The product must not be exported to embargoed countries or sanctioned individuals.
|
|
34
|
+
|
|
35
|
+
ACCEPTABLE USE
|
|
36
|
+
You agree not to use the product for any unlawful, illegal, or malicious activities.
|
|
37
|
+
|
|
38
|
+
SEVERABILITY
|
|
39
|
+
If any provision of this license is held to be invalid or unenforceable, the remaining provisions shall remain in full force and effect.
|
|
40
|
+
|
|
41
|
+
Project-URL: Homepage, https://plainkitbin.gumroad.com
|
|
42
|
+
Project-URL: Source, https://github.com/plainkitbin/sqlitemd
|
|
43
|
+
Keywords: sqlite,schema,markdown,cli,offline
|
|
44
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
45
|
+
Classifier: Programming Language :: Python :: 3
|
|
46
|
+
Classifier: Environment :: Console
|
|
47
|
+
Classifier: Operating System :: OS Independent
|
|
48
|
+
Requires-Python: >=3.8
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
License-File: LICENSE
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# SQLiteMD
|
|
54
|
+
|
|
55
|
+
Export a SQLite schema to Markdown for LLM context -- offline, no
|
|
56
|
+
dependencies. Python 3.8+, stdlib only (`sqlite3`). No network at
|
|
57
|
+
runtime.
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python3 sqlitemd.py export my.db -o schema.md
|
|
63
|
+
python3 sqlitemd.py schema my.db -o schema.json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## CRON example
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Weekly schema doc for a local analytics db
|
|
70
|
+
0 3 * * 0 cd /path/to/sqlitemd && python3 sqlitemd.py export /data/app.db -o /backup/schema.md
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Limitations
|
|
74
|
+
|
|
75
|
+
Read-only introspection. Does not migrate data. Complex
|
|
76
|
+
attached databases are not supported.
|
|
77
|
+
|
|
78
|
+
Free and open source (MIT license, see LICENSE). No telemetry, no
|
|
79
|
+
network calls, no nagware.
|
|
80
|
+
|
|
81
|
+
Part of the [PlainKitBin](https://plainkitbin.gumroad.com) toolset --
|
|
82
|
+
small, offline, single-file utilities with automated tests and a
|
|
83
|
+
provenance record for every release. If you find this useful, check out
|
|
84
|
+
[PlainKitBin DirSnapshot](https://plainkitbin.gumroad.com/l/PlainKitBinDirSnapshot).
|
|
85
|
+
|
|
86
|
+
Provided as-is with no individual support.
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
*Built with AI assistance and automatically tested before release; released under human oversight.*
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
sqlitemd.py,sha256=iIDwZK1Oq8_37EdYNZfOUDFwq9wPOPuxfMNGLPI6TGQ,3721
|
|
2
|
+
plainkitbin_sqlitemd-1.0.0.dist-info/licenses/LICENSE,sha256=V59rRQ8oTck6lR7J0APsOgdv8Vh6NtRji6mjof_GAE4,1605
|
|
3
|
+
plainkitbin_sqlitemd-1.0.0.dist-info/METADATA,sha256=eYYT4LctExdNM8w_438yTBna-IMNjcwxKxzCbUiiCd4,3602
|
|
4
|
+
plainkitbin_sqlitemd-1.0.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
5
|
+
plainkitbin_sqlitemd-1.0.0.dist-info/entry_points.txt,sha256=7wR1BvwXOl8ANCIDYto_o-F3xfn7JoSVgsP6SlXZMQU,43
|
|
6
|
+
plainkitbin_sqlitemd-1.0.0.dist-info/top_level.txt,sha256=kGyMIKlOwLUDTApEsn1n4f9uZPPq8McplUHE3Ek9ZD8,9
|
|
7
|
+
plainkitbin_sqlitemd-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PlainKitBin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
6
|
+
copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included
|
|
14
|
+
in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
GOVERNING LAW
|
|
25
|
+
This Agreement shall be governed by and construed in accordance with the laws of Japan.
|
|
26
|
+
|
|
27
|
+
EXPORT COMPLIANCE
|
|
28
|
+
You agree to comply with all applicable export and import laws and regulations. The product must not be exported to embargoed countries or sanctioned individuals.
|
|
29
|
+
|
|
30
|
+
ACCEPTABLE USE
|
|
31
|
+
You agree not to use the product for any unlawful, illegal, or malicious activities.
|
|
32
|
+
|
|
33
|
+
SEVERABILITY
|
|
34
|
+
If any provision of this license is held to be invalid or unenforceable, the remaining provisions shall remain in full force and effect.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sqlitemd
|
sqlitemd.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# MIT License
|
|
3
|
+
# Copyright (c) 2026 PlainKitBin
|
|
4
|
+
#
|
|
5
|
+
# SQLite schema -> Markdown exporter. Stdlib only. Product #2.
|
|
6
|
+
import argparse
|
|
7
|
+
import os
|
|
8
|
+
import sqlite3
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
_HDR = "# SQLite Schema\n\n"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _ro_conn(db_path):
|
|
15
|
+
uri = "file:" + os.path.abspath(db_path) + "?mode=ro"
|
|
16
|
+
return sqlite3.connect(uri, uri=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def introspect_db(db_path):
|
|
20
|
+
"""Return sorted schema dict from a sqlite database."""
|
|
21
|
+
if not os.path.isfile(db_path):
|
|
22
|
+
raise ValueError("db missing: " + db_path)
|
|
23
|
+
conn = _ro_conn(db_path)
|
|
24
|
+
try:
|
|
25
|
+
cur = conn.cursor()
|
|
26
|
+
sql = (
|
|
27
|
+
"SELECT name FROM sqlite_master "
|
|
28
|
+
"WHERE type='table' AND name NOT LIKE 'sqlite_%' "
|
|
29
|
+
"ORDER BY name"
|
|
30
|
+
)
|
|
31
|
+
names = [r[0] for r in cur.execute(sql).fetchall()]
|
|
32
|
+
tables = []
|
|
33
|
+
for name in names:
|
|
34
|
+
cols = cur.execute(
|
|
35
|
+
"PRAGMA table_info(" + name + ")"
|
|
36
|
+
).fetchall()
|
|
37
|
+
idx = cur.execute(
|
|
38
|
+
"PRAGMA index_list(" + name + ")"
|
|
39
|
+
).fetchall()
|
|
40
|
+
rows = []
|
|
41
|
+
for r in cols:
|
|
42
|
+
rows.append({
|
|
43
|
+
"name": r[1],
|
|
44
|
+
"type": r[2] or "",
|
|
45
|
+
"notnull": bool(r[3]),
|
|
46
|
+
"pk": bool(r[5]),
|
|
47
|
+
})
|
|
48
|
+
tables.append({
|
|
49
|
+
"name": name,
|
|
50
|
+
"columns": rows,
|
|
51
|
+
"index_count": len(idx),
|
|
52
|
+
})
|
|
53
|
+
return {"tables": tables}
|
|
54
|
+
finally:
|
|
55
|
+
conn.close()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def schema_to_markdown(schema):
|
|
59
|
+
"""Pure: schema dict -> markdown string."""
|
|
60
|
+
lines = [_HDR.rstrip(), ""]
|
|
61
|
+
for tbl in schema.get("tables", []):
|
|
62
|
+
lines.append("## " + tbl["name"])
|
|
63
|
+
lines.append("")
|
|
64
|
+
lines.append("| column | type | pk | notnull |")
|
|
65
|
+
lines.append("| --- | --- | --- | --- |")
|
|
66
|
+
for c in tbl["columns"]:
|
|
67
|
+
pk = "yes" if c["pk"] else ""
|
|
68
|
+
nn = "yes" if c["notnull"] else ""
|
|
69
|
+
nm = c["name"]
|
|
70
|
+
ty = c["type"]
|
|
71
|
+
lines.append(
|
|
72
|
+
"| " + nm + " | " + ty + " | " + pk + " | " + nn + " |"
|
|
73
|
+
)
|
|
74
|
+
lines.append("")
|
|
75
|
+
ic = tbl.get("index_count", 0)
|
|
76
|
+
lines.append("Indexes: " + str(ic))
|
|
77
|
+
lines.append("")
|
|
78
|
+
return "\n".join(lines).rstrip() + "\n"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def export_markdown(db_path):
|
|
82
|
+
"""Pure pipeline: db path -> markdown string."""
|
|
83
|
+
return schema_to_markdown(introspect_db(db_path))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _cmd_export(args):
|
|
87
|
+
md = export_markdown(args.db)
|
|
88
|
+
if args.out:
|
|
89
|
+
with open(args.out, "w", encoding="utf-8") as f:
|
|
90
|
+
f.write(md)
|
|
91
|
+
else:
|
|
92
|
+
sys.stdout.write(md)
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _cmd_schema(args):
|
|
97
|
+
import json
|
|
98
|
+
data = introspect_db(args.db)
|
|
99
|
+
txt = json.dumps(data, indent=2, sort_keys=True) + "\n"
|
|
100
|
+
if args.out:
|
|
101
|
+
with open(args.out, "w", encoding="utf-8") as f:
|
|
102
|
+
f.write(txt)
|
|
103
|
+
else:
|
|
104
|
+
sys.stdout.write(txt)
|
|
105
|
+
return 0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def main(argv=None):
|
|
109
|
+
p = argparse.ArgumentParser(
|
|
110
|
+
description="SQLite schema to Markdown (offline)",
|
|
111
|
+
)
|
|
112
|
+
sub = p.add_subparsers(dest="cmd", required=True)
|
|
113
|
+
pe = sub.add_parser("export", help="write markdown report")
|
|
114
|
+
pe.add_argument("db")
|
|
115
|
+
pe.add_argument("-o", "--out", default="")
|
|
116
|
+
pe.set_defaults(func=_cmd_export)
|
|
117
|
+
ps = sub.add_parser("schema", help="write json schema")
|
|
118
|
+
ps.add_argument("db")
|
|
119
|
+
ps.add_argument("-o", "--out", default="")
|
|
120
|
+
ps.set_defaults(func=_cmd_schema)
|
|
121
|
+
args = p.parse_args(argv)
|
|
122
|
+
try:
|
|
123
|
+
return args.func(args)
|
|
124
|
+
except (OSError, ValueError, sqlite3.Error) as e:
|
|
125
|
+
print("error:", e, file=sys.stderr)
|
|
126
|
+
return 1
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
sys.exit(main())
|