Skip to content

Commit 49e25a5

Browse files
committed
feat: add banner image and finalize v0.1.0
1 parent 5396d3b commit 49e25a5

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

banner-image.png

389 KB
Loading

internal/db/db.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@ func Connect(connStr string) (Database, error) {
5959
}
6060

6161
func (s *sqlDB) Query(query string) (*Result, error) {
62+
upperQuery := strings.TrimSpace(strings.ToUpper(query))
63+
isSelect := strings.HasPrefix(upperQuery, "SELECT") ||
64+
strings.HasPrefix(upperQuery, "PRAGMA") ||
65+
strings.HasPrefix(upperQuery, "SHOW") ||
66+
strings.HasPrefix(upperQuery, "EXPLAIN") ||
67+
strings.HasPrefix(upperQuery, "WITH")
68+
69+
if !isSelect {
70+
res, err := s.db.Exec(query)
71+
if err != nil {
72+
return nil, err
73+
}
74+
75+
rowsAffected, _ := res.RowsAffected()
76+
lastInsertID, _ := res.LastInsertId()
77+
78+
msg := fmt.Sprintf("Success. Rows affected: %d", rowsAffected)
79+
if lastInsertID > 0 {
80+
msg += fmt.Sprintf(", Last Insert ID: %d", lastInsertID)
81+
}
82+
83+
return &Result{
84+
Columns: []string{"Status"},
85+
Rows: [][]string{{msg}},
86+
}, nil
87+
}
88+
6289
rows, err := s.db.Query(query)
6390
if err != nil {
6491
return nil, err

internal/ui/ui.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
125125
}
126126

127127
case "h":
128-
if m.focus == focusInput {
128+
if m.focus == focusInput && !m.showHelp {
129129
m.input, cmd = m.input.Update(msg)
130130
return m, cmd
131131
}
132132
m.showHelp = !m.showHelp
133133
if m.showHelp {
134134
m.showDetail = false
135135
}
136+
return m, nil
136137

137138
case "c":
138139
if m.focus == focusTable && m.result != nil {
@@ -196,6 +197,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
196197
}
197198

198199
case "esc":
200+
if m.showHelp {
201+
m.showHelp = false
202+
return m, nil
203+
}
199204
if m.showDetail {
200205
m.showDetail = false
201206
return m, nil
@@ -444,6 +449,13 @@ func (m Model) helpView() string {
444449
tutorial.Render(" SELECT * FROM users WHERE age > 18;"),
445450
tutorial.Render(" -- Join tables"),
446451
tutorial.Render(" SELECT u.name, p.title FROM users u JOIN posts p ON u.id = p.user_id;"),
452+
"",
453+
tutorial.Render(" -- Create / Insert / Update / Delete"),
454+
tutorial.Render(" CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT);"),
455+
tutorial.Render(" INSERT INTO items (name) VALUES ('Laptop'), ('Mouse');"),
456+
tutorial.Render(" UPDATE items SET name = 'Mechanical Mouse' WHERE id = 2;"),
457+
tutorial.Render(" DELETE FROM items WHERE id = 1;"),
458+
"",
447459
tutorial.Render(" -- SQLite Meta: List Tables / Schema"),
448460
tutorial.Render(" SELECT name FROM sqlite_master WHERE type='table';"),
449461
tutorial.Render(" PRAGMA table_info(table_name); -- Describe table"),

0 commit comments

Comments
 (0)