Beispiel #1
0
/*
 * news functions
 */
func (n *News) SaveNews() error {
	// get database
	db, err := db.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()
	// insert kotoba
	_, err = db.Exec(insert_query, n.Title, n.Description)
	return err
}
Beispiel #2
0
func Test_MongoDB(t *testing.T) {
	db, err := db.GetDB()
	if err != nil {
		panic(err)
	}
	k := GetKotoba(66, db)
	fmt.Println(k)
	k.IncLevel()
	fmt.Println(k)
	fmt.Println(TimeUntil(k.Review))
	ks, _ := FindKotoba(2, "america", db)
	fmt.Println(ks)
}
Beispiel #3
0
func (n *News) UpdateNews() error {
	// get database
	db, err := db.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()
	// insert kotoba
	if n.Id == -1 {
		_, err = db.Exec(insert_query, n.Title, n.Description)
	} else {
		_, err = db.Exec(update_query, n.Title, n.Description, n.Id)
	}
	return err
}
Beispiel #4
0
func GetLastNews() (*[]News, error) {
	// get database
	db, err := db.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()
	err = db.Ping()
	if err != nil {
		panic(err.Error()) // proper error handling instead of panic in your app
	}
	// query kotoba
	rows, err := db.Query(select_5_last_query)
	if err != nil {
		panic(err.Error())
	}
	// get data from rows
	defer rows.Close()
	newsArray := GetNewsFromRow(rows)
	return newsArray, err
}