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


TypeScript objection.transaction函数代码示例

本文整理汇总了TypeScript中objection.transaction函数的典型用法代码示例。如果您正苦于以下问题:TypeScript transaction函数的具体用法?TypeScript transaction怎么用?TypeScript transaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了transaction函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

  router.patch('/persons/:id/upsert', async (req, res) => {
    const graph = req.body;

    // Make sure only one person was sent.
    if (Array.isArray(graph)) {
      throw createStatusCodeError(400);
    }

    // Make sure the person has the correct id because `upsertGraph` uses the id fields
    // to determine which models need to be updated and which inserted.
    graph.id = parseInt(req.params.id, 10);

    // It's a good idea to wrap `upsertGraph` call in a transaction since it
    // may create multiple queries.
    const upsertedGraph = await transaction(Person.knex(), trx => {
      return (
        Person.query(trx)
          // For security reasons, limit the relations that can be upserted.
          .allowUpsert('[pets, children.[pets, movies], movies, parent]')
          .upsertGraph(graph)
      );
    });

    res.send(upsertedGraph);
  });
开发者ID:fl0w,项目名称:objection.js,代码行数:25,代码来源:api.ts

示例2: function

const saveDocument = function(document, userId) {
  return transaction(DocumentModel.knex(), function(trx) {
    return DocumentModel.query(trx).upsertGraphAndFetch({
      ...document,
      userId,
    });
  });
};
开发者ID:carlospaelinck,项目名称:publications-js,代码行数:8,代码来源:index.ts

示例3: async

  router.post('/persons/:id/movies', async (req, res) => {
    // Inserting a movie for a person creates two queries: the movie insert query
    // and the join table row insert query. It is wise to use a transaction here.
    const movie = await objection.transaction(Person, async (Person) => {
      const person = await Person
        .query()
        .findById(req.params.id);

      if (!person) {
        return throwNotFound();
      } else {
        return person
          .$relatedQuery('movies')
          .insert(req.body);
      }
    });

    res.send(movie);
  });
开发者ID:johannessjoberg,项目名称:objection.js,代码行数:19,代码来源:api.ts

示例4: createArtist

        startedOn: String
        endedOn: String
        names: [ArtistNameInput!]!
    }

    type Mutation {
        createArtist(input: NewArtistInput!): Artist!
        patchArtist(input: ArtistInput!): Artist!
    }
`;

export const resolvers = {
    Mutation: {
        createArtist(_root: any, { input }: { input: INewArtistInput }): Promise<Artist> {
            return transaction(Artist.knex(), (trx) => (
                createArtistAndArtistNames(input, trx)
            ));
        },

        patchArtist(_root: any, { input }: { input: IArtistInput }): Promise<Artist> {
            return transaction(Artist.knex(), (trx) => (
                patchArtistAndArtistNames(input, trx)
            ));
        },
    },
};

export const createArtistAndArtistNames = async (
    input: INewArtistInput,
    trxOrKnex?: Transaction | knex,
): Promise<Artist> => {
开发者ID:zaeleus,项目名称:lp-api,代码行数:31,代码来源:Mutation.ts


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