model

package
v0.0.0-...-598a1f7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: AGPL-3.0, MIT Imports: 4 Imported by: 0

README

Package model

This was an early sketch of helper utilities for resources. I've since decided that this code is best included within the apps, as a shared resources package, so you should consider this package and those under it deprecated. It will be removed in version 2.0.

Documentation

Overview

Package model provides a class including Id, CreatedAt and UpdatedAt, and some utility functions, optionally include in your models

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanParams

func CleanParams(params map[string]string, allowed []string) map[string]string

CleanParams returns a params list cleaned of keys not in allowed list DEPRECATED - REMOVE AND REPLACE WITH params.Clean()

Types

type Model

type Model struct {
	// Id is the default primary key of the model
	Id int64

	// CreatedAt stores the creation time of the model and should not be changed after cretion
	CreatedAt time.Time

	// UpdatedAt stores the last update time of the model
	UpdatedAt time.Time

	// TableName is used for database queries and urls
	TableName string

	// KeyName is used for database queries as the primary key
	KeyName string
}

Model base class

func (*Model) CacheKey

func (m *Model) CacheKey() string

CacheKey generates a cache key for this model object, dependent on id and UpdatedAt should we generate a hash of this to ensure we fit in small key size?

func (*Model) Init

func (m *Model) Init()

Init sets up the model fields

func (*Model) OwnedBy

func (m *Model) OwnedBy(uid int64) bool

OwnedBy returns true if the user id passed in owns this model

func (*Model) PrimaryKey

func (m *Model) PrimaryKey() string

PrimaryKey returns the id for primary key by default - used by query

func (*Model) PrimaryKeyValue

func (m *Model) PrimaryKeyValue() int64

PrimaryKeyValue returns the unique id

func (*Model) ResourceID

func (m *Model) ResourceID() string

ResourceID returns a key unique to this resource (we use table).

func (*Model) SelectName

func (m *Model) SelectName() string

SelectName returns our name for select menus

func (*Model) SelectValue

func (m *Model) SelectValue() string

SelectValue returns our value for select options

func (*Model) String

func (m *Model) String() string

String returns a string representation of the model

func (*Model) Table

func (m *Model) Table() string

Table returns the table name for this object

func (*Model) ToSlug

func (m *Model) ToSlug(name string) string

ToSlug converts our name to something suitable for use on the web as part of a url

func (*Model) URLCreate

func (m *Model) URLCreate() string

URLCreate returns the create url for this model /table/create

func (*Model) URLDestroy

func (m *Model) URLDestroy() string

URLDestroy returns the destroy url for this model /table/id/destroy

func (*Model) URLIndex

func (m *Model) URLIndex() string

URLIndex returns the index url for this model - /table

func (*Model) URLShow

func (m *Model) URLShow() string

URLShow returns the show url for this model /table/id

func (*Model) URLUpdate

func (m *Model) URLUpdate() string

URLUpdate returns the update url for this model /table/id/update

Directories

Path Synopsis
Package validate provides methods for validating params passed from the database row as interface{} types
Package validate provides methods for validating params passed from the database row as interface{} types

Jump to

Keyboard shortcuts

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