Skip to content

Commit 09837ff

Browse files
committed
Initial commit
1 parent 6fc7219 commit 09837ff

File tree

5 files changed

+746
-0
lines changed

5 files changed

+746
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163+
*.db
164+
test-*.py

README.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,241 @@
11
# sqlite3-cli-manager
22
Python tool designed to interact with SQLite databases via command-line interface
3+
4+
# Pre-requisite
5+
6+
- [x] [Python>=3.9](https://python.org) *(optional)*
7+
8+
# Installation and Usage
9+
10+
## Installation
11+
12+
- Clone repo and install requirements
13+
14+
```sh
15+
git clone https://github.com/Simatwa/sqlite3-cli-manager.git
16+
cd sqlite3-cli-manager
17+
pip install -r requirements.txt
18+
```
19+
20+
## Usage
21+
22+
<details open>
23+
24+
<summary><code>$ python manager.py --help</code></summary>
25+
26+
```
27+
Usage: manager.py [OPTIONS] COMMAND [ARGS]...
28+
29+
Interact with SQLite databases via command-line interface
30+
31+
Options:
32+
--version Show the version and exit.
33+
--help Show this message and exit.
34+
35+
Commands:
36+
execute Run sql statements against database [AUTO-COMMITS]
37+
interactive Execute sql statements interactively
38+
show-columns List columns for a particular table
39+
show-tables List tables contained in the database
40+
41+
```
42+
43+
</details>
44+
45+
### Execute
46+
47+
- The `execute` command accepts multiple sql statements and run each against the database before auto-commiting the changes.
48+
<details open>
49+
50+
<summary><code>$ python manager.py execute --help </code></summary>
51+
52+
```
53+
Usage: sqlite-manager execute [OPTIONS] DATABASE
54+
55+
Run sql statements against database [AUTO-COMMITS]
56+
57+
Options:
58+
-s, --sql TEXT Sql statements [required]
59+
-j, --json Stdout results in json format
60+
-q, --quiet Do not stdout results
61+
--help Show this message and exit.
62+
```
63+
64+
</details>
65+
66+
`$ sqlite-manager execute <path-to-sqlite3-database> -s "<sql-statement>"`
67+
68+
> For example:
69+
<details>
70+
<summary><code>$ python manager execute test.db -s "select * from linux"</code></summary>
71+
72+
```
73+
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
74+
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃ Col. 7 ┃
75+
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
76+
│ 0 │ 1 │ Parrot │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
77+
│ │ │ │ │ │ │ 13:22:13 │ 13:22:13 │
78+
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
79+
│ 1 │ 2 │ Kali │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
80+
│ │ │ │ │ │ │ 13:22:21 │ 13:22:21 │
81+
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
82+
│ 2 │ 3 │ Ubuntu │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
83+
│ │ │ │ │ │ │ 13:48:18 │ 13:48:18 │
84+
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
85+
│ 3 │ 4 │ Fedora │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
86+
│ │ │ │ │ │ │ 13:48:49 │ 13:48:49 │
87+
└───────┴────────┴────────┴───────────┴────────┴────────┴────────────┴────────────┘──┘
88+
```
89+
</details>
90+
91+
---
92+
93+
### Interactive
94+
95+
- The `interactive` command launches a recursive prompt that takes in sql statements and proceed to run them against the database.
96+
<details open>
97+
98+
<summary><code>$ python manager.py interactive --help </code></summary>
99+
100+
```
101+
Usage: sqlite-manager interactive [OPTIONS] DATABASE
102+
103+
Execute sql statements interactively
104+
105+
Options:
106+
-a, --auto-commit Enable auto-commit
107+
-C, --disable-coloring Stdout prompt text in white font color
108+
-S, --disable-suggestions Do not suggest sql statements
109+
-N, --new-history-thread Start a new history thread
110+
--help Show this message and exit.
111+
```
112+
113+
</details>
114+
115+
`$ sqlite-manager execute <path-to-sqlite3-database> -s "<sql-statement>"`
116+
117+
> For example:
118+
<details>
119+
<summary><code>$ sqlite-manager interactive test.db </code></summary>
120+
121+
```
122+
Welcome to interactive sqlite3-db manager.
123+
Run help or h <command> for usage info.
124+
Repo : https://github.com/Simatwa/sqlite3-cli-manager
125+
126+
╰─>select * from Linux
127+
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
128+
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃ Col. 7 ┃
129+
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
130+
│ 0 │ 1 │ Parrot │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
131+
│ │ │ │ │ │ │ 13:22:13 │ 13:22:13 │
132+
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
133+
│ 1 │ 2 │ Kali │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
134+
│ │ │ │ │ │ │ 13:22:21 │ 13:22:21 │
135+
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
136+
│ 2 │ 3 │ Ubuntu │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
137+
│ │ │ │ │ │ │ 13:48:18 │ 13:48:18 │
138+
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
139+
│ 3 │ 4 │ Fedora │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
140+
│ │ │ │ │ │ │ 13:48:49 │ 13:48:49 │
141+
└───────┴────────┴────────┴───────────┴────────┴────────┴────────────┴────────────┘
142+
╭─[[email protected]]~[🕒16:55:56-💻00:00:03-⚡-3.9s]
143+
╰─>select * from
144+
select * from Linux
145+
select * from sqlite_schema
146+
select * from sqlite_temp_schema
147+
148+
149+
150+
```
151+
</details>
152+
153+
---
154+
155+
### Show-columns
156+
157+
- The `show-columns` command lists the columns for a particular table in the database.
158+
<details open>
159+
160+
<summary><code>$ python manager.py show-columns --help </code></summary>
161+
162+
```
163+
Usage: sqlite-manager show-columns [OPTIONS] DATABASE TABLE
164+
165+
List columns for a particular table
166+
167+
Options:
168+
-j, --json Stdout results in json format
169+
--help Show this message and exit.
170+
```
171+
172+
</details>
173+
174+
`$ python manager.py show-columns <path-to-sqlite3-database> <table-name>"`
175+
176+
> For example:
177+
<details>
178+
<summary><code>$ python manager.py show-columns test.db linux</code></summary>
179+
180+
```
181+
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┓
182+
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃
183+
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━┩
184+
│ 0 │ 0 │ id │ INTEGER │ 0 │ None │ 1 │
185+
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
186+
│ 1 │ 1 │ distro │ TEXT │ 1 │ None │ 0 │
187+
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
188+
│ 2 │ 2 │ org │ TEXT │ 0 │ 'community' │ 0 │
189+
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
190+
│ 3 │ 3 │ logo │ BLOB NULLABLE │ 0 │ None │ 0 │
191+
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
192+
│ 4 │ 4 │ is_maintained │ BOOLEAN │ 0 │ 1 │ 0 │
193+
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
194+
│ 5 │ 5 │ updated_on │ TIMESTAMP │ 0 │ CURRENT_TIM… │ 0 │
195+
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
196+
│ 6 │ 6 │ created_at │ TIMESTAMP │ 1 │ CURRENT_TIM… │ 0 │
197+
└───────┴────────┴───────────────┴───────────────┴────────┴──────────────┴────────┘
198+
```
199+
</details>
200+
201+
---
202+
203+
### Show-tables
204+
205+
- The `show-tables` command lists the available tables across the entire database.
206+
<details open>
207+
208+
<summary><code>$ python manager.py show-tables --help </code></summary>
209+
210+
```
211+
Usage: manager.py show-tables [OPTIONS] DATABASE
212+
213+
List tables contained in the database
214+
215+
Options:
216+
-j, --json Stdout results in json format
217+
--help Show this message and exit.
218+
```
219+
220+
</details>
221+
222+
`$ python manager.py show-tables <path-to-sqlite3-database>`
223+
224+
> For example:
225+
<details>
226+
<summary><code>$ python manager.py show-tables test.db</code></summary>
227+
228+
```
229+
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┓
230+
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃
231+
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━┩
232+
│ 0 │ main │ sqlite_sequence │ table │ 2 │ 0 │ 0 │
233+
├───────┼────────┼────────────────────┼────────┼────────┼────────┼────────┤
234+
│ 1 │ main │ Linux │ table │ 7 │ 0 │ 0 │
235+
├───────┼────────┼────────────────────┼────────┼────────┼────────┼────────┤
236+
│ 2 │ main │ sqlite_schema │ table │ 5 │ 0 │ 0 │
237+
├───────┼────────┼────────────────────┼────────┼────────┼────────┼────────┤
238+
│ 3 │ temp │ sqlite_temp_schema │ table │ 5 │ 0 │ 0 │
239+
└───────┴────────┴────────────────────┴────────┴────────┴────────┴────────┘
240+
```
241+
</details>

0 commit comments

Comments
 (0)