当前位置: 首页>>代码示例>>Golang>>正文


Golang meddler.Insert函数代码示例

本文整理汇总了Golang中github.com/russross/meddler.Insert函数的典型用法代码示例。如果您正苦于以下问题:Golang Insert函数的具体用法?Golang Insert怎么用?Golang Insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Insert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PostProblemSetBundle

// PostProblemSetBundle handles requests to /v2/problem_set/bundles,
// creating a new problem set.
func PostProblemSetBundle(w http.ResponseWriter, tx *sql.Tx, bundle ProblemSetBundle, render render.Render) {
	now := time.Now()

	if bundle.ProblemSet == nil {
		loggedHTTPErrorf(w, http.StatusBadRequest, "bundle must contain a problem set")
		return
	}
	set := bundle.ProblemSet
	if set.ID != 0 {
		loggedHTTPErrorf(w, http.StatusBadRequest, "a new problem set must not have an ID")
		return
	}
	if len(bundle.ProblemIDs) == 0 {
		loggedHTTPErrorf(w, http.StatusBadRequest, "a problem set must have at least one problem")
		return
	}
	if len(bundle.Weights) != len(bundle.ProblemIDs) {
		loggedHTTPErrorf(w, http.StatusBadRequest, "each problem must have exactly one associated weight")
		return
	}

	// clean up basic fields and do some checks
	if err := set.Normalize(now); err != nil {
		loggedHTTPErrorf(w, http.StatusBadRequest, "%v", err)
		return
	}

	// save the problem set object
	if err := meddler.Insert(tx, "problem_sets", set); err != nil {
		loggedHTTPErrorf(w, http.StatusInternalServerError, "db error: %v", err)
		return
	}

	// save the problem set problem list
	for i := 0; i < len(bundle.ProblemIDs); i++ {
		problemID, weight := bundle.ProblemIDs[i], bundle.Weights[i]
		if weight <= 0.0 {
			bundle.Weights[i] = 1.0
			weight = 1.0
		}
		psp := &ProblemSetProblem{
			ProblemSetID: set.ID,
			ProblemID:    problemID,
			Weight:       weight,
		}
		if err := meddler.Insert(tx, "problem_set_problems", psp); err != nil {
			loggedHTTPErrorf(w, http.StatusInternalServerError, "db error: %v", err)
			return
		}
	}

	log.Printf("problem set %s (%d) with %d problem(s) created", set.Unique, set.ID, len(bundle.ProblemIDs))

	render.JSON(http.StatusOK, bundle)
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:57,代码来源:problem_creation.go

示例2: createAccountSnapshot

// createAccountSnapshot creates an AccountSnapshot object.
func (a *AccountFeed) createAccountSnapshot(accountId int64) (core.AccountSnapshot, error) {
	snap := &core.AccountSnapshot{}
	snap.AccountId = accountId
	snap.Created = a.created
	err := meddler.Insert(a.tx, "account_snapshot", snap)
	return *snap, err
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:8,代码来源:account_feed.go

示例3: CreateLabel

func CreateLabel(db meddler.DB, name string) (*Label, error) {
	label := new(Label)
	label.Name = name

	err := meddler.Insert(db, "labels", label)
	return label, err
}
开发者ID:jasonrdsouza,项目名称:banktorrent,代码行数:7,代码来源:labels.go

示例4: CreateUser

func CreateUser(db meddler.DB, name string, email string, balance int) (*User, error) {
	user := new(User)
	user.Name = name
	user.Email = email
	user.Balance = balance

	err := meddler.Insert(db, "users", user)
	return user, err
}
开发者ID:jasonrdsouza,项目名称:banktorrent,代码行数:9,代码来源:users.go

示例5: CreateFeature

func (s *mySQLStore) CreateFeature(feature *models.Feature) error {
	feature.CreatedAt = time.Now()

	if err := meddler.Insert(s.db, "feature", feature); err != nil {
		return err
	}

	// update the feature to create all the status
	return s.UpdateFeature(feature)
}
开发者ID:medigo,项目名称:laika,代码行数:10,代码来源:mysql_store.go

示例6: store

// store writes the full updates into the database in a single transaction.
func (a *AccountFeed) store() error {
	for _, amt := range a.amounts {
		err := meddler.Insert(a.tx, "account_amount", &amt)
		if err != nil {
			return err
		}
	}

	for _, pos := range a.positions {
		for _, p := range pos {
			err := meddler.Insert(a.tx, "account_position", &p)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:20,代码来源:account_feed.go

示例7: CreateExpense

// Creates the expense in the db and gives it an ID
func CreateExpense(db meddler.DB, amount *MoneyAmount, label *Label, comment string, date time.Time) (*Expense, error) {
	expense := new(Expense)
	expense.Amount = amount.Int()
	expense.LabelId = label.Id
	expense.Comment = comment
	expense.Date = date.Format(DATE_FMT)

	err := meddler.Insert(db, "expenses", expense)
	return expense, err
}
开发者ID:jasonrdsouza,项目名称:banktorrent,代码行数:11,代码来源:expenses.go

示例8: Create

func (db *buildstore) Create(build *model.Build, jobs ...*model.Job) error {
	var number int
	db.QueryRow(rebind(buildNumberLast), build.RepoID).Scan(&number)
	build.Number = number + 1
	build.Created = time.Now().UTC().Unix()
	build.Enqueued = build.Created
	err := meddler.Insert(db, buildTable, build)
	if err != nil {
		return err
	}
	for i, job := range jobs {
		job.BuildID = build.ID
		job.Number = i + 1
		job.Enqueued = build.Created
		err = meddler.Insert(db, jobTable, job)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:allenbhuiyan,项目名称:drone,代码行数:21,代码来源:builds.go

示例9: CreateUser

func (s *mySQLStore) CreateUser(user *models.User) error {
	passwordHash, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)
	if err != nil {
		return err
	}

	user.Password = ""
	user.PasswordHash = string(passwordHash)

	user.CreatedAt = time.Now()
	return meddler.Insert(s.db, "user", user)
}
开发者ID:medigo,项目名称:laika,代码行数:12,代码来源:mysql_store.go

示例10: getSecurityType

// getSecurityType returns the SecurityType object, creating a database record if needed.
func (a *AccountFeed) getSecurityType(desc string) (core.SecurityType, error) {
	existing := new(core.SecurityType)
	err := meddler.QueryRow(a.tx, existing, "SELECT * FROM security_type WHERE security_type = $1", desc)
	if err != nil && err != sql.ErrNoRows {
		return *existing, err
	}

	if existing.Id != 0 {
		return *existing, nil
	}

	st := &core.SecurityType{}
	st.SecurityType = desc
	err = meddler.Insert(a.tx, "security_type", st)
	return *st, err
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:17,代码来源:account_feed.go

示例11: getAccount

// getAccount returns the Account object, creating a database record if needed.
func (a *AccountFeed) getAccount(accountKey string) (core.Account, error) {
	existing := new(core.Account)
	err := meddler.QueryRow(a.tx, existing, "SELECT * FROM account WHERE account_code = $1", accountKey)
	if err != nil && err != sql.ErrNoRows {
		return *existing, err
	}

	if existing.Id != 0 {
		return *existing, nil
	}

	acct := &core.Account{}
	acct.AccountCode = accountKey
	err = meddler.Insert(a.tx, "account", acct)
	return *acct, err
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:17,代码来源:account_feed.go

示例12: getSymbol

// getSymbol returns the Symbol object, creating a database record if needed.
func (a *AccountFeed) getSymbol(desc string) (core.Symbol, error) {
	existing := new(core.Symbol)
	err := meddler.QueryRow(a.tx, existing, "SELECT * FROM symbol WHERE symbol = $1", desc)
	if err != nil && err != sql.ErrNoRows {
		return *existing, err
	}

	if existing.Id != 0 {
		return *existing, nil
	}

	s := &core.Symbol{}
	s.Symbol = desc
	err = meddler.Insert(a.tx, "symbol", s)
	return *s, err
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:17,代码来源:account_feed.go

示例13: getAccountType

// getAccountType returns the AccountType object, creating a database record if needed.
func (a *AccountFeed) getAccountType(desc string) (core.AccountType, error) {
	existing := new(core.AccountType)
	err := meddler.QueryRow(a.tx, existing, "SELECT * FROM account_type WHERE type_desc = $1", desc)
	if err != nil && err != sql.ErrNoRows {
		return *existing, err
	}

	if existing.Id != 0 {
		return *existing, nil
	}

	at := &core.AccountType{}
	at.TypeDescription = desc
	err = meddler.Insert(a.tx, "account_type", at)
	return *at, err
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:17,代码来源:account_feed.go

示例14: getExchange

// getExchange returns the Exchange object, creating a database record if needed.
func (a *AccountFeed) getExchange(desc string) (core.Exchange, error) {
	existing := new(core.Exchange)
	err := meddler.QueryRow(a.tx, existing, "SELECT * FROM exchange WHERE exchange = $1", desc)
	if err != nil && err != sql.ErrNoRows {
		return *existing, err
	}

	if existing.Id != 0 {
		return *existing, nil
	}

	e := &core.Exchange{}
	e.Exchange = desc
	err = meddler.Insert(a.tx, "exchange", e)
	return *e, err
}
开发者ID:jacktang,项目名称:ibconnect.go,代码行数:17,代码来源:account_feed.go

示例15: addTransaction

// Adds a transaction to the db, and updates the user's balances accordingly
func addTransaction(db meddler.DB, lender *User, debtor *User, amount int, expense *Expense) (*Transaction, error) {
	trans := new(Transaction)
	trans.LenderId = lender.Id
	trans.DebtorId = debtor.Id
	trans.Amount = amount
	trans.Date = expense.Date
	trans.ExpenseId = expense.Id

	err := meddler.Insert(db, "transactions", trans)
	if err != nil {
		return nil, err
	}

	lender.UpdateBalance(db, amount)
	debtor.UpdateBalance(db, -amount)

	return trans, nil
}
开发者ID:jasonrdsouza,项目名称:banktorrent,代码行数:19,代码来源:transactions.go


注:本文中的github.com/russross/meddler.Insert函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。