Merge branch 'main' of https://github.com/Poomipat-Ch/taobin_recipe_manager
This commit is contained in:
commit
96f341aa28
26 changed files with 1068 additions and 664 deletions
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
|
|
@ -39,7 +38,7 @@ func HashCommit(n int) (string, error) {
|
|||
byt := make([]byte, n)
|
||||
_, err := rand.Read(byt)
|
||||
if err != nil {
|
||||
Log.Debug("Error when hashing commit", zap.Error(err))
|
||||
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(byt), nil
|
||||
|
|
@ -48,14 +47,14 @@ func HashCommit(n int) (string, error) {
|
|||
func Insert(c *CommitLog) error {
|
||||
commit_db, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||
if err != nil {
|
||||
Log.Fatal("Error when connecting to database", zap.Error(err))
|
||||
|
||||
}
|
||||
// init table in db
|
||||
commit_db.MustExec(schema)
|
||||
|
||||
_, err = commit_db.NamedExec("INSERT INTO commit_log (id, msg, created_at, editor, change_file) VALUES (:id, :msg, :created_at, :editor, :change_file)", c)
|
||||
if err != nil {
|
||||
Log.Error("Error when insert commit log", zap.Error(err))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -74,11 +73,9 @@ func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, err
|
|||
filename = filenameParts[1] + "_" + filenameParts[2]
|
||||
}
|
||||
|
||||
Log.Debug("CommitDB", zap.Any("lookup", filename))
|
||||
|
||||
commitDB, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||
if err != nil {
|
||||
Log.Fatal("Error when connecting to database", zap.Error(err))
|
||||
|
||||
}
|
||||
|
||||
var commits []CommitLog
|
||||
|
|
@ -96,7 +93,6 @@ func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, err
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
Log.Error("Error when get commit log", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -106,14 +102,14 @@ func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, err
|
|||
func GetCommitLogs() ([]CommitLog, error) {
|
||||
commit_db, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||
if err != nil {
|
||||
Log.Fatal("Error when connecting to database", zap.Error(err))
|
||||
|
||||
}
|
||||
|
||||
var commits []CommitLog
|
||||
err = commit_db.Get(&commits, "SELECT * FROM commit_log", nil)
|
||||
|
||||
if err != nil {
|
||||
Log.Error("Error when get commit log", zap.Error(err))
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue