當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。