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