func (sis *SiteinfoService) saveToDB(db ab.DB, resp siteInfoResponse) error {
	_, err := db.Exec(
		"INSERT INTO siteinfo(url, blocks_iframe, has_embed_code) VALUES($1, $2, $3)",
		resp.Url,
		resp.BlocksIframe,
		resp.HasEmbedCode,
	)
	return err
}
Example #2
0
func (gud *GoogleUserDelegate) ResolveUniqueID(db ab.DB, entity ab.Entity) (string, error) {
	if user, ok := entity.(*User); ok {
		var uuid string
		err := db.QueryRow(`SELECT uuid FROM "user" WHERE mail = $1`, user.Mail).Scan(&uuid)
		if err != nil {
			return "", err
		}
		return uuid, nil
	}
	return "", nil
}
Example #3
0
func (e *Walkthrough) Insert(db ab.DB) error {
	if e.UUID == "" {
		e.UUID = uuid.NewRandom().String()
	}

	jsonSteps := ""

	bjsonSteps, _ := json.Marshal(e.Steps)
	jsonSteps = string(bjsonSteps)
	return db.QueryRow("INSERT INTO \"walkthrough\"(uuid, uid, name, description, steps, updated, published) VALUES($1, $2, $3, $4, $5, $6, $7) RETURNING revision", e.UUID, e.UID, e.Name, e.Description, jsonSteps, e.Updated, e.Published).Scan(&e.Revision)
}
func (sis *SiteinfoService) getFromDB(db ab.DB, site string) (siteInfoResponse, error) {
	resp := siteInfoResponse{}

	if err := db.QueryRow("SELECT blocks_iframe, has_embed_code FROM siteinfo WHERE url = $1 AND created > (now() - '1 month'::interval)", site).Scan(&resp.BlocksIframe, &resp.HasEmbedCode); err != nil {
		if err == sql.ErrNoRows {
			return resp, nil
		}
		return siteInfoResponse{}, err
	}

	resp.Url = site

	return resp, nil
}
Example #5
0
func (e *Walkthrough) Delete(db ab.DB) error {
	res, err := db.Exec("UPDATE walkthrough SET published = false WHERE UUID = $1", e.UUID)
	if err != nil {
		return err
	}

	aff, err := res.RowsAffected()
	if err != nil {
		return err
	}

	if aff < 1 {
		return WalkthroughNotFoundError
	}

	return nil
}