func NewUserRepoFromUsers(dbm *gorp.DbMap, us []user.UserWithRemoteIdentities) (user.UserRepo, error) { repo := NewUserRepo(dbm).(*userRepo) for _, u := range us { um, err := newUserModel(&u.User) if err != nil { return nil, err } err = repo.executor(nil).Insert(um) for _, ri := range u.RemoteIdentities { err = repo.AddRemoteIdentity(nil, u.User.ID, ri) if err != nil { return nil, err } } } return repo, nil }
func NewClientRepoFromClients(dbm *gorp.DbMap, cs []client.LoadableClient) (client.ClientRepo, error) { repo := NewClientRepo(dbm).(*clientRepo) for _, c := range cs { cm, err := newClientModel(c.Client) if err != nil { return nil, err } err = repo.executor(nil).Insert(cm) if err != nil { return nil, err } err = repo.SetTrustedPeers(nil, c.Client.Credentials.ID, c.TrustedPeers) if err != nil { return nil, err } } return repo, nil }