Add Models, Add Database

This commit is contained in:
hoernschen 2020-09-28 22:37:02 +02:00
parent 8f90344870
commit faee833481
21 changed files with 407 additions and 1 deletions

View file

@ -0,0 +1,7 @@
package device
type Device struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Keys map[string]string `json:"keys,omitempty"`
}

View file

6
entities/event/edu.go Normal file
View file

@ -0,0 +1,6 @@
package event
type EDU struct {
Type string `json:"type,omitempty"`
Content string `json:"content,omitempty"`
}

10
entities/event/event.go Normal file
View file

@ -0,0 +1,10 @@
package event
type Event struct {
Id string `json:"id,omitempty"`
RoomId string `json:"roomId,omitempty"`
EventType string `json:"eventType,omitempty"`
Content string `json:"content,omitempty"`
Parent string `json:"parent,omitempty"`
Depth int `json:"depth,omitempty"`
}

View file

@ -0,0 +1,18 @@
package event
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
func InitDB(filepath string) *sql.DB {
db, err := sql.Open("sqlite3", filepath)
if err != nil {
panic(err)
}
if db == nil {
panic("db nil")
}
return db
}

13
entities/room/room.go Normal file
View file

@ -0,0 +1,13 @@
package room
import (
"nutfactory.org/Matrix/entities/event"
)
type Room struct {
Id string `json:"id,omitempty"`
Messages map[string]event.Event `json:"messages,omitempty"`
State map[string]event.Event `json:"state,omitempty"`
Members []string `json:"members,omitempty"`
Version string `json:"version,omitempty"`
}

View file

View file

@ -0,0 +1,11 @@
package transaction
import (
"nutfactory.org/Matrix/entities/event"
)
type Transaction struct {
Id string `json:"id,omitempty"`
PDUS map[string]event.Event `json:"pdus,omitempty"`
EDUS []event.EDU `json:"edus,omitempty"`
}

12
entities/user/user.go Normal file
View file

@ -0,0 +1,12 @@
package user
import (
"nutfactory.org/Matrix/entities/device"
)
type User struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Password string `json:"password,omitempty"`
Devices map[string]device.Device `json:"devices,omitempty"`
}

View file