package sqldb import ( "database/sql" "errors" ) func ResDataStore(key, value string, channel int) error { sqlStr := `INSERT OR REPLACE INTO db_unis_res_store VALUES(?,?,?)` res, err := db.Exec(sqlStr, key, value, channel) 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 ResDataGet(key string, channel int) (string, error) { sqlStr := `SELECT value FROM db_unis_res_store WHERE key=? AND channel=?` var res string if err := db.Get(&res, sqlStr, key, channel); err != nil { if errors.Is(err, sql.ErrNoRows) { return "", nil } return "", err } return res, nil }