本文整理汇总了Golang中github.com/coopernurse/gorp.SqlExecutor.Insert方法的典型用法代码示例。如果您正苦于以下问题:Golang SqlExecutor.Insert方法的具体用法?Golang SqlExecutor.Insert怎么用?Golang SqlExecutor.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coopernurse/gorp.SqlExecutor
的用法示例。
在下文中一共展示了SqlExecutor.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SaveOrUpdateMessage
func SaveOrUpdateMessage(entity models.MessageStruct, enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {
u := UserById(user.UniqueId().(int), db)
if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
entity.Last_modified_by = user.UniqueId().(int)
if entity.Id < 1 {
err := db.Insert(&entity)
if err != nil {
checkErr(err, "insert failed")
return http.StatusBadRequest, ""
}
} else {
obj, _ := db.Get(models.MessageStruct{}, entity.Id)
if obj == nil {
// Invalid id, or does not exist
return http.StatusBadRequest, ""
}
_, err := db.Update(&entity)
if err != nil {
checkErr(err, "update failed")
return http.StatusBadRequest, ""
}
}
return http.StatusOK, Must(enc.EncodeOne(entity))
}
return http.StatusUnauthorized, ""
}
示例2: AddContact_type
func AddContact_type(entity models.DefaultStruct, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {
err := db.Insert(&entity)
if err != nil {
checkErr(err, "INSERT CONTACT TYPE FAILED")
return http.StatusBadRequest, ""
}
w.Header().Set("Location", fmt.Sprintf("/warnabroda/contact_types/%d", entity.Id))
return http.StatusCreated, Must(enc.EncodeOne(entity))
}
示例3: AddMessage
func AddMessage(entity models.DefaultStruct, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {
err := db.Insert(&entity)
if err != nil {
checkErr(err, "insert failed")
return http.StatusBadRequest, ""
}
w.Header().Set("Location", fmt.Sprintf("/warnabroda/messages/%d", entity.Id))
return http.StatusCreated, Must(enc.EncodeOne(entity))
}
示例4: updateCategoires
func (m *Member) updateCategoires(s gorp.SqlExecutor) error {
// delete existing categories
format := "delete from " + TableNameCategoryMember + " where memberid = ?"
if _, err := s.Exec(format, m.ID); err != nil {
return err
}
// create new categories
for _, catId := range m.CategoryIds {
catMem := NewCategoryMember(catId, m.ID)
if err := s.Insert(catMem); err != nil {
return err
}
}
return nil
}
示例5: ProcessWarnReply
func ProcessWarnReply(warning *models.Warning, db gorp.SqlExecutor) {
fmt.Println("ProcessWarnReply")
warning.WarnResp.Id_warning = warning.Id
warning.WarnResp.Lang_key = warning.Lang_key
warning.WarnResp.Resp_hash = GenerateSha1(warning.Contact + "-" + warning.Created_date)
warning.WarnResp.Read_hash = GenerateSha1(warning.WarnResp.Reply_to + "-" + warning.Created_date)
warning.WarnResp.Reply_to = warning.WarnResp.Reply_to
warning.WarnResp.Created_date = warning.Created_date
if strings.Contains(warning.WarnResp.Reply_to, "@") {
warning.WarnResp.Id_contact_type = 1
} else {
warning.WarnResp.Id_contact_type = 3
}
err := db.Insert(warning.WarnResp)
checkErr(err, "INSERT WARNING ERROR")
}
示例6: AddWarning
// Receives a warning tru, inserts the request and process the warning and then respond to the interface
//TODO: use (session sessions.Session, r *http.Request) to prevent flood
func AddWarning(entity models.Warning, enc Encoder, db gorp.SqlExecutor, r *http.Request) (int, string) {
fmt.Println("AddWarning")
if isInvalidWarning(&entity) {
return http.StatusBadRequest, Must(enc.EncodeOne(entity))
}
status := &models.DefaultStruct{
Id: http.StatusOK,
Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_WARNING_SENT_SUCCESS"),
Lang_key: entity.Lang_key,
Type: models.MSG_TYPE_WARNING,
}
entity.Sent = false
entity.Created_by = "system"
//entity.Created_date = time.Now().String()
err := db.Insert(&entity)
checkErr(err, "INSERT WARNING ERROR")
if err != nil {
return http.StatusBadRequest, Must(enc.EncodeOne(entity))
}
ingnored := InIgnoreList(db, entity.Contact)
if ingnored != nil && ingnored.Confirmed {
status = &models.DefaultStruct{
Id: http.StatusBadRequest,
Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORED_USER"),
Lang_key: entity.Lang_key,
Type: models.MSG_TYPE_WARNING,
}
} else {
processWarn(&entity, db, status)
}
return http.StatusCreated, Must(enc.EncodeOne(status))
}
示例7: Save
func (app *App) Save(txn gorp.SqlExecutor) error {
return txn.Insert(app)
}
示例8: AddIgnoreList
// Add the request to be ignored for future warnings, it requires further confimation
func AddIgnoreList(entity models.Ignore_List, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {
if isInvalidIgnoreList(&entity) {
return http.StatusBadRequest, Must(enc.EncodeOne(entity))
}
status := &models.DefaultStruct{
Id: http.StatusOK,
Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_CONFIRM_IGNOREME"),
Lang_key: entity.Lang_key,
Type: models.MSG_TYPE_IGNORE,
}
if MoreThanTwoRequestByIp(db, &entity) {
status = &models.DefaultStruct{
Id: http.StatusBadRequest,
Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_TOO_MANY_IGNOREME_REQUESTS"),
Lang_key: entity.Lang_key,
Type: models.MSG_TYPE_IGNORE,
}
return http.StatusUnauthorized, Must(enc.EncodeOne(status))
}
ingnored := InIgnoreList(db, entity.Contact)
if ingnored != nil && ingnored.Confirmed {
status = &models.DefaultStruct{
Id: http.StatusBadRequest,
Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_CONTACT_ALREADY_IGNORED"),
Lang_key: entity.Lang_key,
}
return http.StatusUnauthorized, Must(enc.EncodeOne(status))
} else if ingnored != nil {
status = &models.DefaultStruct{
Id: http.StatusBadRequest,
Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORE_REQUEST_EXISTS"),
Lang_key: entity.Lang_key,
}
return http.StatusUnauthorized, Must(enc.EncodeOne(status))
}
rand.Seed(time.Now().UTC().UnixNano())
entity.Created_by = "user"
entity.Confirmed = false
entity.Confirmation_code = randomString(6)
errIns := db.Insert(&entity)
checkErr(errIns, "INSERT IGNORE FAIL")
if strings.Contains(entity.Contact, "@") {
status.Name += " via e-mail."
go SendEmailIgnoreme(&entity, db)
} else if strings.Contains(entity.Contact, "+55") {
status.Name += " via SMS."
go sendSMSIgnoreme(&entity, db)
}
//w.Header().Set("Location", fmt.Sprintf("/warnabroda/ignore-list/%d", entity.Id))
return http.StatusCreated, Must(enc.EncodeOne(status))
}
示例9: GetStories
func (ft FeedType) GetStories(s gorp.SqlExecutor, m *Member, f *Feed) error {
switch ft {
case FeedTypeRSS:
itemHandler := func(
fe *feeder.Feed,
ch *feeder.Channel,
newitems []*feeder.Item) {
for _, item := range newitems {
story := NewStoryRSS(m, f, item)
s.Insert(story)
}
}
feed := feeder.New(1, true, nil, itemHandler)
if err := feed.Fetch(f.Identifier, nil); err != nil {
fmt.Println(err)
}
case FeedTypeTwitter:
v := url.Values{}
v.Set("screen_name", f.Identifier)
v.Set("include_rts", "false")
anaconda.SetConsumerKey(os.Getenv("twitterApiKey"))
anaconda.SetConsumerSecret(os.Getenv("twitterApiSecret"))
api := anaconda.NewTwitterApi("", "")
tweets, err := api.GetUserTimeline(v)
if err != nil {
fmt.Println(err)
}
for _, t := range tweets {
story := NewStoryTwitter(m, f, t)
if err := s.Insert(story); err == nil {
fmt.Printf("Added Twitter story for %s. Date: %s Score: %f\n", m.Name, milli.Time(story.Timestamp).String(), story.Score)
} else {
fmt.Printf("Failed to add Twitter story for %s. Error: %s\n", m.Name, err)
}
}
case FeedTypeFacebook:
session := facebookSession()
route := fmt.Sprintf("/%s/posts", f.Identifier)
result, err := session.Api(route, facebook.GET, nil)
if err != nil {
fmt.Println(err)
}
posts := &FacebookPosts{}
if err := result.Decode(posts); err != nil {
fmt.Println(err)
}
for _, post := range posts.Data {
story := NewFacebookStory(m, f, post)
if story != nil {
if err := s.Insert(story); err == nil {
fmt.Printf("Added Facebook story for %s. Date: %s Score: %f\n", m.Name, milli.Time(story.Timestamp).String(), story.Score)
} else {
fmt.Printf("Failed to add Facebook story for %s. Error: %s\n", m.Name, err)
}
}
}
}
return nil
}
示例10: CreateBundle
func CreateBundle(txn gorp.SqlExecutor, bundle *Bundle) error {
return txn.Insert(bundle)
}
示例11: Save
func (bundle *Bundle) Save(txn gorp.SqlExecutor) error {
return txn.Insert(bundle)
}
示例12: CreateUser
func CreateUser(txn gorp.SqlExecutor, user *User) error {
return txn.Insert(user)
}
示例13: Save
func (user *User) Save(txn gorp.SqlExecutor) error {
return txn.Insert(user)
}
示例14: Save
func (authority *Authority) Save(txn gorp.SqlExecutor) error {
return txn.Insert(authority)
}
示例15: CreateAudit
func CreateAudit(txn gorp.SqlExecutor, audit *Audit) error {
return txn.Insert(audit)
}