本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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))
}
}