本文整理汇总了TypeScript中slonik.sql.raw方法的典型用法代码示例。如果您正苦于以下问题:TypeScript sql.raw方法的具体用法?TypeScript sql.raw怎么用?TypeScript sql.raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类slonik.sql
的用法示例。
在下文中一共展示了sql.raw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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])}
`;
})();
示例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);
})();