models

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2015 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

The models package defines how the Application server interacts with the local SQLITE database to store information. Currently, the DB will only store

- Identities - Contacts - Messages - Standard Key-Value (string or []byte)

This may change in the future.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTables

func CreateTables(conn gdb.Database) (map[string]gdb.Table, error)

Types

type Address

type Address struct {
	Id            gdb.PrimaryKey `json:"id"`
	Contact       *gdb.HasOne    `table:"contact" json:"-"`
	Alias         string         `json:"alias"`
	Fingerprint   string         `json:"fingerprint"`
	EncryptionKey []byte         `json:"-"`
	Location      string         `json:"location"`
	Subscribed    bool           `json:"subscribed"`
}

type Alias

type Alias struct {
	Id       gdb.PrimaryKey
	Identity *gdb.HasOne `table:"identity"`
	Location string
	Username string
}

Alias represent a registered Identity

func (*Alias) String

func (a *Alias) String() string

type Component

type Component struct {
	Id      gdb.PrimaryKey
	Message *gdb.HasOne `table:"message"`
	Name    string
	Data    []byte
}

An AirDispatch Component

type Contact

type Contact struct {
	Id        gdb.PrimaryKey `json:"id"`
	Name      string         `json:"name"`
	Image     string         `json:"image"`
	Notify    bool           `json:"favorite"`
	Addresses *gdb.HasMany   `table:"address" on:"contact" json:"-"`
	List      *gdb.HasMany   `table:"contact_membership" on:"contact" json:"-"`

	// JSON Specific Transient Fields
	Identities []*Address   `db:"-" json:"addresses"`
	Profile    *JSONProfile `db:"-" json:"profile"`
	Lists      []*List      `db:"-" json:"lists"`
}

func (*Contact) LoadIdentities

func (c *Contact) LoadIdentities(store *Store, tables map[string]gdb.Table) error

type ContactMembership

type ContactMembership struct {
	Id      gdb.PrimaryKey `json:"id"`
	Contact *gdb.HasOne    `table:"contact" json:"-"`
	List    *gdb.HasOne    `table:"contact" json:"-"`
}

type DeveloperPlugin

type DeveloperPlugin struct {
	// Plugin Information
	Id          gdb.PrimaryKey `json:"id"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Image       string         `json:image"`

	// Source Information
	Source string `json:"source"`
}

DeveloperPlugin is analogous to the message that publishes a plugin to the world

`plugins/chat`

type DeveloperPluginPermissions

type DeveloperPluginPermissions struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type DeveloperPluginTile

type DeveloperPluginTile struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Size        string `json:"size"`
	View        string `json:"view"`
}

type DeveloperPluginVersion

type DeveloperPluginVersion struct {
	Version   string `json:"version"`
	Changelog string `json:"changelog"`

	// Permissions Information
	Permissions     []DeveloperPluginPermissions `db:"-" json:"permissions"`
	PermissionsData []byte                       `json:"-"`

	// Extras Information
	Viewers     []DeveloperPluginViewer `db:"-" json:"viewers"`
	Tiles       []DeveloperPluginTile   `db:"-" json:"tiles"`
	ViewersData []byte                  `json:"-"`
	TilesData   []byte                  `json:"-"`

	// Data Information
	Data string `json:"data"`
}

DeveloperPluginVersion has version-specific information.

`plugins/chat/0.0.1`

type DeveloperPluginViewer

type DeveloperPluginViewer struct {
	Id     string   `json:"id"`
	Name   string   `json:"name"`
	Hidden bool     `json:"hidden"`
	Type   []string `json:"type"`
	View   string   `json:"view"`
}

type Identity

type Identity struct {
	Id          gdb.PrimaryKey `json:"-"`
	Nickname    string
	Fingerprint string
	// Server Information and Tacking
	Server            string
	ServerKey         string
	ServerFingerprint string
	ServerAlias       string
	// Actual Data
	Data []byte `json:"-"`
	// Password Protection
	Protected bool
	Aliases   *gdb.HasMany `table:"alias" on:"identity"`
	// Profile
	Profile *gdb.HasOne `table:"profile"`
	// Transcendence
	Current bool `db:"-"`
}

Identity represents a Keypair

func CreateIdentityFromDispatch

func CreateIdentityFromDispatch(id *identity.Identity, key string) (*Identity, error)

CreateIdentityFromDispatch will take an (*identity).Identity from the AirDispatch package and a key (to encrypt the identity with) and return an *Identity suitable for inserting into the database.

func (*Identity) CreateServerFromIdentity

func (id *Identity) CreateServerFromIdentity() (*identity.Address, error)

func (*Identity) ToDispatch

func (i *Identity) ToDispatch(s gdb.Executor, key string) (*identity.Identity, error)

ToDispatch will take a key (to decode the identity) and return an (*identity).Identity suitable for using in AirDispatch-related objects.

type JSONComponent

type JSONComponent struct {
	Binary []byte `json:"binary"`
	String string `json:"string"`
}

type JSONMessage

type JSONMessage struct {
	Name       string                    `json:"name"`
	Date       time.Time                 `json:"date"`
	From       *JSONProfile              `json:"from"`
	To         []*JSONProfile            `json:"to"`
	Public     bool                      `json:"public"`
	Self       bool                      `json:"self"`
	Components map[string]*JSONComponent `json:"components"`
	Context    map[string]string         `json:"context"`
}

func (*JSONMessage) ToDispatch

func (m *JSONMessage) ToDispatch(from *identity.Identity) (*message.Mail, []*identity.Address, error)

func (*JSONMessage) ToModel

func (m *JSONMessage) ToModel(from *identity.Identity) (*Message, []*Component)

type JSONMessageList

type JSONMessageList []*JSONMessage

JSON Encoding

func (JSONMessageList) Len

func (m JSONMessageList) Len() int

func (JSONMessageList) Less

func (m JSONMessageList) Less(i int, j int) bool

func (JSONMessageList) Swap

func (m JSONMessageList) Swap(i int, j int)

type JSONProfile

type JSONProfile struct {
	Name        string `json:"name"`
	Avatar      string `json:"avatar"`
	Alias       string `json:"alias"`
	Fingerprint string `json:"fingerprint"`
}

type List

type List struct {
	Id       gdb.PrimaryKey `json:"id"`
	Name     string         `json:"name"`
	Parent   *gdb.HasOne    `table:"list" json:"-"`
	Children *gdb.HasMany   `table:"list" on:"parent" json:"-"`
	Contacts *gdb.HasMany   `table:"contact_membership" on:"list" json:"-"`
}

type Message

type Message struct {
	Id gdb.PrimaryKey
	// Name registered on Server
	Name string
	// Cleared Addresses
	To string
	// Fingerprint of Sender
	From string
	// Message Metadata
	Alert    bool
	Incoming bool
	Date     int64

	Components *gdb.HasMany `table:"component" on:"message"`
}

A full AirDispatch Message

type Migration

type Migration interface {
	Apply(gdb.Database) error
}

type MigrationFunc

type MigrationFunc func(gdb.Database) error

func (MigrationFunc) Apply

func (m MigrationFunc) Apply(g gdb.Database) error

type MigrationRecord

type MigrationRecord struct {
	Id          gdb.PrimaryKey
	Migration   int
	DateApplied *time.Time
}

type Profile

type Profile struct {
	Id          gdb.PrimaryKey `json:"-"`
	Name        string         `json:"name"`
	Image       string         `json:"image"`
	Description string         `json:"description"`
}

type Record

type Record struct {
	Key   string
	Value []byte
}

type Store

type Store struct {
	*sqlx.DB
	Filename string
	Prefix   string
	// contains filtered or unexported fields
}

func CreateStore

func CreateStore(filename string) (*Store, error)

func (*Store) CreateTables

func (s *Store) CreateTables() error

func (*Store) Get

func (s *Store) Get(key string) (string, error)

func (*Store) GetBytes

func (s *Store) GetBytes(key string) ([]byte, error)

func (*Store) GetConnection

func (s *Store) GetConnection() error

Load the Database Connection

func (*Store) GetDefault

func (s *Store) GetDefault(key string, alt string) (string, error)

func (*Store) Set

func (s *Store) Set(key string, value string) error

func (*Store) SetBytes

func (s *Store) SetBytes(key string, value []byte) error

func (*Store) TableName

func (s *Store) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL