// Save saves the AuthGroupPermission to the database.
760673
func (agp *AuthGroupPermission) Save(db XODB) error {
	if agp.Exists() {
		return agp.Update(db)
	}

	return agp.Insert(db)
}
1230942
func (s *DB) Save(value interface{}) *DB {
	scope := s.NewScope(value)
	if !scope.PrimaryKeyZero() {
		newDB := scope.callCallbacks(s.parent.callbacks.updates).db
		if newDB.Error == nil && newDB.RowsAffected == 0 {
			return s.New().FirstOrCreate(value)
		}
		return newDB
	}
	return scope.callCallbacks(s.parent.callbacks.creates).db
}
257950
func Save(collectionName string, doc interface{}) error {
	connection := shared.Connection()
	if connection == nil {
		log.Println("MongoConn", connection)
		return errors.New("No connection to database server")
	}
	err := Insert(collectionName, doc)
	if err == nil {
		return nil
	}
	return Update(collectionName, doc)
}
75969
func Save(args *RequestArgs) error {
	user := args.User
	appName := args.AppName
	org := args.Organization

	stats_query := utils.M{
		"user":     user,
		"app_name": appName,
		"org":      org,
	}

	save_doc := utils.M{
		"user":      user,
		"app_name":  appName,
		"org":       org,
		"timestamp": utils.EpochNow(),
	}

	return db.Conn.Upsert(db.StatsCollection, stats_query, save_doc)
}
993527
func save(filename, passphrase string, data map[string]string) error {
	buf, err := seal(data, passphrase)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(filename, buf, 0600)
}
1337287
func (m *GormResourceRepository) Save(ctx context.Context, resource *Resource) error {
	defer goa.MeasureSince([]string{"goa", "db", "resource", "save"}, time.Now())

	err := m.db.Save(resource).Error

	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"resource_id": resource.ResourceID,
			"err":         err,
		}, "unable to update the resource")
		return errs.WithStack(err)
	}

	log.Debug(ctx, map[string]interface{}{
		"resource_id": resource.ResourceID,
	}, "Resource saved!")

	return nil
}
1177003
func (w *wrappedWAL) Save(st raftpb.HardState, ents []raftpb.Entry) error {
	var writeEnts []raftpb.Entry
	for _, ent := range ents {
		data, err := encryption.Encrypt(ent.Data, w.encrypter)
		if err != nil {
			return err
		}
		writeEnts = append(writeEnts, raftpb.Entry{
			Index: ent.Index,
			Term:  ent.Term,
			Type:  ent.Type,
			Data:  data,
		})
	}

	return w.WAL.Save(st, writeEnts)
}
1208888
func (agp *AuthGroupPermission) Upsert(db XODB) error {
	var err error

	// if already exist, bail
	if agp._exists {
		return errors.New("insert failed: already exists")
	}

	// sql query
	const sqlstr = `INSERT INTO public.auth_group_permissions (` +
		`id, group_id, permission_id` +
		`) VALUES (` +
		`$1, $2, $3` +
		`) ON CONFLICT (id) DO UPDATE SET (` +
		`id, group_id, permission_id` +
		`) = (` +
		`EXCLUDED.id, EXCLUDED.group_id, EXCLUDED.permission_id` +
		`)`

	// run query
	XOLog(sqlstr, agp.ID, agp.GroupID, agp.PermissionID)
	_, err = db.Exec(sqlstr, agp.ID, agp.GroupID, agp.PermissionID)
	if err != nil {
		return err
	}

	// set existence
	agp._exists = true

	return nil
}
580229
func (b LeveldbAuthBackend) SaveUser(user UserData) error {
	b.users[user.Username] = user
	err := b.save()
	return err
}
914124
func (r *Repo) Save(ctx context.Context, entity eh.Entity) error {
	ns := r.namespace(ctx)

	if entity.EntityID() == uuid.Nil {
		return eh.RepoError{
			Err:       eh.ErrCouldNotSaveEntity,
			BaseErr:   eh.ErrMissingEntityID,
			Namespace: eh.NamespaceFromContext(ctx),
		}
	}

	r.dbMu.Lock()
	defer r.dbMu.Unlock()
	id := entity.EntityID()
	if _, ok := r.db[ns][id]; !ok {
		r.ids[ns] = append(r.ids[ns], id)
	}
	r.db[ns][id] = entity

	return nil
}
704780
func (agp *AuthGroupPermission) Insert(db XODB) error {
	var err error

	// if already exist, bail
	if agp._exists {
		return errors.New("insert failed: already exists")
	}

	// sql insert query, primary key provided by autoincrement
	const sqlstr = `INSERT INTO auth_group_permissions (` +
		`group_id, permission_id` +
		`) VALUES (` +
		`?, ?` +
		`)`

	// run query
	XOLog(sqlstr, agp.GroupID, agp.PermissionID)
	res, err := db.Exec(sqlstr, agp.GroupID, agp.PermissionID)
	if err != nil {
		return err
	}

	// retrieve id
	id, err := res.LastInsertId()
	if err != nil {
		return err
	}

	// set primary key and existence
	agp.ID = int(id)
	agp._exists = true

	return nil
}
943816
func (m *GormTokenRepository) Save(ctx context.Context, token *Token) error {
	defer goa.MeasureSince([]string{"goa", "db", "token", "save"}, time.Now())

	obj, err := m.Load(ctx, token.TokenID)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"token_id": token.TokenID,
			"err":      err,
		}, "unable to update token")
		return errs.WithStack(err)
	}

	err = m.db.Model(obj).Updates(token).Error
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"token_id": token.TokenID,
			"err":      err,
		}, "unable to update the token")

		return errs.WithStack(err)
	}

	log.Debug(ctx, map[string]interface{}{
		"token_id": token.TokenID,
	}, "Token saved!")

	return nil
}
319304
func (agp *AuthGroupPermission) AuthGroup(db XODB) (*AuthGroup, error) {
	return AuthGroupByID(db, agp.GroupID)
}
885041
func (aug *AuthUserGroup) Save(db XODB) error {
	if aug.Exists() {
		return aug.Update(db)
	}

	return aug.Insert(db)
}
232708
func (o *OAuthSession) Save(v Voter, category string) error {
	// Build form for POST request.
	form := url.Values{
		"id":       {v.voteID()},
		"category": {category},
	}
	var s interface{}

	err := o.postBody("https://oauth.reddit.com/api/save", form, s)
	if err != nil {
		return err
	}
	return nil
}
17812
func (m *GormIdentityRepository) Save(ctx context.Context, model *Identity) error {
	defer goa.MeasureSince([]string{"goa", "db", "identity", "save"}, time.Now())

	err := m.db.Save(model).Error

	log.Debug(ctx, map[string]interface{}{
		"identity_id": model.ID,
	}, "Identity saved!")

	return errs.WithStack(err)
}
144461
func (ds *DjangoSession) Save(db XODB) error {
	if ds.Exists() {
		return ds.Update(db)
	}

	return ds.Insert(db)
}