data

package
v0.0.0-...-1d33cbc Latest Latest
Warning

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

Go to latest
Published: May 5, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package data supports interacting with the main database and defines a few important data types.

Index

Constants

View Source
const (
	SitesTable        = "sites"
	ContentTable      = "content"
	UsersTable        = "users"
	UserMetaTable     = "user_meta"
	OptionsTable      = "options"
	MediaTable        = "media"
	SiteMessagesTable = "site_messages"
	UserMessagesTable = "user_messages"
)

Variables

This section is empty.

Functions

func BlobsTable

func BlobsTable(siteID int64) string

BlobsTable gives the name of the blobs table for the site with the given ID. If siteID is zero, then the name of the system's blobs table is returned.

func Init

func Init() error

Init sets up the database connection to be used throughout the rest of the program's lifetime. The function must be called only once.

Types

type Blob

type Blob struct {
	// Row ID in the table.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// General field to specify what kind of blob this is.
	Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"`
	// Key to connect the Blob with content (not an actual foreign key).
	K int64 `protobuf:"varint,3,opt,name=k,proto3" json:"k,omitempty"`
	// The data.
	V []byte `protobuf:"bytes,4,opt,name=v,proto3" json:"v,omitempty"`
	// Time of the last update.
	Updated              *time.Time `protobuf:"bytes,5,opt,name=updated,proto3" json:"updated,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A Blob is a general-use container for binary data.

func (*Blob) Descriptor

func (*Blob) Descriptor() ([]byte, []int)

func (*Blob) GetId

func (m *Blob) GetId() int64

func (*Blob) GetK

func (m *Blob) GetK() int64

func (*Blob) GetRole

func (m *Blob) GetRole() string

func (*Blob) GetUpdated

func (m *Blob) GetUpdated() *time.Time

func (*Blob) GetV

func (m *Blob) GetV() []byte

func (*Blob) ProtoMessage

func (*Blob) ProtoMessage()

func (*Blob) Reset

func (m *Blob) Reset()

func (*Blob) String

func (m *Blob) String() string

func (*Blob) XXX_DiscardUnknown

func (m *Blob) XXX_DiscardUnknown()

func (*Blob) XXX_Marshal

func (m *Blob) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Blob) XXX_Merge

func (m *Blob) XXX_Merge(src proto.Message)

func (*Blob) XXX_Size

func (m *Blob) XXX_Size() int

func (*Blob) XXX_Unmarshal

func (m *Blob) XXX_Unmarshal(b []byte) error

type BlobDeleter

type BlobDeleter interface {
}

type BlobGetter

type BlobGetter interface {
	// BlobsByRoleInK selects blobs where the role matches a role in the given list and the K equals the given k.
	// If not matching Blobs are found, an empty slice is returned but no error.
	BlobsByRoleInK(site int64, roles []string, k int64) ([]Blob, error)

	// BlobByRoleLikeLast returns the last Blob that is matched to the role column using the LIKE feature, ordered
	// by the record ID.
	BlobByRoleLikeLast(site int64, kPattern string) (*Blob, error)
}

type BlobInserter

type BlobInserter interface {
}

type BlobManager

type BlobManager interface {
	BlobGetter
	BlobInserter
	BlobDeleter
}

type Content

type Content struct {
	// Row ID in the table.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// Site ID that the content is part of.
	Site int64 `protobuf:"varint,2,opt,name=site,proto3" json:"site,omitempty"`
	// Valid URL path part with no slashes.
	Slug string `protobuf:"bytes,3,opt,name=slug,proto3" json:"slug,omitempty"`
	// The ID of the author.
	Author int64 `protobuf:"varint,4,opt,name=author,proto3" json:"author,omitempty"`
	// The general type of the content, such as "page" or "post".
	Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"`
	// Either 0 or the ID of the parent in the same table.
	Parent int64 `protobuf:"varint,6,opt,name=parent,proto3" json:"parent,omitempty"`
	// Title for displaying.
	Title string `protobuf:"bytes,7,opt,name=title,proto3" json:"title,omitempty"`
	// Title to give in an HTML meta tag; optional but not null.
	MetaTitle string `protobuf:"bytes,8,opt,name=meta_title,json=metaTitle,proto3" json:"meta_title,omitempty"`
	// Description to give in an HTML meta tag; optional but not null.
	MetaDesc string `protobuf:"bytes,9,opt,name=meta_desc,json=metaDesc,proto3" json:"meta_desc,omitempty"`
	// Either blank or the published (and compiled) body, cached for quick loading.
	Body []byte `protobuf:"bytes,10,opt,name=body,proto3" json:"body,omitempty"`
	// Publication status is one of 'draft', 'published', 'unsaved', or 'trashed';
	// defaults to 'draft' in the database.
	Status string `protobuf:"bytes,11,opt,name=status,proto3" json:"status,omitempty"`
	// Time of the last update.
	Updated              *time.Time `protobuf:"bytes,12,opt,name=updated,proto3" json:"updated,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A Content is piece of the content of an email body. Each email must have at least one Content.

func (*Content) Descriptor

func (*Content) Descriptor() ([]byte, []int)

func (*Content) GetAuthor

func (m *Content) GetAuthor() int64

func (*Content) GetBody

func (m *Content) GetBody() []byte

func (*Content) GetId

func (m *Content) GetId() int64

func (*Content) GetMetaDesc

func (m *Content) GetMetaDesc() string

func (*Content) GetMetaTitle

func (m *Content) GetMetaTitle() string

func (*Content) GetParent

func (m *Content) GetParent() int64

func (*Content) GetSite

func (m *Content) GetSite() int64

func (*Content) GetSlug

func (m *Content) GetSlug() string

func (*Content) GetStatus

func (m *Content) GetStatus() string

func (*Content) GetTitle

func (m *Content) GetTitle() string

func (*Content) GetType

func (m *Content) GetType() string

func (*Content) GetUpdated

func (m *Content) GetUpdated() *time.Time

func (*Content) ProtoMessage

func (*Content) ProtoMessage()

func (*Content) Reset

func (m *Content) Reset()

func (*Content) String

func (m *Content) String() string

func (*Content) XXX_DiscardUnknown

func (m *Content) XXX_DiscardUnknown()

func (*Content) XXX_Marshal

func (m *Content) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Content) XXX_Merge

func (m *Content) XXX_Merge(src proto.Message)

func (*Content) XXX_Size

func (m *Content) XXX_Size() int

func (*Content) XXX_Unmarshal

func (m *Content) XXX_Unmarshal(b []byte) error

type ContentDeleter

type ContentDeleter interface {
	DeleteContent(IDs []int64) (rowsAffected int, err error)
}

type ContentGetter

type ContentGetter interface {
	// ContentByID returns a single Content by its ID.
	ContentByID(id int64) (*Content, error)

	// ContentsByIDs returns the Content rows selected by their ID.
	ContentsByIDs(IDs []int64) ([]Content, error)

	ContentsIDIn(ids []int64) ([]Content, error)

	ContentBySiteSlug(siteID int64, slug string) (*Content, string, error)

	ContentByAuthor(authorID int64) ([]Content, error)

	// ContentsList retrieves the specified Content items. The parent argument should be either nil to indicate that the
	// parent column should not be considered in the query, or a list of the parent IDs to which the returned items should belong.
	// The value of offset may never be negative, which is why its type is uint64.
	ContentsList(siteID int64, cType string, parents []int64, statuses []string, authorID int64, offset uint64) ([]Content, error)

	// CountContent says how many content pages/posts there are with the given parameters and how many such have no parent.
	// Optionally give a non-zero authorID to also filter by author.
	// The given statuses should not have any punctuation at all (should be already sanitized).
	CountContent(siteID int64, pType string, statuses []string, authorID int64) (countTotal uint16, countParentLevel uint32, err error)

	// ContentCountSlug returns the number of rows with the given site ID and slug.
	ContentCountSlug(siteID int64, slug string) (count int64, err error)
}

type ContentInserter

type ContentInserter interface {
	ContentUpdate(contentID int64, vals map[string]interface{}) (int64, error)
}

type ContentManager

type ContentManager interface {
	ContentGetter
	ContentInserter
	ContentDeleter
}

type DB

type DB interface {
	Init(env map[string]string) error
	Ping() error
	BeginTx() (Transaction, error)

	Ops

	// Close closes the underlying representation of the database connection.
	Close() error

	// ErrIsDupKey says if the error reports a database error indicating that an insert would
	// cause a duplicate key error.
	ErrIsDupKey(e error) bool
}

A DB is an abstract handle on a database connection implemented for a particular DBMS.

var Conn DB

Conn represents the connection to the main database.

This variable is initialized when the Init function in this package is called, and its Close method is called before the program exits.

type Media

type Media struct {
	// A UUID encoded in base32 without padding.
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// File extension, starting with a dot if set; optional but not null.
	Ext string `protobuf:"bytes,2,opt,name=ext,proto3" json:"ext,omitempty"`
	// Foreign key to a Site ID.
	Site int64 `protobuf:"varint,3,opt,name=site,proto3" json:"site,omitempty"`
	// A user-given name.
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"`
	// HTML "alt" tag.
	Alt string `protobuf:"bytes,5,opt,name=alt,proto3" json:"alt,omitempty"`
	// A description.
	Desc string `protobuf:"bytes,6,opt,name=desc,proto3" json:"desc,omitempty"`
	// Time when the object was uploaded.
	Uploaded             *time.Time `protobuf:"bytes,7,opt,name=uploaded,proto3" json:"uploaded,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A Media represents a static media item belonging to a website.

The fields Id, Ext, Site, and Name are required; the other strings default to empty strings and must not be null; the Uploaded time defaults to the current time in the database.

func (*Media) Descriptor

func (*Media) Descriptor() ([]byte, []int)

func (*Media) GetAlt

func (m *Media) GetAlt() string

func (*Media) GetDesc

func (m *Media) GetDesc() string

func (*Media) GetExt

func (m *Media) GetExt() string

func (*Media) GetId

func (m *Media) GetId() string

func (*Media) GetName

func (m *Media) GetName() string

func (*Media) GetSite

func (m *Media) GetSite() int64

func (*Media) GetUploaded

func (m *Media) GetUploaded() *time.Time

func (*Media) ProtoMessage

func (*Media) ProtoMessage()

func (*Media) Reset

func (m *Media) Reset()

func (*Media) String

func (m *Media) String() string

func (*Media) XXX_DiscardUnknown

func (m *Media) XXX_DiscardUnknown()

func (*Media) XXX_Marshal

func (m *Media) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Media) XXX_Merge

func (m *Media) XXX_Merge(src proto.Message)

func (*Media) XXX_Size

func (m *Media) XXX_Size() int

func (*Media) XXX_Unmarshal

func (m *Media) XXX_Unmarshal(b []byte) error

type Ops

Ops includes all of the operations that may be performed on a database.

type Option

type Option struct {
	// Site is a foreign key to a Site ID.
	Site                 int64    `protobuf:"varint,1,opt,name=site,proto3" json:"site,omitempty"`
	K                    string   `protobuf:"bytes,2,opt,name=k,proto3" json:"k,omitempty"`
	V                    []byte   `protobuf:"bytes,3,opt,name=v,proto3" json:"v,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

An Option is a key => value pair holding a small amount of data for a site, the primary key being the composite of the site ID and the value of K.

func (*Option) Descriptor

func (*Option) Descriptor() ([]byte, []int)

func (*Option) GetK

func (m *Option) GetK() string

func (*Option) GetSite

func (m *Option) GetSite() int64

func (*Option) GetV

func (m *Option) GetV() []byte

func (*Option) ProtoMessage

func (*Option) ProtoMessage()

func (*Option) Reset

func (m *Option) Reset()

func (*Option) String

func (m *Option) String() string

func (*Option) XXX_DiscardUnknown

func (m *Option) XXX_DiscardUnknown()

func (*Option) XXX_Marshal

func (m *Option) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Option) XXX_Merge

func (m *Option) XXX_Merge(src proto.Message)

func (*Option) XXX_Size

func (m *Option) XXX_Size() int

func (*Option) XXX_Unmarshal

func (m *Option) XXX_Unmarshal(b []byte) error

type OptionDeleter

type OptionDeleter interface {
	// OptionDelete deletes a site option selected by its K.
	OptionDelete(site int64, k string) (rowsAffected int64, err error)
}

type OptionGetter

type OptionGetter interface {
	// OptionByKey returns a site's option selected by its K.
	OptionByKey(site int64, k string) (*Option, error)

	// OptionsLikeKey returns options selected by their K being like k, as matched using the LIKE string
	// pattern matching feature in the database system.
	//
	// The syntax valid for the k string ultimately depends on the database implementation in use, but as
	// a general guideline the core application here should only use pattern strings that are supported in
	// the LIKE feature of all the major DBMSs, such as PostgreSQL (and CockroachDB) and MySQL.
	OptionsLikeKey(site int64, k string) ([]Option, error)

	// OptionsKeyIn returns a site's options selected by the Ks IN list.
	// The strings in the Ks slice must be valid UTF-8 strings.
	OptionsKeyIn(site int64, Ks []string) ([]Option, error)

	// OptionsKeyInMapped returns a map of the K-V pairs of a site's options selected by the Ks IN list.
	// This function always returns a non-nil map, though the map may be empty.
	// An error is not returned if there are no records retrieved.
	OptionsKeyInMapped(site int64, Ks []string) (map[string][]byte, error)

	// OptionsKeyInMappedStr returns a map of the K-V pairs of a site's options selected by the Ks In list,
	// with the V values converted to strings.
	// This function always returns a non-nil map, though the map may be empty.
	// An error is not returned if there are no records retrieved.
	OptionsKeyInMappedStr(site int64, Ks []string) (map[string]string, error)

	// OptionV returns the V of a site's option selected by key.
	OptionV(site int64, k string) ([]byte, error)
}

type OptionInserter

type OptionInserter interface {
	// OptionUpdate updates an Option or creates a new record in the database if necessary.
	//
	// The primary key is set by both the site ID and the value of K.
	OptionUpdate(site int64, k string, v []byte) (rowsAffected int64, err error)

	// OptionUpdateStr updates an Option or creates a new record in the database if necessary.
	OptionUpdateStr(site int64, k string, v string) (rowsAffected int64, err error)

	// OptionsUpdate updates Option records or creates new records in the database if necessary.
	// The strings passed in as keys in the map must be valid UTF-8 strings.
	// Returned is the number of rows affected.
	OptionsUpdate(site int64, opts map[string]string) (int64, error)
}

type OptionManager

type OptionManager interface {
	OptionGetter
	OptionInserter
	OptionDeleter
}

type Site

type Site struct {
	// Row ID in the table.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// The domain (no slashes; possibly includes sub-domain).
	Domain string `protobuf:"bytes,2,opt,name=domain,proto3" json:"domain,omitempty"`
	// The name of the website.
	Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
	Logo string `protobuf:"bytes,4,opt,name=logo,proto3" json:"logo,omitempty"`
	// The URL of the favicon file.
	Favicon string `protobuf:"bytes,5,opt,name=favicon,proto3" json:"favicon,omitempty"`
	// The primary language.
	Language string `protobuf:"bytes,6,opt,name=language,proto3" json:"language,omitempty"`
	// The status of the TLS on the domain: 0 = none, 1 = configuring, 2 = good
	Tls uint32 `protobuf:"varint,7,opt,name=tls,proto3" json:"tls,omitempty"`
	// Time of the last update.
	Updated              *time.Time `protobuf:"bytes,8,opt,name=updated,proto3" json:"updated,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A Site is the basic settings of a site, except for the time when the site was created. Everything else that shapes a site is in either an Option or a Blob.

func (*Site) Descriptor

func (*Site) Descriptor() ([]byte, []int)

func (*Site) GetDomain

func (m *Site) GetDomain() string

func (*Site) GetFavicon

func (m *Site) GetFavicon() string

func (*Site) GetId

func (m *Site) GetId() int64

func (*Site) GetLanguage

func (m *Site) GetLanguage() string
func (m *Site) GetLogo() string

func (*Site) GetName

func (m *Site) GetName() string

func (*Site) GetTls

func (m *Site) GetTls() uint32

func (*Site) GetUpdated

func (m *Site) GetUpdated() *time.Time

func (*Site) ProtoMessage

func (*Site) ProtoMessage()

func (*Site) Reset

func (m *Site) Reset()

func (*Site) String

func (m *Site) String() string

func (*Site) XXX_DiscardUnknown

func (m *Site) XXX_DiscardUnknown()

func (*Site) XXX_Marshal

func (m *Site) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Site) XXX_Merge

func (m *Site) XXX_Merge(src proto.Message)

func (*Site) XXX_Size

func (m *Site) XXX_Size() int

func (*Site) XXX_Unmarshal

func (m *Site) XXX_Unmarshal(b []byte) error

type SiteDeleter

type SiteDeleter interface {
}

type SiteGetter

type SiteGetter interface {
	// SiteByDomain retrieves a site by its domain.
	SiteByDomain(domain string) (*Site, error)

	// SitesByIDs retrieves sites by their ID.
	SitesByIDs(ids []int64) ([]Site, error)
}

type SiteInserter

type SiteInserter interface {
	// InsertSite inserts a Site into the sites table and create all needed tables for the site in a transaction.
	// The int64 returned is the ID of the new site (the inserted row).
	// The domain passed in must have already been validated as a real domain name.
	InsertSite(domain, name string) (int64, error)
}

type SiteManager

type SiteManager interface {
	SiteGetter
	SiteInserter
	SiteDeleter
}

type SiteMessage

type SiteMessage struct {
	// Row ID in the table.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// SiteId is a foreign key to a Site ID.
	SiteId int64 `protobuf:"varint,2,opt,name=site_id,json=siteId,proto3" json:"site_id,omitempty"`
	// Role is the minimum role a user must have to be shown the message.
	Role string `protobuf:"bytes,3,opt,name=role,proto3" json:"role,omitempty"`
	// K is a key to identify the message.
	K       string `protobuf:"bytes,4,opt,name=k,proto3" json:"k,omitempty"`
	Message string `protobuf:"bytes,5,opt,name=message,proto3" json:"message,omitempty"`
	// Time when the message was created.
	Created              *time.Time `protobuf:"bytes,6,opt,name=created,proto3" json:"created,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A SiteMessage is a notification message for a site, to be shown to all users whose role on the site is at least Role.

func (*SiteMessage) Descriptor

func (*SiteMessage) Descriptor() ([]byte, []int)

func (*SiteMessage) GetCreated

func (m *SiteMessage) GetCreated() *time.Time

func (*SiteMessage) GetId

func (m *SiteMessage) GetId() int64

func (*SiteMessage) GetK

func (m *SiteMessage) GetK() string

func (*SiteMessage) GetMessage

func (m *SiteMessage) GetMessage() string

func (*SiteMessage) GetRole

func (m *SiteMessage) GetRole() string

func (*SiteMessage) GetSiteId

func (m *SiteMessage) GetSiteId() int64

func (*SiteMessage) ProtoMessage

func (*SiteMessage) ProtoMessage()

func (*SiteMessage) Reset

func (m *SiteMessage) Reset()

func (*SiteMessage) String

func (m *SiteMessage) String() string

func (*SiteMessage) XXX_DiscardUnknown

func (m *SiteMessage) XXX_DiscardUnknown()

func (*SiteMessage) XXX_Marshal

func (m *SiteMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SiteMessage) XXX_Merge

func (m *SiteMessage) XXX_Merge(src proto.Message)

func (*SiteMessage) XXX_Size

func (m *SiteMessage) XXX_Size() int

func (*SiteMessage) XXX_Unmarshal

func (m *SiteMessage) XXX_Unmarshal(b []byte) error

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
	Ops
}

A Transaction is an initialized database transaction. Each transaction must end with a call to either Commit or Rollback.

A Transaction guarantees a serializable isolation level.

type User

type User struct {
	// Row ID in the table.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// Username.
	Uname string `protobuf:"bytes,2,opt,name=uname,proto3" json:"uname,omitempty"`
	// Email address.
	Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
	// Password, already hashed.
	Pass []byte `protobuf:"bytes,4,opt,name=pass,proto3" json:"pass,omitempty"`
	// First name.
	Fname string `protobuf:"bytes,5,opt,name=fname,proto3" json:"fname,omitempty"`
	// Last name.
	Lname string `protobuf:"bytes,6,opt,name=lname,proto3" json:"lname,omitempty"`
	// The user's role in the site being accessed in the current request.
	Role string `protobuf:"bytes,7,opt,name=role,proto3" json:"role,omitempty"`
	// Time of the last update.
	Updated              *time.Time `protobuf:"bytes,8,opt,name=updated,proto3" json:"updated,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A User contains all the basic info of registered a user.

func (*User) Descriptor

func (*User) Descriptor() ([]byte, []int)

func (*User) GetEmail

func (m *User) GetEmail() string

func (*User) GetFname

func (m *User) GetFname() string

func (*User) GetId

func (m *User) GetId() int64

func (*User) GetLname

func (m *User) GetLname() string

func (*User) GetPass

func (m *User) GetPass() []byte

func (*User) GetRole

func (m *User) GetRole() string

func (*User) GetUname

func (m *User) GetUname() string

func (*User) GetUpdated

func (m *User) GetUpdated() *time.Time

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) Reset

func (m *User) Reset()

func (*User) String

func (m *User) String() string

func (*User) XXX_DiscardUnknown

func (m *User) XXX_DiscardUnknown()

func (*User) XXX_Marshal

func (m *User) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*User) XXX_Merge

func (m *User) XXX_Merge(src proto.Message)

func (*User) XXX_Size

func (m *User) XXX_Size() int

func (*User) XXX_Unmarshal

func (m *User) XXX_Unmarshal(b []byte) error

type UserDeleter

type UserDeleter interface {
	UserDelete(ID int64) error
}

type UserGetter

type UserGetter interface {
	UserById(id int64) (*User, error)
	UserByUsername(username string) (*User, error)
	UserByEmail(email string) (*User, error)
	UsersByIDs(IDs []int64) ([]User, error)
}

type UserInserter

type UserInserter interface {
	// UserInsert inserts a new User.
	// If there are hooks to the user insert operation, the failures in the hook handlers does not cancel the transaction.
	UserInsert(username string, email string, passHash []byte, fname string, lname string) (userID int64, err error)
}

type UserManager

type UserManager interface {
	UserGetter
	UserInserter
	UserDeleter
}

type UserMessage

type UserMessage struct {
	// Row ID in the table.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// UserId is a foreign key to a User ID.
	UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	// K is a key to identify the message.
	K       string `protobuf:"bytes,3,opt,name=k,proto3" json:"k,omitempty"`
	Message string `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"`
	// Time when the message was created.
	Created              *time.Time `protobuf:"bytes,5,opt,name=created,proto3" json:"created,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A UserMessage is a notification message for a user.

func (*UserMessage) Descriptor

func (*UserMessage) Descriptor() ([]byte, []int)

func (*UserMessage) GetCreated

func (m *UserMessage) GetCreated() *time.Time

func (*UserMessage) GetId

func (m *UserMessage) GetId() int64

func (*UserMessage) GetK

func (m *UserMessage) GetK() string

func (*UserMessage) GetMessage

func (m *UserMessage) GetMessage() string

func (*UserMessage) GetUserId

func (m *UserMessage) GetUserId() int64

func (*UserMessage) ProtoMessage

func (*UserMessage) ProtoMessage()

func (*UserMessage) Reset

func (m *UserMessage) Reset()

func (*UserMessage) String

func (m *UserMessage) String() string

func (*UserMessage) XXX_DiscardUnknown

func (m *UserMessage) XXX_DiscardUnknown()

func (*UserMessage) XXX_Marshal

func (m *UserMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UserMessage) XXX_Merge

func (m *UserMessage) XXX_Merge(src proto.Message)

func (*UserMessage) XXX_Size

func (m *UserMessage) XXX_Size() int

func (*UserMessage) XXX_Unmarshal

func (m *UserMessage) XXX_Unmarshal(b []byte) error

type UserMeta

type UserMeta struct {
	// UserId is a foreign key to a User ID.
	UserId int64  `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	K      string `protobuf:"bytes,2,opt,name=k,proto3" json:"k,omitempty"`
	V      []byte `protobuf:"bytes,3,opt,name=v,proto3" json:"v,omitempty"`
	// Time of the last update.
	Updated              *time.Time `protobuf:"bytes,4,opt,name=updated,proto3" json:"updated,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

A UserMeta struct contains the key and value of a meta datum for a user (along with the timestamp of the last update of the row). The rows in the database table are primary-keyed by both the user ID and the K.

func (*UserMeta) Descriptor

func (*UserMeta) Descriptor() ([]byte, []int)

func (*UserMeta) GetK

func (m *UserMeta) GetK() string

func (*UserMeta) GetUpdated

func (m *UserMeta) GetUpdated() *time.Time

func (*UserMeta) GetUserId

func (m *UserMeta) GetUserId() int64

func (*UserMeta) GetV

func (m *UserMeta) GetV() []byte

func (*UserMeta) ProtoMessage

func (*UserMeta) ProtoMessage()

func (*UserMeta) Reset

func (m *UserMeta) Reset()

func (*UserMeta) String

func (m *UserMeta) String() string

func (*UserMeta) XXX_DiscardUnknown

func (m *UserMeta) XXX_DiscardUnknown()

func (*UserMeta) XXX_Marshal

func (m *UserMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UserMeta) XXX_Merge

func (m *UserMeta) XXX_Merge(src proto.Message)

func (*UserMeta) XXX_Size

func (m *UserMeta) XXX_Size() int

func (*UserMeta) XXX_Unmarshal

func (m *UserMeta) XXX_Unmarshal(b []byte) error

type UserMetaDeleter

type UserMetaDeleter interface {
	UserMetaDelete(userID int64, k string) (int64, error)
}

type UserMetaGetter

type UserMetaGetter interface {
	UserMetaById(userID int64) ([]UserMeta, error)
	UserMetaByIdMapped(userID int64) (map[string][]byte, error)
	UserMetaByIdKey(userID int64, k string) (*UserMeta, error)
	UserMetaByIdLikeKey(userID int64, k string) ([]UserMeta, error)
	UserMetaV(userID int64, k string) (v []byte, err error)
}

type UserMetaInserter

type UserMetaInserter interface {
	UserMetaUpdate(userID int64, k string, v []byte) (int64, error)
	UserMetasUpdate(ums []UserMeta) (int64, error)
}

type UserMetaManager

type UserMetaManager interface {
	UserMetaGetter
	UserMetaInserter
	UserMetaDeleter
}

type UserPasswordGetter

type UserPasswordGetter interface {
	// UserPassword returns a user's hashed password from the database.
	UserPassword(userID int64) ([]byte, error)
}

Directories

Path Synopsis
Package cockroach contains the official implementation of the CockroachDB integration.
Package cockroach contains the official implementation of the CockroachDB integration.
Package mysql contains the official implementation of the MySQL integration.
Package mysql contains the official implementation of the MySQL integration.
Package postgres contains the official implementation of the PostgreSQL integration.
Package postgres contains the official implementation of the PostgreSQL integration.

Jump to

Keyboard shortcuts

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