Test DB-Connection, Add CRUD Methods
This commit is contained in:
parent
faee833481
commit
a39f23411b
7 changed files with 139 additions and 13 deletions
|
@ -14,7 +14,41 @@ func InitDB(filepath string) *sql.DB {
|
|||
panic(err)
|
||||
}
|
||||
if db == nil {
|
||||
panic("db nil")
|
||||
panic("DB couldn't be initialized")
|
||||
}
|
||||
|
||||
// TODO: Change to correct DB-Structure
|
||||
statement, _ := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
|
||||
statement.Exec()
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
/*
|
||||
sqlStmt := fmt.Sprintf(`INSERT INTO data
|
||||
(id, content)
|
||||
VALUES
|
||||
(?, ?)`)
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
stmt, err := tx.Prepare(sqlStmt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
id := fmt.Sprintf("%d", i)
|
||||
content := fmt.Sprintf("content #%d %s", i, shortuuid.New())
|
||||
log.Printf("Inserting %s: %s", id, content)
|
||||
_, err := stmt.Exec(id, content)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
tx.Commit()
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue