FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
atlas.sql/main.go at main · fezcode/atlas.sql · GitHub
fezcode
/
atlas.sql
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
atlas.sql
/
main.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
95 lines (84 loc) · 2.24 KB
Breadcrumbs
atlas.sql
/
main.go
Copy path
File metadata and controls
95 lines (84 loc) · 2.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package
main
import
(
"atlas.sql/internal/db"
"atlas.sql/internal/ui"
"fmt"
"os"
tea
"github.com/charmbracelet/bubbletea"
)
var
Version
=
"dev"
func
main
() {
var
connStr
string
var
listTables
bool
if
len
(
os
.
Args
)
<
2
{
showHelp
()
os
.
Exit
(
1
)
}
for
_
,
arg
:=
range
os
.
Args
[
1
:] {
if
arg
==
"-v"
||
arg
==
"--version"
{
fmt
.
Printf
(
"atlas.sql v%s
\n
"
,
Version
)
return
}
else
if
arg
==
"-h"
||
arg
==
"--help"
{
showHelp
()
return
}
else
if
arg
==
"-l"
||
arg
==
"--list"
||
arg
==
"--tables"
{
listTables
=
true
}
else
if
connStr
==
""
{
connStr
=
arg
}
}
if
connStr
==
""
{
showHelp
()
os
.
Exit
(
1
)
}
database
,
err
:=
db
.
Connect
(
connStr
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error connecting to database: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
defer
database
.
Close
()
if
listTables
{
result
,
err
:=
database
.
ListTables
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error listing tables: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
if
len
(
result
.
Rows
)
==
0
{
fmt
.
Println
(
"No tables found."
)
}
else
{
for
_
,
row
:=
range
result
.
Rows
{
if
len
(
row
)
>
0
{
fmt
.
Println
(
row
[
0
])
}
}
}
return
}
p
:=
tea
.
NewProgram
(
ui
.
NewModel
(
database
),
tea
.
WithAltScreen
())
if
_
,
err
:=
p
.
Run
();
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error running program: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
}
func
showHelp
() {
fmt
.
Println
(
"Atlas SQL - Terminal-based SQL client"
)
fmt
.
Println
(
"
\n
Usage:"
)
fmt
.
Println
(
" atlas.sql [options] [connection_string]"
)
fmt
.
Println
(
"
\n
Options:"
)
fmt
.
Println
(
" -l, --list List all tables in the database and exit"
)
fmt
.
Println
(
" -v, --version Show version and exit"
)
fmt
.
Println
(
" -h, --help Show this help message and exit"
)
fmt
.
Println
(
"
\n
Examples:"
)
fmt
.
Println
(
" SQLite: atlas.sql sqlite://path/to/db.sqlite"
)
fmt
.
Println
(
" PostgreSQL: atlas.sql
\"
postgres://user:pass@localhost:5432/dbname?sslmode=disable
\"
"
)
fmt
.
Println
(
" List Table: atlas.sql -l sqlite://path/to/db.sqlite"
)
fmt
.
Println
(
"
\n
Controls:"
)
fmt
.
Println
(
" Enter: Run Query"
)
fmt
.
Println
(
" Tab: Switch focus"
)
fmt
.
Println
(
" Arrows: Navigate Results / Columns"
)
fmt
.
Println
(
" +/-: Adjust Column Width"
)
fmt
.
Println
(
" v: Detail View"
)
fmt
.
Println
(
" c: Copy CSV"
)
fmt
.
Println
(
" h: Show Help"
)
fmt
.
Println
(
" q: Quit"
)
}
Back
|
FazBrowse Home
|
New Git URL