models

package
v0.0.0-...-86fb063 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaUploadEnabled  = 1 // enabled
	MediaUploadDisabled = 2 // deleted
)
View Source
const (
	TRANSACTION_STATUS_PENDING    = 1
	TRANSACTION_STATUS_DONE       = 2
	TRANSACTION_STATUS_ERROR      = 3
	TRANSACTION_STATUS_PENDING_CB = 4
)
View Source
const (
	TRANSACTION_KIND_NFT   = 1
	TRANSACTION_KIND_TOKEN = 2
)

Variables

View Source
var (

	// Db is the global database reference
	Db *gorm.DB
)

Functions

func CloseDatabase

func CloseDatabase()

CloseDatabase closes the database

func DropAllTables

func DropAllTables()

DropAllTables drops all tables and relations, only works with local database in debug mode

func InitializeDatabase

func InitializeDatabase()

InitializeDatabase opens and migrates the database if necessary

func OpenDatabase

func OpenDatabase()

OpenDatabase opens the database and returns a handle

Types

type Arc

type Arc struct {
	gorm.Model
	Object
}

type JSONMap

type JSONMap map[string]interface{}

JSONMap defiend JSON data type, need to implements driver.Valuer, sql.Scanner interface

func (JSONMap) GormDBDataType

func (JSONMap) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (JSONMap) GormDataType

func (m JSONMap) GormDataType() string

GormDataType gorm common data type

func (JSONMap) MarshalJSON

func (m JSONMap) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte

func (*JSONMap) Scan

func (m *JSONMap) Scan(val interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (*JSONMap) UnmarshalJSON

func (m *JSONMap) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte

func (JSONMap) Value

func (m JSONMap) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Layer

type Layer struct {
	gorm.Model
	Uid  string `gorm:"column:uid; index"`
	Name string `gorm:"column:name"`
}

type MediaUpload

type MediaUpload struct {
	gorm.Model
	SessionID string  `gorm:"column:session_id; index"`
	Path      string  `gorm:"column:path; index"`
	Status    byte    `gorm:"column:status`
	Metadata  JSONMap `gorm:"column:metadata"`
}

type Object

type Object struct {
	gorm.Model
	Cid            string    `gorm:"column:cid; index" binding:"required"`
	OwnerUid       string    `gorm:"column:owner_uid; index" binding:"required"`
	OwnerProvider  string    `gorm:"column:owner_provider; index" binding:"required"`
	Name           string    `gorm:"column:name; index" binding:"required"`
	Description    string    `gorm:"description; index"`
	CoverImageUri  string    `gorm:"coverImageUri"`
	CreatedAtInner time.Time `gorm:"column:created_at_inner"`
	Body           JSONMap   `gorm:"column:body"`
	Files          JSONMap   `gorm:"column:files"`
}

type Pin

type Pin struct {
	gorm.Model
	Object
	Location PointGeo `gorm:"column:location; index"`
}

type PinnedArc

type PinnedArc struct {
	gorm.Model
	Object
	Arc   Arc  `gorm:"foreignkey:ArcId; references: id; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	ArcId uint `gorm:"column:arc_id; index"`
	Pin   Pin  `gorm:"foreignkey:PinId; references: id; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	PinId uint `gorm:"column:pin_id; index"`
}

type Place

type Place struct {
	gorm.Model

	Name       string   `gorm:"column:name; binding:"required"`
	Location   PointGeo `gorm:"column:location"`
	ViewportNE PointGeo `gorm:"column:viewport_ne"`
	ViewportSW PointGeo `gorm:"column:viewport_sw"`
	Uid        string   `gorm:"column:uid; binding:"required"`
	Status     byte     `gorm:"column:status; index"`
	Metadata   string   `gorm:"column:metadata; binding:"required"`
}

func (*Place) MarshallFromJson

func (p *Place) MarshallFromJson(j PlaceJson)

MarshallFromJson marshalls Place to PlaceJson

func (*Place) MarshallToJson

func (p *Place) MarshallToJson(includeMetadata bool) PlaceJson

MarshallToJson marshalls Place to PlaceJson

type PlaceJson

type PlaceJson struct {
	Name     string `json:"name"`
	Geometry struct {
		Location struct {
			Lat float64 `json:"lat"`
			Lon float64 `json:"lon"`
		} `json:"location"`
		Viewport struct {
			Northeast struct {
				Lat float64 `json:"lat"`
				Lon float64 `json:"lon"`
			} `json:"northeast,omitempty"`
			Southwest struct {
				Lat float64 `json:"lat"`
				Lon float64 `json:"lon"`
			} `json:"southwest,omitempty"`
		} `json:"viewport,omitempty"`
	} `json:"geometry,omitempty"`

	Metadata  string `json:"metadata,omitempty"`
	Uid       string `json:"uid,omitempty"`
	CreatedAt string `json:"createdAt,omitempty"`
}

type PointGeo

type PointGeo struct {
	Lon float64 `json:"lon"`
	Lat float64 `json:"lat"`
}

PointGeo is a manually serialized postgis point

func (*PointGeo) GormDataType

func (p *PointGeo) GormDataType() string

GormDataType sets the Gorm type to geometry

func (PointGeo) GormValue

func (p PointGeo) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue sets geom point

func (*PointGeo) Scan

func (p *PointGeo) Scan(val interface{}) error

Scan reads a point from database and converts to simple point

func (*PointGeo) String

func (p *PointGeo) String() string

String converts simple point to postgis string

func (PointGeo) Value

func (p PointGeo) Value() (driver.Value, error)

Value converts simple point to SQL driver value, which is a string

type Transaction

type Transaction struct {
	gorm.Model
	Uid           string    `gorm:"column:uid; index" binding:"required"`
	Kind          string    `gorm:"column:kind" binding:"required"`
	Status        byte      `gorm:"column:status" binding:"required"`
	WalletAddr    string    `json:"column:wallet_addr" binding:"required"`
	WalletKind    string    `json:"column:wallet_kind" binding:"required"`
	CallbackUri   string    `json:"column:callback_uri" binding:"required"`
	IpfsCid       string    `json:"column:ipfs_cid"`
	TokenQuantity int       `json:"column:token_quantity"`
	Metadata      JSONMap   `gorm:"column:metadata"`
	Cost          string    `json:"column:cost"`
	ContractAddr  string    `json:"column:contract_addr"`
	ErrorCount    int       `json:"column:error_count"`
	LastErrorAt   time.Time `json:"column:last_error_at"`
	LastError     string    `json:"column:last_error"`
}

Jump to

Keyboard shortcuts

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