本文整理匯總了Golang中github.com/eirka/eirka-libs/db.GetDb函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetDb函數的具體用法?Golang GetDb怎麽用?Golang GetDb使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetDb函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Delete
// Delete will remove the entry
func (m *DeleteImageTagModel) Delete() (err error) {
// check model validity
if !m.IsValid() {
return errors.New("DeleteImageTagModel is not valid")
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
ps1, err := dbase.Prepare(`DELETE tm FROM tagmap AS tm
INNER JOIN tags ON tm.tag_id = tags.tag_id
WHERE image_id = ? AND tm.tag_id = ? AND ib_id = ?`)
if err != nil {
return
}
defer ps1.Close()
_, err = ps1.Exec(m.Image, m.Tag, m.Ib)
if err != nil {
return
}
return
}
示例2: Delete
// Delete will remove the entry
func (m *DeleteTagModel) Delete() (err error) {
// check model validity
if !m.IsValid() {
return errors.New("DeleteTagModel is not valid")
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
ps1, err := dbase.Prepare("DELETE FROM tags WHERE tag_id= ? AND ib_id = ? LIMIT 1")
if err != nil {
return
}
defer ps1.Close()
_, err = ps1.Exec(m.ID, m.Ib)
if err != nil {
return
}
return
}
示例3: Update
// Update will update the entry
func (m *UpdateTagModel) Update() (err error) {
// check model validity
if !m.IsValid() {
return errors.New("UpdateTagModel is not valid")
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
ps1, err := dbase.Prepare("UPDATE tags SET tag_name= ?, tagtype_id= ? WHERE tag_id = ? AND ib_id = ?")
if err != nil {
return
}
defer ps1.Close()
_, err = ps1.Exec(m.Tag, m.TagType, m.ID, m.Ib)
if err != nil {
return
}
return
}
示例4: FromName
// FromName will get the password and user id from the database for a user name
func (u *User) FromName(name string) (err error) {
// name cant be empty
if len(name) == 0 {
return e.ErrUserNotValid
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// get hashed password from database
err = dbase.QueryRow("select user_id, user_password from users where user_name = ?", name).Scan(&u.ID, &u.hash)
if err != nil {
return
}
u.SetAuthenticated()
if !u.IsValid() {
return e.ErrUserNotValid
}
return
}
示例5: Delete
// Delete will remove the entry
func (m *DeleteThreadModel) Delete() (err error) {
// check model validity
if !m.IsValid() {
return errors.New("DeleteThreadModel is not valid")
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
ps1, err := dbase.Prepare("UPDATE threads SET thread_deleted = ? WHERE thread_id = ? AND ib_id = ?")
if err != nil {
return
}
defer ps1.Close()
_, err = ps1.Exec(!m.Deleted, m.ID, m.Ib)
if err != nil {
return
}
return
}
示例6: PruneAnalytics
// PruneAnalytics will remove old entries from the analytics table
func PruneAnalytics() {
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
_, err = dbase.Exec("DELETE FROM analytics WHERE request_time < (now() - interval 1 month)")
if err != nil {
return
}
return
}
示例7: Status
// Status will return info
func (m *DeleteImageTagModel) Status() (err error) {
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// Check if the tag is there
err = dbase.QueryRow("SELECT tag_name FROM tags WHERE tag_id = ? AND ib_id = ? LIMIT 1", m.Tag, m.Ib).Scan(&m.Name)
if err == sql.ErrNoRows {
return e.ErrNotFound
} else if err != nil {
return
}
return
}
示例8: Status
// Status will return info
func (m *PurgePostModel) Status() (err error) {
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// get thread ib and title
err = dbase.QueryRow("SELECT thread_title FROM threads WHERE thread_id = ? AND ib_id = ? LIMIT 1", m.Thread, m.Ib).Scan(&m.Name)
if err == sql.ErrNoRows {
return e.ErrNotFound
} else if err != nil {
return
}
return
}
示例9: Status
// Status will return info
func (m *PurgeThreadModel) Status() (err error) {
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// Check if favorite is already there
err = dbase.QueryRow("SELECT thread_title FROM threads WHERE thread_id = ? AND ib_id = ? LIMIT 1", m.ID, m.Ib).Scan(&m.Name)
if err == sql.ErrNoRows {
return e.ErrNotFound
} else if err != nil {
return
}
return
}
示例10: Submit
// Submit will insert audit info into the audit log
func (m *Audit) Submit() (err error) {
if !m.IsValid() {
return errors.New("Audit not valid")
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
_, err = dbase.Exec("INSERT INTO audit (user_id,ib_id,audit_type,audit_ip,audit_time,audit_action,audit_info) VALUES (?,?,?,?,NOW(),?,?)",
m.User, m.Ib, m.Type, m.IP, m.Action, m.Info)
if err != nil {
return
}
return
}
示例11: IsAuthorized
// IsAuthorized will get the perms and role info from the userid
func (u *User) IsAuthorized(ib uint) bool {
var err error
if !u.IsValid() {
return false
}
// check for invalid stuff
if ib == 0 {
return false
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return false
}
// holds our role
var role uint
// get data from users table
err = dbase.QueryRow(`SELECT COALESCE((SELECT MAX(role_id) FROM user_ib_role_map WHERE user_ib_role_map.user_id = users.user_id AND ib_id = ?),user_role_map.role_id) as role
FROM users
INNER JOIN user_role_map ON (user_role_map.user_id = users.user_id)
WHERE users.user_id = ?`, ib, u.ID).Scan(&role)
if err != nil {
return false
}
switch role {
case 3:
return true
case 4:
return true
default:
return false
}
}
示例12: Password
// Password will get the password and name from the database for an instantiated user
func (u *User) Password() (err error) {
// check user struct validity
if !u.IsValid() {
return e.ErrUserNotValid
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// get hashed password from database
err = dbase.QueryRow("select user_name, user_password from users where user_id = ?", u.ID).Scan(&u.Name, &u.hash)
if err != nil {
return
}
return
}
示例13: Status
// Status will return info
func (m *BanIPModel) Status() (err error) {
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// get thread ib and title
err = dbase.QueryRow(`SELECT post_ip FROM threads
INNER JOIN posts ON threads.thread_id = posts.thread_id
WHERE ib_id = ? AND threads.thread_id = ? AND post_num = ? LIMIT 1`, m.Ib, m.Thread, m.ID).Scan(&m.IP)
if err == sql.ErrNoRows {
return e.ErrNotFound
} else if err != nil {
return
}
return
}
示例14: Status
// Status will return info
func (m *DeletePostModel) Status() (err error) {
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return
}
// get thread ib and title
err = dbase.QueryRow(`SELECT thread_title, post_deleted FROM threads
INNER JOIN posts on threads.thread_id = posts.thread_id
WHERE threads.thread_id = ? AND ib_id = ? LIMIT 1`, m.Thread, m.Ib).Scan(&m.Name, &m.Deleted)
if err == sql.ErrNoRows {
return e.ErrNotFound
} else if err != nil {
return
}
return
}
示例15: CheckDuplicate
// CheckDuplicate will check for duplicate name before registering
func CheckDuplicate(name string) (check bool) {
// name cant be empty
if len(name) == 0 {
return true
}
// Get Database handle
dbase, err := db.GetDb()
if err != nil {
return true
}
// this will return true if there is a user
err = dbase.QueryRow("select count(*) from users where user_name = ?", name).Scan(&check)
if err != nil {
return true
}
return
}