mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
StorDB fixes and additions
This commit is contained in:
@@ -20,14 +20,12 @@ package engine
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type PostgresStorage struct {
|
||||
*SQLStorage
|
||||
}
|
||||
|
||||
func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdleConn int) (*PostgresStorage, error) {
|
||||
connectString := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s sslmode=disable", host, port, name, user, password)
|
||||
db, err := gorm.Open("postgres", connectString)
|
||||
@@ -44,3 +42,30 @@ func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdl
|
||||
|
||||
return &PostgresStorage{&SQLStorage{Db: db.DB(), db: db}}, nil
|
||||
}
|
||||
|
||||
type PostgresStorage struct {
|
||||
*SQLStorage
|
||||
}
|
||||
|
||||
func (self *PostgresStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
|
||||
tx := self.db.Begin()
|
||||
if overwrite {
|
||||
tx.Table(utils.TBLVersions).Delete(nil)
|
||||
}
|
||||
for key, val := range vrs {
|
||||
vrModel := &TBLVersion{Item: key, Version: val}
|
||||
if !overwrite {
|
||||
if err = tx.Model(&TBLVersion{}).Where(
|
||||
TBLVersion{Item: vrModel.Item}).Delete(TBLVersion{Version: val}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = tx.Save(vrModel).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
}
|
||||
tx.Commit()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user