fix make table order
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/repository"
|
"git.infra.nkode.tech/dkelly/nkode-core/repository"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/sqlite"
|
"git.infra.nkode.tech/dkelly/nkode-core/sqlite"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@@ -21,17 +22,23 @@ func main() {
|
|||||||
commandLine := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
commandLine := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||||
dbPath := commandLine.String("db-path", "", "Path to the database")
|
dbPath := commandLine.String("db-path", "", "Path to the database")
|
||||||
svgPath := commandLine.String("svg-path", "", "Path to the SVG directory")
|
svgPath := commandLine.String("svg-path", "", "Path to the SVG directory")
|
||||||
ctx := context.Background()
|
if err = commandLine.Parse(os.Args[1:]); err != nil {
|
||||||
sqliteRepo, err := repository.NewSqliteRepository(*dbPath, ctx)
|
|
||||||
err = commandLine.Parse(os.Args[1:])
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to parse flags: %v", err)
|
log.Fatalf("Failed to parse flags: %v", err)
|
||||||
}
|
}
|
||||||
if err = MakeTables(*dbPath, string(sqliteSchema)); err != nil {
|
if err = MakeTables(*dbPath, string(sqliteSchema)); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
sqliteRepo, err := repository.NewSqliteRepository(*dbPath, ctx)
|
||||||
|
sqliteRepo.Start()
|
||||||
|
defer func(sqliteRepo *repository.SqliteRepository) {
|
||||||
|
if err := sqliteRepo.Stop(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}(sqliteRepo)
|
||||||
|
|
||||||
FlaticonToSqlite(sqliteRepo, *svgPath)
|
FlaticonToSqlite(sqliteRepo, *svgPath)
|
||||||
|
fmt.Sprintf("Successfully added all SVGs in %s to the database at %s", *svgPath, *dbPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
|
func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
|
||||||
@@ -60,7 +67,6 @@ func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MakeTables(dbPath string, schema string) error {
|
func MakeTables(dbPath string, schema string) error {
|
||||||
// check if the database file and path exists. make them if they don't
|
|
||||||
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
|
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
|
||||||
if err = os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
if err = os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -73,9 +79,8 @@ func MakeTables(dbPath string, schema string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer db.Close()
|
|
||||||
if _, err = db.Exec(schema); err != nil {
|
if _, err = db.Exec(schema); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return db.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user