當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Tx.Create方法代碼示例

本文整理匯總了Golang中periwinkle.Tx.Create方法的典型用法代碼示例。如果您正苦於以下問題:Golang Tx.Create方法的具體用法?Golang Tx.Create怎麽用?Golang Tx.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在periwinkle.Tx的用法示例。


在下文中一共展示了Tx.Create方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewGroup

func NewGroup(db *periwinkle.Tx, name string, existence []int, read []int, post []int, join []int) *Group {
	if name == "" {
		programmerError("Group name can't be empty")
	}
	name = strings.ToLower(name)
	subscriptions := make([]Subscription, 0)
	o := Group{
		ID:                 name,
		ReadPublic:         read[0],
		ReadConfirmed:      read[1],
		ExistencePublic:    existence[0],
		ExistenceConfirmed: existence[1],
		PostPublic:         post[0],
		PostConfirmed:      post[1],
		PostMember:         post[2],
		JoinPublic:         join[0],
		JoinConfirmed:      join[1],
		JoinMember:         join[2],
		Subscriptions:      subscriptions,
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:25,代碼來源:group.go

示例2: dbSeed

func (o Medium) dbSeed(db *periwinkle.Tx) locale.Error {
	errs := errorList{}
	errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"email"}).Error))
	errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"sms"}).Error))
	errHelper(&errs, locale.UntranslatedError(db.Create(&Medium{"mms"}).Error))
	if len(errs) > 0 {
		return errs
	}
	return nil
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:10,代碼來源:medium.go

示例3: NewShortURL

func NewShortURL(db *periwinkle.Tx, u *url.URL) *ShortURL {
	o := ShortURL{
		ID:   RandomString(5),
		Dest: u.String(), // TODO: automatic marshalling
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:10,代碼來源:shorturl.go

示例4: NewCaptcha

func NewCaptcha(db *periwinkle.Tx) *Captcha {
	o := Captcha{
		ID:    captcha.New(),
		Value: string(captcha.RandomDigits(defaultLen)),
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:10,代碼來源:captcha.go

示例5: NewSubscription

func NewSubscription(db *periwinkle.Tx, addressID int64, groupID string, confirmed bool) Subscription {
	subscription := Subscription{
		AddressID: addressID,
		GroupID:   groupID,
		Confirmed: confirmed,
	}
	if err := db.Create(&subscription).Error; err != nil {
		dbError(err)
	}
	return subscription
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:11,代碼來源:subscription.go

示例6: NewUserAddress

func NewUserAddress(db *periwinkle.Tx, userID string, medium string, address string, confirmed bool) UserAddress {
	userID = strings.ToLower(userID)
	o := UserAddress{
		UserID:    userID,
		Medium:    medium,
		Address:   address,
		Confirmed: confirmed,
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:13,代碼來源:user.go

示例7: NewMessage

func NewMessage(db *periwinkle.Tx, id string, group Group, unique maildir.Unique) Message {
	if id == "" {
		programmerError("Message ID can't be emtpy")
	}
	o := Message{
		ID:      id,
		GroupID: group.ID,
		Unique:  string(unique),
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:14,代碼來源:message.go

示例8: NewSession

func NewSession(db *periwinkle.Tx, user *User, password string) *Session {
	if user == nil || !user.CheckPassword(password) {
		return nil
	}
	o := Session{
		ID:       RandomString(24),
		UserID:   user.ID,
		LastUsed: time.Now(),
	}
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return &o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:14,代碼來源:session.go

示例9: NewUser

func NewUser(db *periwinkle.Tx, name string, password string, email string) User {
	if name == "" {
		programmerError("User name can't be empty")
	}
	name = strings.ToLower(name)
	o := User{
		ID:        name,
		FullName:  "",
		Addresses: []UserAddress{{Medium: "email", Address: email, Confirmed: false}},
	}
	o.SetPassword(password)
	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}
	return o
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:16,代碼來源:user.go

示例10: dbSeed

func (o Group) dbSeed(db *periwinkle.Tx) locale.Error {
	existence := [2]int{2, 2}
	read := [2]int{2, 2}
	post := [3]int{1, 1, 1}
	join := [3]int{1, 1, 1}
	return locale.UntranslatedError(db.Create(&Group{
		ID:                 "test",
		ReadPublic:         read[0],
		ReadConfirmed:      read[1],
		ExistencePublic:    existence[0],
		ExistenceConfirmed: existence[1],
		PostPublic:         post[0],
		PostConfirmed:      post[1],
		PostMember:         post[2],
		JoinPublic:         join[0],
		JoinConfirmed:      join[1],
		JoinMember:         join[2],
		Subscriptions:      []Subscription{},
	}).Error)
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:20,代碼來源:group.go

示例11: AssignTwilioNumber

func AssignTwilioNumber(db *periwinkle.Tx, userid string, groupid string, twilioNum string) *TwilioPool {

	num := TwilioNumber{}
	err := db.Where(TwilioNumber{Number: twilioNum}).FirstOrCreate(&num).Error

	if err != nil {
		dbError(err)
	}

	o := TwilioPool{
		UserID:   userid,
		GroupID:  groupid,
		NumberID: num.ID,
	}

	if err := db.Create(&o).Error; err != nil {
		dbError(err)
	}

	return &o

}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:22,代碼來源:twilio.go

示例12: Test

func Test(cfg *periwinkle.Cfg, db *periwinkle.Tx) {

	num := backend.TwilioNumber{
		Number: "+13346038139",
	}

	if err := db.Create(&num).Error; err != nil {
		panic(err)
	}

	user1 := backend.User{
		ID:        "alex",
		FullName:  "",
		Addresses: []backend.UserAddress{{Medium: "email", Address: "[email protected]", Confirmed: true}},
	}

	uerr := db.Create(&user1).Error
	if uerr != nil {
		periwinkle.LogErr(locale.UntranslatedError(uerr))
	}

	user2 := backend.User{
		ID:        "john",
		FullName:  "",
		Addresses: []backend.UserAddress{{Medium: "sms", Address: "+17656027006", Confirmed: true}, {Medium: "email", Address: "[email protected]", Confirmed: true}},
	}

	uerr = db.Create(&user2).Error
	if uerr != nil {
		periwinkle.LogErr(locale.UntranslatedError(uerr))
	}

	user3 := backend.User{
		ID:        "guntas",
		FullName:  "",
		Addresses: []backend.UserAddress{{Medium: "sms", Address: "+16166342620", Confirmed: true}},
	}

	uerr = db.Create(&user3).Error
	if uerr != nil {
		periwinkle.LogErr(locale.UntranslatedError(uerr))
	}
	existence := [2]int{2, 2}
	read := [2]int{2, 2}
	post := [3]int{1, 1, 1}
	join := [3]int{1, 1, 1}
	uerr = db.Create(&backend.Group{
		ID:                 "Purdue",
		ReadPublic:         read[0],
		ReadConfirmed:      read[1],
		ExistencePublic:    existence[0],
		ExistenceConfirmed: existence[1],
		PostPublic:         post[0],
		PostConfirmed:      post[1],
		PostMember:         post[2],
		JoinPublic:         join[0],
		JoinConfirmed:      join[1],
		JoinMember:         join[2],
		Subscriptions: []backend.Subscription{
			{AddressID: user1.Addresses[0].ID, Confirmed: true},
			{AddressID: user2.Addresses[0].ID, Confirmed: true},
			{AddressID: user2.Addresses[1].ID, Confirmed: true},
			{AddressID: user3.Addresses[0].ID, Confirmed: true},
		},
	}).Error
	if uerr != nil {
		periwinkle.LogErr(locale.UntranslatedError(uerr))
	}
}
開發者ID:LukeShu,項目名稱:periwinkle,代碼行數:69,代碼來源:testing.go


注:本文中的periwinkle.Tx.Create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。