Example #1
0
func (b *AccountManagerBinding) get(
	db gorp.SqlExecutor, id snowflake.Snowflake) (*AccountBinding, error) {

	var row AccountWithStaffCapability
	err := db.SelectOne(
		&row,
		"SELECT a.id, a.nonce, a.mac, a.encrypted_system_key, a.encrypted_user_key,"+
			" a.encrypted_private_key, a.public_key,"+
			" c.id AS staff_capability_id, c.nonce AS staff_capability_nonce,"+
			" c.encrypted_private_data, c.public_data"+
			" FROM account a LEFT OUTER JOIN capability c ON a.staff_capability_id = c.id"+
			" WHERE a.id = $1",
		id.String())
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, proto.ErrAccountNotFound
		}
		return nil, err
	}

	ab := row.Bind(b.Backend)

	rows, err := db.Select(
		PersonalIdentity{},
		"SELECT namespace, id, account_id, verified FROM personal_identity WHERE account_id = $1",
		id.String())
	switch err {
	case sql.ErrNoRows:
	case nil:
		ab.identities = make([]proto.PersonalIdentity, len(rows))
		for i, row := range rows {
			ab.identities[i] = &PersonalIdentityBinding{row.(*PersonalIdentity)}
		}
	default:
		return nil, err
	}

	return ab, nil
}