当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript klay-core.ModelContext类代码示例

本文整理汇总了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 = []
  })
开发者ID:patrickhulce,项目名称:klay,代码行数:60,代码来源:executor.test.ts

示例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
    })
开发者ID:patrickhulce,项目名称:klay,代码行数:18,代码来源:helpers.test.ts

示例3: beforeEach

 beforeEach(() => {
   context = new ModelContext()
   model = context.object().children({id: context.integer()})
   next = jest.fn()
 })
开发者ID:patrickhulce,项目名称:klay,代码行数:5,代码来源:validation.test.ts

示例4: beforeEach

 beforeEach(() => {
   const extension = new DatabaseExtension()
   modelContext = ModelContext.create().use(extension)
 })
开发者ID:patrickhulce,项目名称:klay,代码行数:4,代码来源:extension.test.ts


注:本文中的klay-core.ModelContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。