From 8486bb380900e514a6150109aef4cf30834fbc5c Mon Sep 17 00:00:00 2001 From: Minho Date: Fri, 2 Jun 2017 09:27:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8sqlite=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E4=B8=8B=E9=A1=B9=E7=9B=AE=E6=88=90=E5=91=98?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=9D=83=E9=99=90=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/command.go | 3 +++ models/relationship.go | 20 ++++++++++++++++---- utils/file.go | 10 ++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/commands/command.go b/commands/command.go index 4c27064e..020cc6cf 100644 --- a/commands/command.go +++ b/commands/command.go @@ -15,6 +15,7 @@ import ( "github.com/lifei6671/godoc/models" "strings" "github.com/lifei6671/godoc/commands/migrate" + "path/filepath" ) @@ -43,6 +44,8 @@ func RegisterDataBase() { } }else if adapter == "sqlite3" { database := beego.AppConfig.String("db_database") + dbPath := filepath.Dir(database) + os.MkdirAll(dbPath,0777) orm.RegisterDataBase("default", "sqlite3", database) } diff --git a/models/relationship.go b/models/relationship.go index e38881c5..c34904aa 100644 --- a/models/relationship.go +++ b/models/relationship.go @@ -79,7 +79,11 @@ func (m *Relationship) UpdateRoleId(book_id,member_id, role_id int) (*Relationsh } m.RoleId = role_id - _,err = o.InsertOrUpdate(m) + if m.RelationshipId > 0 { + _,err = o.Update(m) + }else{ + _,err = o.Insert(m) + } return m,err @@ -176,10 +180,18 @@ func (m *Relationship) Transfer(book_id,founder_id,receive_id int) error { o.Rollback() return err } - if _,err := o.InsertOrUpdate(receive);err != nil { - o.Rollback() - return err + if receive.RelationshipId > 0 { + if _,err := o.Update(receive);err != nil { + o.Rollback() + return err + } + }else{ + if _,err := o.Insert(receive);err != nil { + o.Rollback() + return err + } } + return o.Commit() } diff --git a/utils/file.go b/utils/file.go index 3014f7af..d413d5bb 100644 --- a/utils/file.go +++ b/utils/file.go @@ -23,3 +23,13 @@ func AbsolutePath(p string) (string,error) { } return s,nil } + +// FileExists reports whether the named file or directory exists. +func FileExists(name string) bool { + if _, err := os.Stat(name); err != nil { + if os.IsNotExist(err) { + return false + } + } + return true +} \ No newline at end of file