3
0

Extended channel struct to cover all (db) fields

This commit is contained in:
Denis Arh 2018-07-12 19:01:49 +02:00
parent d4c6020174
commit efb42bd036
3 changed files with 32 additions and 13 deletions

View File

@ -16,6 +16,7 @@ package sam
*/
import (
"encoding/json"
"time"
)
@ -25,9 +26,10 @@ type (
ID uint64
Name string
Topic string
LastMessageId uint64 `json:",omitempty"`
ArchivedAt *time.Time `json:",omitempty"`
DeletedAt *time.Time `json:",omitempty"`
Meta json.RawMessage
LastMessageId uint64 `json:",omitempty" db:"rel_last_message"`
ArchivedAt *time.Time `json:",omitempty" db:"archived_at"`
DeletedAt *time.Time `json:",omitempty" db:"deleted_at"`
changed []string
}
@ -72,6 +74,14 @@ func (c *Channel) SetTopic(value string) *Channel {
}
return c
}
func (c *Channel) GetMeta() json.RawMessage {
return c.Meta
}
func (c *Channel) SetMeta(value json.RawMessage) *Channel {
c.Meta = value
return c
}
func (c *Channel) GetLastMessageId() uint64 {
return c.LastMessageId
}

View File

@ -178,15 +178,17 @@
{
"name": "Channel",
"imports": [
"time"
"time",
"encoding/json"
],
"fields": [
{ "type": "uint64", "name": "ID" },
{ "type": "string", "name": "Name" },
{ "type": "string", "name": "Topic" },
{ "type": "uint64", "name": "LastMessageId", "tag": "json:\",omitempty\"" },
{ "type": "*time.Time", "name": "ArchivedAt", "tag": "json:\",omitempty\"", "complex": true },
{ "type": "*time.Time", "name": "DeletedAt", "tag": "json:\",omitempty\"", "complex": true }
{ "type": "uint64", "name": "ID" },
{ "type": "string", "name": "Name" },
{ "type": "string", "name": "Topic" },
{ "type": "json.RawMessage", "name": "Meta", "complex": true},
{ "type": "uint64", "name": "LastMessageId", "tag": "json:\",omitempty\"", "dbname": "rel_last_message" },
{ "type": "*time.Time", "name": "ArchivedAt", "tag": "json:\",omitempty\" db:\"archived_at\"", "complex": true },
{ "type": "*time.Time", "name": "DeletedAt", "tag": "json:\",omitempty\" db:\"deleted_at\"", "complex": true }
]
}
],

View File

@ -19,6 +19,12 @@
"type": "string"
},
{
"complex": true,
"name": "Meta",
"type": "json.RawMessage"
},
{
"dbname": "rel_last_message",
"name": "LastMessageId",
"tag": "json:\",omitempty\"",
"type": "uint64"
@ -26,18 +32,19 @@
{
"complex": true,
"name": "ArchivedAt",
"tag": "json:\",omitempty\"",
"tag": "json:\",omitempty\" db:\"archived_at\"",
"type": "*time.Time"
},
{
"complex": true,
"name": "DeletedAt",
"tag": "json:\",omitempty\"",
"tag": "json:\",omitempty\" db:\"deleted_at\"",
"type": "*time.Time"
}
],
"imports": [
"time"
"time",
"encoding/json"
],
"name": "Channel"
}