orm

package
v0.0.0-...-f093712 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 12 Imported by: 6

Documentation

Overview

Package orm 数据库操作模块,当前只对接了 MongoDB

Index

Constants

This section is empty.

Variables

Adapter ...

View Source
var DefaultColumns = map[string]types.M{
	"_Default": types.M{
		"objectId":  types.M{"type": "String"},
		"createdAt": types.M{"type": "Date"},
		"updatedAt": types.M{"type": "Date"},
		"ACL":       types.M{"type": "ACL"},
	},
	"_User": types.M{
		"username":      types.M{"type": "String"},
		"password":      types.M{"type": "String"},
		"email":         types.M{"type": "String"},
		"emailVerified": types.M{"type": "Boolean"},
		"authData":      types.M{"type": "Object"},
	},
	"_Installation": types.M{
		"installationId":   types.M{"type": "String"},
		"deviceToken":      types.M{"type": "String"},
		"channels":         types.M{"type": "Array"},
		"deviceType":       types.M{"type": "String"},
		"pushType":         types.M{"type": "String"},
		"GCMSenderId":      types.M{"type": "String"},
		"timeZone":         types.M{"type": "String"},
		"localeIdentifier": types.M{"type": "String"},
		"badge":            types.M{"type": "Number"},
		"appVersion":       types.M{"type": "String"},
		"appName":          types.M{"type": "String"},
		"appIdentifier":    types.M{"type": "String"},
		"parseVersion":     types.M{"type": "String"},
	},
	"_Role": types.M{
		"name":  types.M{"type": "String"},
		"users": types.M{"type": "Relation", "targetClass": "_User"},
		"roles": types.M{"type": "Relation", "targetClass": "_Role"},
	},
	"_Session": types.M{
		"restricted":     types.M{"type": "Boolean"},
		"user":           types.M{"type": "Pointer", "targetClass": "_User"},
		"installationId": types.M{"type": "String"},
		"sessionToken":   types.M{"type": "String"},
		"expiresAt":      types.M{"type": "Date"},
		"createdWith":    types.M{"type": "Object"},
	},
	"_Product": types.M{
		"productIdentifier": types.M{"type": "String"},
		"download":          types.M{"type": "File"},
		"downloadName":      types.M{"type": "String"},
		"icon":              types.M{"type": "File"},
		"order":             types.M{"type": "Number"},
		"title":             types.M{"type": "String"},
		"subtitle":          types.M{"type": "String"},
	},
	"_PushStatus": types.M{
		"pushTime":      types.M{"type": "String"},
		"source":        types.M{"type": "String"},
		"query":         types.M{"type": "String"},
		"payload":       types.M{"type": "String"},
		"title":         types.M{"type": "String"},
		"expiry":        types.M{"type": "Number"},
		"status":        types.M{"type": "String"},
		"numSent":       types.M{"type": "Number"},
		"numFailed":     types.M{"type": "Number"},
		"pushHash":      types.M{"type": "String"},
		"errorMessage":  types.M{"type": "Object"},
		"sentPerType":   types.M{"type": "Object"},
		"failedPerType": types.M{"type": "Object"},
		"count":         types.M{"type": "Number"},
	},
	"_JobStatus": types.M{
		"jobName":    types.M{"type": "String"},
		"source":     types.M{"type": "String"},
		"status":     types.M{"type": "String"},
		"message":    types.M{"type": "String"},
		"params":     types.M{"type": "Object"},
		"finishedAt": types.M{"type": "Date"},
	},
	"_Hooks": types.M{
		"functionName": types.M{"type": "String"},
		"className":    types.M{"type": "String"},
		"triggerName":  types.M{"type": "String"},
		"url":          types.M{"type": "String"},
	},
	"_GlobalConfig": types.M{
		"objectId": types.M{"type": "String"},
		"params":   types.M{"type": "Object"},
	},
}

DefaultColumns 所有类的默认字段,以及系统类的默认字段

View Source
var SystemClasses = []string{"_User", "_Installation", "_Role", "_Session", "_Product", "_PushStatus", "_JobStatus"}

SystemClasses 系统表

Functions

func ClassNameIsValid

func ClassNameIsValid(className string) bool

ClassNameIsValid 校验类名,可以是系统内置类、join 类 数字字母组合,以及下划线,但不能以下划线或字母开头

func InitOrm

func InitOrm(a storage.Adapter)

InitOrm 初始化 orm ,仅用于测试

func InvalidClassNameMessage

func InvalidClassNameMessage(className string) string

InvalidClassNameMessage ...

Types

type DBController

type DBController struct {
}

DBController 数据库操作类

var TalismanDBController *DBController

TalismanDBController ...

func (*DBController) CollectionExists

func (d *DBController) CollectionExists(className string) bool

CollectionExists 检测表是否存在

func (*DBController) Create

func (d *DBController) Create(className string, object, options types.M) error

Create 创建对象

func (*DBController) DeleteEverything

func (d *DBController) DeleteEverything()

DeleteEverything 删除所有表数据,仅用于测试

func (*DBController) DeleteSchema

func (d *DBController) DeleteSchema(className string) error

DeleteSchema 删除类

func (*DBController) Destroy

func (d *DBController) Destroy(className string, query types.M, options types.M) error

Destroy 从指定表中删除数据

func (*DBController) Find

func (d *DBController) Find(className string, query, options types.M) (types.S, error)

Find 从指定表中查询数据,查询到的数据放入 list 中 如果查询的是 count ,结果也会放入 list,并且只有这一个元素 options 中的选项包括:skip、limit、sort、keys、count、acl

func (*DBController) LoadSchema

func (d *DBController) LoadSchema(options types.M) *Schema

LoadSchema 加载 Schema,仅加载一次

func (*DBController) PerformInitialization

func (d *DBController) PerformInitialization()

PerformInitialization 初始化数据库索引

func (*DBController) PurgeCollection

func (d *DBController) PurgeCollection(className string) error

PurgeCollection 清除类

func (*DBController) RedirectClassNameForKey

func (d *DBController) RedirectClassNameForKey(className, key string) string

RedirectClassNameForKey 返回指定类的字段所对应的类型 如果 key 字段的属性为 relation<classA> ,则返回 classA

func (*DBController) Update

func (d *DBController) Update(className string, query, update, options types.M, skipSanitization bool) (types.M, error)

Update 更新对象 options 中的参数包括:acl、many、upsert skipSanitization 默认为 false

func (*DBController) ValidateObject

func (d *DBController) ValidateObject(className string, object, query, options types.M) error

ValidateObject 校验对象是否合法

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema schema 操作对象

func Load

func Load(adapter storage.Adapter, schemaCache *cache.SchemaCache, options types.M) *Schema

Load 返回一个新的 Schema 结构体

func (*Schema) AddClassIfNotExists

func (s *Schema) AddClassIfNotExists(className string, fields types.M, classLevelPermissions types.M) (types.M, error)

AddClassIfNotExists 添加类定义,包含默认的字段

func (*Schema) EnforceClassExists

func (s *Schema) EnforceClassExists(className string) error

EnforceClassExists 校验类名

func (*Schema) GetAllClasses

func (s *Schema) GetAllClasses(options types.M) ([]types.M, error)

GetAllClasses ...

func (*Schema) GetOneSchema

func (s *Schema) GetOneSchema(className string, allowVolatileClasses bool, options types.M) (types.M, error)

GetOneSchema allowVolatileClasses 默认为 false

func (*Schema) HasClass

func (s *Schema) HasClass(className string) bool

HasClass Schema 中是否存在类定义

func (*Schema) UpdateClass

func (s *Schema) UpdateClass(className string, submittedFields types.M, classLevelPermissions types.M) (types.M, error)

UpdateClass 更新类

Jump to

Keyboard shortcuts

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