41 lines
850 B
Go
41 lines
850 B
Go
package sqldb
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
)
|
|
|
|
func ResFulDataStore(methord, url, response, body string, channel int) error {
|
|
sqlStr := `INSERT OR REPLACE INTO db_unis_res_store(url,body,channel,methord,response) VALUES(?,?,?,?,?)`
|
|
|
|
res, err := db.Exec(sqlStr, url, body, channel, methord, response)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
count, err := res.RowsAffected()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if count == 0 {
|
|
return errors.New("sql insert res_store rows affected 0")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func ResFulDataGet(methord, url string, channel int) (string, error) {
|
|
sqlStr := `SELECT body FROM db_unis_res_store WHERE url=? AND channel=? AND methord=?`
|
|
|
|
var res string
|
|
if err := db.Get(&res, sqlStr, url, channel, methord); err != nil {
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return "", nil
|
|
}
|
|
return "", err
|
|
}
|
|
|
|
return res, nil
|
|
}
|