本文整理汇总了TypeScript中klay-core.ModelContext类的典型用法代码示例。如果您正苦于以下问题:TypeScript ModelContext类的具体用法?TypeScript ModelContext怎么用?TypeScript ModelContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelContext类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
const context = new ModelContext()
context.use(new DatabaseExtension())
model = context
.object()
.children({
id: context.integerId(),
x: context
.integer()
.constrain({type: 'unique'})
.required(),
y: context
.integer()
.constrain({type: 'immutable'})
.automanage({event: 'create', supplyWith: v => v.setValue(1)}),
z: context.integer().automanage({event: '*', supplyWith: v => v.setValue(2)}),
})
.constrain({
type: 'custom',
meta: {
evaluate(data) {
if (data.record.x > 100) {
throw new Error('x is too big')
}
},
},
})
executorMinimal = {
transaction(f) {
transaction = {}
return f(transaction)
},
count(query) {
return executorMinimal.find(query).length
},
find(query) {
return _.filter(executorData, query.where)
},
findById(id) {
return _.filter(executorData, {id})[0]
},
save(object) {
if (!object.id) {
object.id = executorData.length ? _.maxBy(executorData, 'id').id + 1 : 1
}
executorMinimal.destroyById(object.id)
executorData.push(object)
return object
},
destroyById(id) {
executorData = executorData.filter(item => item.id !== id)
},
}
executor = new Executor(model, executorMinimal)
executorData = []
})
示例2: beforeEach
beforeEach(() => {
const extension = new DatabaseExtension()
const context = ModelContext.create().use(extension)
const model = context.object().children({
id: context
.integer()
.constrain({type: 'primary'})
.autoIncrement(),
accountId: context.integer().constrain({type: 'reference'}),
email: context.email().constrain({type: 'unique'}),
updatedAt: context
.dateTime()
.index([{property: [], direction: 'desc'}])
.automanage({...AUTOMANAGE, supplyWith: 'iso-timestamp'}),
})
children = model.spec.children
})
示例3: beforeEach
beforeEach(() => {
context = new ModelContext()
model = context.object().children({id: context.integer()})
next = jest.fn()
})
示例4: beforeEach
beforeEach(() => {
const extension = new DatabaseExtension()
modelContext = ModelContext.create().use(extension)
})