models

package
v0.0.0-...-b770fee Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const AUTH_TOKEN_TABLE = "auth_token"
View Source
const BCRYPT_COST = 10
View Source
const DOWNLOAD_HOUR_TABLE = "download_hour"
View Source
const FILE_TABLE = "file"
View Source
const MODEL_TABLE = "model"
View Source
const USER_TABLE = "auth_user"

Variables

This section is empty.

Functions

func IdStrings

func IdStrings(ids []interface{}) []string

func NewDB

func NewDB() (*runner.DB, error)

Types

type ApiCollection

type ApiCollection struct {
	User         UserApi
	AuthToken    AuthTokenApi
	Model        ModelApi
	File         FileApi
	DownloadHour DownloadHourApi
}

func NewApiCollection

func NewApiCollection(db *runner.DB) *ApiCollection

func (*ApiCollection) BackendModels

func (api *ApiCollection) BackendModels() []BackendModel

func (*ApiCollection) Truncate

func (api *ApiCollection) Truncate() error

type AuthToken

type AuthToken struct {
	Id          string    `db:"id" json:"id"`
	UserId      string    `db:"user_id" json:"user_id"`
	CreatedTime time.Time `db:"created_time" json:"created_time"`
}

func NewAuthToken

func NewAuthToken(userId string) *AuthToken

type AuthTokenApi

type AuthTokenApi interface {
	ById(id interface{}) (*AuthToken, error)
	ByIds(ids []interface{}) ([]*AuthToken, error)
	Delete(id interface{}) error
	Save(*AuthToken) error
	Hydrate([]*AuthToken) error
	Truncate() error
}

type AuthTokenDb

type AuthTokenDb struct {
	DB  *runner.DB
	Api *ApiCollection
}

func NewAuthTokenDb

func NewAuthTokenDb(db *runner.DB, api *ApiCollection) *AuthTokenDb

func (*AuthTokenDb) ById

func (db *AuthTokenDb) ById(id interface{}) (*AuthToken, error)

func (*AuthTokenDb) ByIds

func (db *AuthTokenDb) ByIds(ids []interface{}) ([]*AuthToken, error)

func (*AuthTokenDb) Delete

func (db *AuthTokenDb) Delete(id interface{}) error

func (*AuthTokenDb) Hydrate

func (db *AuthTokenDb) Hydrate(authTokens []*AuthToken) error

func (*AuthTokenDb) Save

func (db *AuthTokenDb) Save(authToken *AuthToken) error

func (*AuthTokenDb) Truncate

func (db *AuthTokenDb) Truncate() error

type BackendModel

type BackendModel interface {
	Truncate() error
}

type DownloadCounts

type DownloadCounts struct {
	Day   int `json:"day"`
	Week  int `json:"week"`
	Month int `json:"month"`
	All   int `json:"all"`
}

type DownloadHourApi

type DownloadHourApi interface {
	MarkDownload(fileId, userId, ip string, t time.Time) error
	CountByFile(fileId string) (DownloadCounts, error)
	CountsByFiles(fileIds []string) (map[string]DownloadCounts, error)
	CountByModel(modelId string) (DownloadCounts, error)
	CountsByModels(modelIds []string) (map[string]DownloadCounts, error)
	Truncate() error
}

type DownloadHourDb

type DownloadHourDb struct {
	DB  *runner.DB
	Api *ApiCollection
}

func NewDownloadHourDb

func NewDownloadHourDb(db *runner.DB, api *ApiCollection) *DownloadHourDb

func (*DownloadHourDb) CountByFile

func (db *DownloadHourDb) CountByFile(fileId string) (DownloadCounts, error)

func (*DownloadHourDb) CountByModel

func (db *DownloadHourDb) CountByModel(modelId string) (DownloadCounts, error)

func (*DownloadHourDb) CountsByFiles

func (db *DownloadHourDb) CountsByFiles(fileIds []string) (map[string]DownloadCounts, error)

func (*DownloadHourDb) CountsByModels

func (db *DownloadHourDb) CountsByModels(modelIds []string) (map[string]DownloadCounts, error)

func (*DownloadHourDb) MarkDownload

func (db *DownloadHourDb) MarkDownload(fileId, userId, ip string, t time.Time) error

func (*DownloadHourDb) Truncate

func (db *DownloadHourDb) Truncate() error

type File

type File struct {
	Id               string                 `db:"id" json:"id"`
	UserId           string                 `db:"user_id" json:"user_id"`
	ModelId          string                 `db:"model_id" json:"model_id"`
	Filename         string                 `db:"filename" json:"filename"`
	Status           string                 `db:"status" json:"status"`
	Framework        string                 `db:"framework" json:"framework"`
	FrameworkVersion string                 `db:"framework_version" json:"framework_version"`
	ClientName       string                 `db:"client_name" json:"client_name"`
	SizeBytes        int                    `db:"size_bytes" json:"size_bytes"`
	MetadataString   string                 `db:"metadata" json:"-"`
	Metadata         map[string]interface{} `db:"-" json:"metadata"`
	CreatedTime      time.Time              `db:"created_time" json:"created_time"`

	// Hydrated fields
	Downloads *DownloadCounts `db:"-" json:"downloads,omitempty"`
}

func NewFile

func NewFile(userId, modelId, filename, framework, frameworkVersion,
	clientName string, sizeBytes int, metadata map[string]interface{}) (*File, error)

func (*File) BlobFilename

func (f *File) BlobFilename() string

func (*File) FillMetadata

func (f *File) FillMetadata() error

type FileApi

type FileApi interface {
	ById(id interface{}) (*File, error)
	ByIds(ids []interface{}) ([]*File, error)
	Delete(id interface{}) error
	Save(*File) error
	Hydrate([]*File) error
	Truncate() error

	// TODO: Potentially this should be a separate interface
	ByModelIdFilenameLatest(modelId, filename string) (*File, error)
	ByModelIdFrameworkFilename(modelId, framework, filename string) ([]*File, error)
	ByModelIdLatest(modelId string) ([]*File, error)
	ByModelId(modelId string) ([]*File, error)
	DeletePending(modelId, filename string) error
	CommitPending(modelId, filename, fileId string) error
	ToDelete(modelId, filename string, n int) ([]*File, error)
}

type FileDb

type FileDb struct {
	DB  *runner.DB
	Api *ApiCollection
}

func NewFileDb

func NewFileDb(db *runner.DB, api *ApiCollection) *FileDb

func (*FileDb) ById

func (db *FileDb) ById(id interface{}) (*File, error)

func (*FileDb) ByIds

func (db *FileDb) ByIds(ids []interface{}) ([]*File, error)

func (*FileDb) ByModelId

func (db *FileDb) ByModelId(modelId string) ([]*File, error)

func (*FileDb) ByModelIdFilenameLatest

func (db *FileDb) ByModelIdFilenameLatest(modelId, filename string) (*File, error)

func (*FileDb) ByModelIdFrameworkFilename

func (db *FileDb) ByModelIdFrameworkFilename(modelId, framework, filename string) ([]*File, error)

func (*FileDb) ByModelIdLatest

func (db *FileDb) ByModelIdLatest(modelId string) ([]*File, error)

func (*FileDb) CommitPending

func (db *FileDb) CommitPending(modelId, filename, fileId string) error

func (*FileDb) Delete

func (db *FileDb) Delete(id interface{}) error

func (*FileDb) DeletePending

func (db *FileDb) DeletePending(modelId, filename string) error

func (*FileDb) Hydrate

func (db *FileDb) Hydrate(files []*File) error

func (*FileDb) Save

func (db *FileDb) Save(f *File) error

func (*FileDb) ToDelete

func (db *FileDb) ToDelete(modelId, filename string, n int) ([]*File, error)

func (*FileDb) Truncate

func (db *FileDb) Truncate() error

type FileDownloads

type FileDownloads struct {
	FileId string `db:"file_id"`
	DownloadCounts
}

type Model

type Model struct {
	Id          string    `db:"id" json:"id"`
	UserId      string    `db:"user_id" json:"user_id"`
	Slug        string    `db:"slug" json:"slug"`
	Name        string    `db:"name" json:"name"`
	Description string    `db:"description" json:"description"`
	Visibility  string    `db:"visibility" json:"visibility"`
	Keep        int       `db:"keep" json:"keep"`
	Readme      string    `db:"readme" json:"-"`
	CreatedTime time.Time `db:"created_time" json:"created_time"`

	// Hydrated fields
	Downloads      *DownloadCounts `db:"-" json:"downloads,omitempty"`
	HydratedReadme zero.String     `db:"-" json:"readme,omitempty"`
}

func NewModel

func NewModel(userId, slug, name, description, visibility string, keep int) *Model

type ModelApi

type ModelApi interface {
	ById(id interface{}) (*Model, error)
	ByIds(ids []interface{}) ([]*Model, error)
	Delete(id interface{}) error
	Save(*Model) error
	Hydrate([]*Model) error
	Truncate() error

	// TODO: Potentially this should be a separate interface
	ByUserId(userId string) ([]*Model, error)
	ByUserIdSlug(userId, slug string) (*Model, error)
	ByVisibility(visibility string, limit int, last string) ([]*Model, error)
	ByDownloads(visibility string, start, end time.Time, limit int, last string) ([]*Model, error)
}

type ModelDb

type ModelDb struct {
	DB  *runner.DB
	Api *ApiCollection
}

func NewModelDb

func NewModelDb(db *runner.DB, api *ApiCollection) *ModelDb

func (*ModelDb) ByDownloads

func (db *ModelDb) ByDownloads(visibility string, start, end time.Time, limit int, last string) ([]*Model, error)

func (*ModelDb) ById

func (db *ModelDb) ById(id interface{}) (*Model, error)

func (*ModelDb) ByIds

func (db *ModelDb) ByIds(ids []interface{}) ([]*Model, error)

func (*ModelDb) ByUserId

func (db *ModelDb) ByUserId(userId string) ([]*Model, error)

func (*ModelDb) ByUserIdSlug

func (db *ModelDb) ByUserIdSlug(userId, slug string) (*Model, error)

func (*ModelDb) ByVisibility

func (db *ModelDb) ByVisibility(visibility string, limit int, last string) ([]*Model, error)

func (*ModelDb) Delete

func (db *ModelDb) Delete(id interface{}) error

func (*ModelDb) Hydrate

func (db *ModelDb) Hydrate(models []*Model) error

func (*ModelDb) Save

func (db *ModelDb) Save(model *Model) error

func (*ModelDb) Truncate

func (db *ModelDb) Truncate() error

type ModelDownloads

type ModelDownloads struct {
	ModelId string `db:"model_id"`
	DownloadCounts
}

type Scannable

type Scannable interface {
	Scan(dest ...interface{}) error
}

type User

type User struct {
	Id               string    `db:"id" json:"id"`
	Email            string    `db:"email" json:"-"`
	Username         string    `db:"username" json:"username"`
	PasswordHash     string    `db:"password_hash" json:"-"`
	StripeCustomerId string    `db:"stripe_customer_id" json:"-"`
	CreatedTime      time.Time `db:"created_time" json:"created_time"`

	// Hydrated fields
	HasStripeCustomerId zero.Bool `json:"has_stripe_customer_id,omitempty"`
}

func NewUser

func NewUser(email, username, password string) *User

func (*User) CheckPassword

func (user *User) CheckPassword(password string) error

func (*User) SetPassword

func (user *User) SetPassword(password string) error

type UserApi

type UserApi interface {
	ById(id interface{}) (*User, error)
	ByIds(ids []interface{}) ([]*User, error)
	Delete(id interface{}) error
	Save(*User) error
	Hydrate([]*User) error
	Truncate() error

	// TODO: Potentially this should be a separate interface
	ByEmail(email string) (*User, error)
	ByUsername(username string) (*User, error)
}

type UserDb

type UserDb struct {
	DB  *runner.DB
	Api *ApiCollection
}

func NewUserDb

func NewUserDb(db *runner.DB, api *ApiCollection) *UserDb

func (*UserDb) ByEmail

func (db *UserDb) ByEmail(email string) (*User, error)

func (*UserDb) ById

func (db *UserDb) ById(id interface{}) (*User, error)

func (*UserDb) ByIds

func (db *UserDb) ByIds(ids []interface{}) ([]*User, error)

func (*UserDb) ByUsername

func (db *UserDb) ByUsername(username string) (*User, error)

func (*UserDb) Delete

func (db *UserDb) Delete(id interface{}) error

func (*UserDb) Hydrate

func (db *UserDb) Hydrate(users []*User) error

func (*UserDb) Save

func (db *UserDb) Save(user *User) error

func (*UserDb) Truncate

func (db *UserDb) Truncate() error

Jump to

Keyboard shortcuts

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