Remove unused title field

This commit is contained in:
kageru 2018-11-04 22:14:34 +01:00
parent 99d20cf1f6
commit 645756d800
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 8 additions and 9 deletions

12
db.go
View File

@ -20,12 +20,12 @@ func initializeDatabase() {
}
func writeToDB(post BlogPost) {
stmt, _ := db.Prepare("INSERT INTO blogposts(author, title, content, time) VALUES (?, ?, ?, ?)")
stmt.Exec(post.Author, post.Title, post.Content, time.Now().Unix())
stmt, _ := db.Prepare("INSERT INTO blogposts(author, content, time) VALUES (?, ?, ?)")
stmt.Exec(post.Author, post.Content, time.Now().Unix())
}
func readBlogpostsFromDB() []BlogPost {
res, err := db.Query("SELECT content, author, title, time from blogposts")
res, err := db.Query("SELECT content, title, time from blogposts limit 50")
if err != nil {
log.Println("Error reading blogposts")
return make([]BlogPost, 0)
@ -38,10 +38,10 @@ func resultToBlogposts(res *sql.Rows) []BlogPost {
defer res.Close()
entries := make([]BlogPost, 0)
for res.Next() {
var content, author, title string
var content, author string
var timeInt int64
res.Scan(&content, &author, &title, &timeInt)
post := BlogPost{Content:content, Author:author, Title:title, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")}
res.Scan(&content, &author, &timeInt)
post := BlogPost{Content:content, Author:author, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")}
entries = append(entries, post)
}
return entries

View File

@ -16,7 +16,6 @@ func main() {
type BlogPost struct {
Id int64 `"id"`
Content string `"content"`
Title string `"title"`
Author string `"author"`
Secret string `"secret"`
Time time.Time `"time"`

2
schema
View File

@ -1 +1 @@
CREATE TABLE `blogposts` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `author` VARCHAR(32) NULL, `title` text NULL, `content` text null, `time` time null);
CREATE TABLE `blogposts` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `author` VARCHAR(32) NULL, `content` text null, `time` time null);

View File

@ -5,5 +5,5 @@ else
msg="$1"
fi
curl localhost:12345/add -d "{\"content\": \"$msg\", \"Title\": \"title\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v
curl localhost:12345/add -d "{\"content\": \"$msg\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v