Skip to content

Commit

Permalink
Add connecting to database by connectionString given as an argument t…
Browse files Browse the repository at this point in the history
…o cli
  • Loading branch information
Mariusz Kuchta committed Dec 5, 2024
1 parent e080d02 commit a186b99
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"os"

"github.com/go-sql-driver/mysql"

"github.com/jorgerojas26/lazysql/app"
"github.com/jorgerojas26/lazysql/components"
"github.com/jorgerojas26/lazysql/drivers"
"github.com/jorgerojas26/lazysql/helpers"
"github.com/jorgerojas26/lazysql/helpers/logger"
"github.com/jorgerojas26/lazysql/models"
)

var version = "dev"
Expand Down Expand Up @@ -41,12 +43,31 @@ func main() {

// Check if "version" arg is passed.
argsWithProg := os.Args

if len(argsWithProg) > 1 {
switch argsWithProg[1] {
case "version":
fmt.Println("LazySQL version: ", version)
os.Exit(0)
default:
connectionString := argsWithProg[1]
parsed, err := helpers.ParseConnectionString(connectionString)
if err != nil {
fmt.Printf("Could not parse connection string: %s\n", err)
os.Exit(1)
}
connection := models.Connection{
Name: connectionString,
Provider: parsed.Driver,
DBName: connectionString,
URL: connectionString,
}
newDbDriver := &drivers.SQLite{}
err = newDbDriver.Connect(connection.URL)
if err != nil {
fmt.Printf("Could not connect to database %s: %s\n", connectionString, err)
os.Exit(1)
}
components.MainPages.AddPage(connection.URL, components.NewHomePage(connection, newDbDriver).Flex, true, true)
}
}

Expand Down

0 comments on commit a186b99

Please sign in to comment.