database issues
This commit is contained in:
parent
b8044adf3f
commit
daf1edffb7
@ -17,6 +17,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
@ -48,6 +49,8 @@ func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
|
||||
|
||||
if dbType == "sqlite3" {
|
||||
//_, _ = conn.Exec("PRAGMA foreign_keys = ON")
|
||||
log.Fatalln("no sqlite for now only postgresql")
|
||||
os.Exit(1)
|
||||
conn = sqlite.Open(uri)
|
||||
} else {
|
||||
conn = postgres.Open(uri)
|
||||
|
@ -83,7 +83,7 @@ type Message struct {
|
||||
Timestamp uint64 `gorm:"notNull;default:0"`
|
||||
Content *groupmeExt.Message `gorm:"type:TEXT;notNull"`
|
||||
|
||||
// Portal Portal `gorm:"foreignKey:JID;"` //`gorm:"foreignKey:Chat.Receiver,Chat.JID;references:jid,receiver;constraint:onDelete:CASCADE;"`TODO
|
||||
Portal Portal `gorm:"foreignKey:chat_jid,chat_receiver;references:jid,receiver;constraint:onDelete:CASCADE;"`
|
||||
}
|
||||
|
||||
// func (msg *Message) Scan(row Scannable) *Message {
|
||||
|
@ -17,8 +17,6 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/mautrix/id"
|
||||
@ -27,8 +25,8 @@ import (
|
||||
)
|
||||
|
||||
type PortalKey struct {
|
||||
JID types.GroupMeID
|
||||
Receiver types.GroupMeID
|
||||
JID types.GroupMeID `gorm:"primaryKey"`
|
||||
Receiver types.GroupMeID `gorm:"primaryKey"`
|
||||
}
|
||||
|
||||
func GroupPortalKey(jid types.GroupMeID) PortalKey {
|
||||
@ -39,9 +37,6 @@ func GroupPortalKey(jid types.GroupMeID) PortalKey {
|
||||
}
|
||||
|
||||
func NewPortalKey(jid, receiver types.GroupMeID) PortalKey {
|
||||
if strings.HasSuffix(jid, "@g.us") {
|
||||
receiver = jid
|
||||
}
|
||||
return PortalKey{
|
||||
JID: jid,
|
||||
Receiver: receiver,
|
||||
@ -127,7 +122,7 @@ type Portal struct {
|
||||
Name string
|
||||
Topic string
|
||||
Avatar string
|
||||
AvatarURL id.ContentURI //`gorm:"-"` //TODO:STORE AVATAR
|
||||
AvatarURL id.ContentURI
|
||||
Encrypted bool `gorm:"notNull;default:false"`
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,13 @@ import (
|
||||
type Message struct{ groupme.Message }
|
||||
|
||||
func (m *Message) Scan(value interface{}) error {
|
||||
bytes, ok := value.([]byte)
|
||||
bytes, ok := value.(string)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
|
||||
return errors.New(fmt.Sprint("Failed to unmarshal json value:", value))
|
||||
}
|
||||
|
||||
message := Message{}
|
||||
err := json.Unmarshal(bytes, &message)
|
||||
err := json.Unmarshal([]byte(bytes), &message)
|
||||
|
||||
*m = Message(message)
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user