当前位置: 首页>>代码示例>>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;未经允许,请勿转载。