當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。