// Create create a user in Database
514285
func (repo *repo) Create(user service.Entity) bool {
	if dbconn.DB.NewRecord(user) {
		dbconn.DB.Create(&user)
	}
	return !dbconn.DB.NewRecord(user)
}
850857
func (idx *AddrIndex) Create(dbTx database.Tx) error {
	_, err := dbTx.Metadata().CreateBucket(addrIndexKey)
	return err
}
141069
func (u *User) Create(db *sqlx.DB, fidT FlexIDType, fid string) error {
	// Create the password hash
	hpw, err := bcrypt.GenerateFromPassword([]byte(u.Password), 10)
	if err != nil {
		return err
	}
	tx, err := db.Beginx()
	if err != nil {
		return err
	}
	q := `INSERT INTO users (name, email, password, locationid, admin)
	      VALUES ($1, $2, $3, 0, $4)
	      RETURNING id`
	var uid uint64
	err = tx.QueryRowx(q, u.Name, u.Email, hpw, u.Admin).Scan(&uid)
	if err != nil && err.Error() ==
		`pq: duplicate key value violates unique constraint "users_email_key"` {
		_ = tx.Rollback()
		return err
	}
	if uid == 0 {
		_ = tx.Rollback()
		return err
	}
	q = `INSERT INTO userflexids (userid, flexid, flexidtype)
	     VALUES ($1, $2, $3)`
	_, err = tx.Exec(q, uid, u.Email, 1)
	if err != nil {
		_ = tx.Rollback()
		return err
	}
	_, err = tx.Exec(q, uid, fid, 2)
	if err != nil {
		_ = tx.Rollback()
		return err
	}
	if err = tx.Commit(); err != nil {
		return err
	}
	u.ID = uid
	return nil
}
1227003
func (s *Service) Create(ctx context.Context, m *platform.DBRPMapping) error {
	if err := m.Validate(); err != nil {
		return nil
	}
	existing, err := s.loadDBRPMapping(ctx, m.Cluster, m.Database, m.RetentionPolicy)
	if err != nil {
		if err == errDBRPMappingNotFound {
			return s.PutDBRPMapping(ctx, m)
		}
		return err
	}

	if !existing.Equal(m) {
		return errors.New("dbrp mapping already exists")
	}

	return s.PutDBRPMapping(ctx, m)
}
1356400
func (r *AdminService) CreateUser(adminuserreq *AdminUserReq) *AdminCreateUserCall {
	c := &AdminCreateUserCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	c.adminuserreq = adminuserreq
	return c
}
472740
func (d *DataBagService) Create(databag *DataBag) (result *DataBagCreateResult, err error) {
	body, err := JSONReader(databag)
	if err != nil {
		return
	}

	err = d.client.magicRequestDecoder("POST", "data", body, &result)
	return
}
27608
func (i *Influxdb) CreateUser(ctx context.Context, statements dbplugin.Statements, usernameConfig dbplugin.UsernameConfig, expiration time.Time) (username string, password string, err error) {
	// Grab the lock
	i.Lock()
	defer i.Unlock()

	statements = dbutil.StatementCompatibilityHelper(statements)

	// Get the connection
	cli, err := i.getConnection(ctx)
	if err != nil {
		return "", "", err
	}

	creationIFQL := statements.Creation
	if len(creationIFQL) == 0 {
		creationIFQL = []string{defaultUserCreationIFQL}
	}

	rollbackIFQL := statements.Rollback
	if len(rollbackIFQL) == 0 {
		rollbackIFQL = []string{defaultUserDeletionIFQL}
	}

	username, err = i.GenerateUsername(usernameConfig)
	username = strings.Replace(username, "-", "_", -1)
	if err != nil {
		return "", "", err
	}
	username = strings.ToLower(username)
	password, err = i.GeneratePassword()
	if err != nil {
		return "", "", err
	}

	// Execute each query
	for _, stmt := range creationIFQL {
		for _, query := range strutil.ParseArbitraryStringSlice(stmt, ";") {
			query = strings.TrimSpace(query)
			if len(query) == 0 {
				continue
			}

			q := influx.NewQuery(dbutil.QueryHelper(query, map[string]string{
				"username": username,
				"password": password,
			}), "", "")
			response, err := cli.Query(q)
			if err != nil && response.Error() != nil {
				for _, stmt := range rollbackIFQL {
					for _, query := range strutil.ParseArbitraryStringSlice(stmt, ";") {
						query = strings.TrimSpace(query)

						if len(query) == 0 {
							continue
						}
						q := influx.NewQuery(dbutil.QueryHelper(query, map[string]string{
							"username": username,
						}), "", "")

						response, err := cli.Query(q)
						if err != nil && response.Error() != nil {
							return "", "", err
						}
					}
				}
				return "", "", err
			}
		}
	}
	return username, password, nil
}
380505
func (lu *LookupUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error {
	return lu.lkp.Create(vcursor, rowsColValues, ksidsToValues(ksids), ignoreMode)
}
464184
func (u *UserService) createUser(request *restful.Request, response *restful.Response) {
	c := appengine.NewContext(request.Request)
	usr := User{Id: request.PathParameter("user-id")}
	err := request.ReadEntity(&usr)
	if err == nil {
		item := &memcache.Item{
			Key:    usr.Id,
			Object: &usr,
		}
		err = memcache.Gob.Add(c, item)
		if err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}
		response.WriteHeader(http.StatusCreated)
		response.WriteEntity(usr)
	} else {
		response.WriteError(http.StatusInternalServerError, err)
	}
}
773665
func (r *GormQueryRepository) Create(ctx context.Context, q *Query) error {
	defer goa.MeasureSince([]string{"goa", "db", "Query", "create"}, time.Now())
	q.ID = uuid.NewV4()
	if q.Creator == uuid.Nil {
		return errors.NewBadParameterError("creator cannot be nil", q.Creator).Expected("valid user ID")
	}
	var v map[string]interface{}
	if err := json.Unmarshal([]byte(q.Fields), &v); err != nil {
		return errors.NewBadParameterError("query field is invalid JSON syntax", q.Fields).Expected("valid JSON")
	}
	// Parse fields to make sure that query is valid
	exp, _, err := search.ParseFilterString(ctx, q.Fields)
	if err != nil || exp == nil {
		log.Error(ctx, map[string]interface{}{
			"space_id": q.SpaceID,
			"fields":   q.Fields,
		}, "unable to parse the query fields")
		return err
	}
	err = r.db.Create(q).Error
	if err != nil {
		if gormsupport.IsCheckViolation(err, "queries_title_check") {
			return errors.NewBadParameterError("Title", q.Title).Expected("not empty")
		}
		// combination of title, space ID and creator should be unique
		if gormsupport.IsUniqueViolation(err, "queries_title_space_id_creator_unique") {
			log.Error(ctx, map[string]interface{}{
				"err":      err,
				"title":    q.Title,
				"space_id": q.SpaceID,
			}, "unable to create query because a query with same title already exists in the space by same creator")
			return errors.NewDataConflictError(fmt.Sprintf("query already exists with title = %s , space_id = %s, creator = %s", q.Title, q.SpaceID, q.Creator))
		}
		log.Error(ctx, map[string]interface{}{}, "error adding Query: %s", err.Error())
		return err
	}
	return nil
}
607987
func (s *Service) CreateUser(ctx context.Context, u *influxdb.User) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		return s.createUser(ctx, tx, u)
	})
}
578762
func (idx *TxIndex) Create(dbTx database.Tx) error {
	meta := dbTx.Metadata()
	if _, err := meta.CreateBucket(idByHashIndexBucketName); err != nil {
		return err
	}
	if _, err := meta.CreateBucket(hashByIDIndexBucketName); err != nil {
		return err
	}
	_, err := meta.CreateBucket(txIndexKey)
	return err
}
432449
func (crud *repo) Create(profile service.Entity) bool {
	if dbconn.DB.NewRecord(profile) {
		dbconn.DB.Create(&profile)
	}
	return !dbconn.DB.NewRecord(profile)
}
100386
func (c *httpClient) CreateDatabase(ctx context.Context, database string) error {
	query := fmt.Sprintf(`CREATE DATABASE "%s"`,
		escapeIdentifier.Replace(database))

	req, err := c.makeQueryRequest(query)

	resp, err := c.client.Do(req.WithContext(ctx))
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	queryResp := &QueryResponse{}
	dec := json.NewDecoder(resp.Body)
	err = dec.Decode(queryResp)

	if err != nil {
		if resp.StatusCode == 200 {
			c.createdDatabases[database] = true
			return nil
		}

		return &APIError{
			StatusCode: resp.StatusCode,
			Title:      resp.Status,
		}
	}

	// Even with a 200 response there can be an error
	if resp.StatusCode == http.StatusOK && queryResp.Error() == "" {
		c.createdDatabases[database] = true
		return nil
	}

	return &APIError{
		StatusCode:  resp.StatusCode,
		Title:       resp.Status,
		Description: queryResp.Error(),
	}
}
231999
func (client *Client) CreateUser(uaaUserID string) (User, Warnings, error) {
	type userRequestBody struct {
		GUID string `json:"guid"`
	}

	bodyBytes, err := json.Marshal(userRequestBody{
		GUID: uaaUserID,
	})
	if err != nil {
		return User{}, nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PostUserRequest,
		Body:        bytes.NewReader(bodyBytes),
	})
	if err != nil {
		return User{}, nil, err
	}

	var user User
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &user,
	}

	err = client.connection.Make(request, &response)
	if err != nil {
		return User{}, response.Warnings, err
	}

	return user, response.Warnings, nil
}
450898
func (c *Client) CreateUser(p *CreateUserParameter) (*User, error) {
	obj, err := c.Request("createUser", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*User), err
}
491843
func (m *GormRoleMappingRepository) Create(ctx context.Context, u *RoleMapping) error {
	defer goa.MeasureSince([]string{"goa", "db", "role_mapping", "create"}, time.Now())
	if u.RoleMappingID == uuid.Nil {
		u.RoleMappingID = uuid.NewV4()
	}
	err := m.db.Create(u).Error
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"role_mapping_id": u.RoleMappingID,
			"err":             err,
		}, "unable to create the role mapping")
		return errs.WithStack(err)
	}
	log.Debug(ctx, map[string]interface{}{
		"role_mapping_id": u.RoleMappingID,
	}, "Role mapping created!")
	return nil
}