本文整理匯總了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)
})