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


TypeScript slonik.sql类代码示例

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


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

示例1: async

 const sample1 = async () => {
   connection.query(sql`
     SELECT ${sql.identifier(['foo', 'a'])}
     FROM (
       VALUES ${sql.tupleList([['a1', 'b1', 'c1'], ['a2', 'b2', 'c2']])}
     ) foo(a, b, c)
     WHERE foo.b IN (${sql.valueList(['c1', 'a2'])})
   `);
 };
开发者ID:TeamworkGuy2,项目名称:DefinitelyTyped,代码行数:9,代码来源:slonik-tests.ts

示例2:

(async () => {
    const uniquePairs = [
        ['a', 1],
        ['b', 2]
      ];

      let placeholderIndex = 1;

      const whereConditionSql = uniquePairs
        .map(needleColumns => {
          return needleColumns
            .map((column) => {
              return `${column} = $${placeholderIndex++}`;
            })
            .join(' AND ');
        })
        .join(' OR ');

      const values = [];

      for (const pairValues of uniquePairs) {
        values.push(...pairValues);
      }

      const query = sql`
        SELECT
          id
        FROM foo
        WHERE
          ${sql.raw(whereConditionSql, values)}
      `;

      await connection.any(query);
})();
开发者ID:benleilei,项目名称:DefinitelyTyped,代码行数:34,代码来源:slonik-tests.ts

示例3: INTO

(async () => {
    await connection.query(sql`
        INSERT INTO (foo, bar, baz)
        VALUES ${sql.tupleList([
            [1, 2, 3],
            [4, 5, 6]
            ])}
    `);
})();
开发者ID:benleilei,项目名称:DefinitelyTyped,代码行数:9,代码来源:slonik-tests.ts

示例4: FROM

(async () => {
  // ExpectType SqlSqlTokenType
  const query0 = sql`SELECT ${'foo'} FROM bar`;
  // ExpectType SqlSqlTokenType
  const query1 = sql`SELECT ${'baz'} FROM (${query0})`;

  await connection.query(sql`
      SELECT (${sql.valueList([1, 2, 3])})
  `);

  await connection.query(sql`
      INSERT INTO (foo, bar, baz)
      VALUES ${sql.tuple([1, 2, 3])}
  `);

  await connection.query(sql`
      INSERT INTO (foo, bar, baz)
      VALUES ${sql.tupleList([
          [1, 2, 3],
          [4, 5, 6]
      ])}
  `);

  await connection.query(sql`
      SELECT bar, baz
      FROM ${sql.unnest(
          [
              [1, 'foo'],
              [2, 'bar']
          ],
          [
              'int4',
              'text'
          ]
      )} AS foo(bar, baz)
  `);

  sql`
      SELECT 1
      FROM ${sql.identifier(['bar', 'baz'])}
  `;

  sql`
      SELECT 1
      FROM ${sql.raw('"bar"')}
  `;

  sql`
      SELECT ${sql.raw('$1', [1])}
  `;
})();
开发者ID:benleilei,项目名称:DefinitelyTyped,代码行数:51,代码来源:slonik-tests.ts


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