summary refs log tree commit diff stats
path: root/storage/init.go
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-04-08 01:44:15 +0530
committerAndinus <andinus@nand.sh>2020-04-08 01:44:15 +0530
commit34adb3a7e676a43cd692b4da14398a7d1b0be822 (patch)
tree52d071f21eda3fdeb9768ecefb41df1c7ee551e8 /storage/init.go
parent47d22337b3a178b14e1cac287799f2c9dfb336e6 (diff)
downloadgrus-34adb3a7e676a43cd692b4da14398a7d1b0be822.tar.gz
Prepare for next rewrite
Diffstat (limited to 'storage/init.go')
-rw-r--r--storage/init.go63
1 files changed, 0 insertions, 63 deletions
diff --git a/storage/init.go b/storage/init.go
deleted file mode 100644
index 9894c5b..0000000
--- a/storage/init.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package storage
-
-import (
-	"database/sql"
-	"fmt"
-	"log"
-
-	_ "github.com/mattn/go-sqlite3"
-)
-
-// initErr will log the error and close the database connection if
-// necessary.
-func initErr(db *DB, err error) {
-	if db.Conn != nil {
-		db.Conn.Close()
-	}
-	log.Fatalf("Initialization Error :: %s", err.Error())
-}
-
-func initDB(db *DB) {
-	var err error
-
-	db.Path = fmt.Sprintf("%s/grus.db", GetDir())
-
-	db.Conn, err = sql.Open("sqlite3", db.Path)
-	if err != nil {
-		log.Printf("storage/init.go: %s\n",
-			"Failed to open database connection")
-		initErr(db, err)
-	}
-
-	sqlstmt := []string{
-		`CREATE TABLE IF NOT EXISTS words (
-        word   TEXT PRIMARY KEY NOT NULL,
-        sorted TEXT NOT NULL);`,
-		`INSERT INTO words(word, lexical)
-        values("grus", "grsu");`,
-	}
-
-	// We range over statements and execute them one by one, this
-	// is during initialization so it doesn't matter if it takes
-	// few more ms. This way we know which statement caused the
-	// program to fail.
-	for _, s := range sqlstmt {
-		stmt, err := db.Conn.Prepare(s)
-
-		if err != nil {
-			log.Printf("storage/init.go: %s\n",
-				"failed to prepare statement")
-			log.Println(s)
-			initErr(db, err)
-		}
-
-		_, err = stmt.Exec()
-		stmt.Close()
-		if err != nil {
-			log.Printf("storage/init.go: %s\n",
-				"failed to execute statement")
-			log.Println(s)
-			initErr(db, err)
-		}
-	}
-}