@@ -8,7 +8,7 @@ import { defaultRetryConfig, isRetryableError, retry } from '@ydbjs/retry'
8
8
9
9
import { Query } from './query.js'
10
10
import { ctx } from './ctx.js'
11
- import { yql } from './yql.js'
11
+ import { UnsafeString , identifier , yql } from './yql.js'
12
12
13
13
export type SQL = < T extends any [ ] = unknown [ ] , P extends any [ ] = unknown [ ] > (
14
14
strings : string | TemplateStringsArray ,
@@ -48,6 +48,20 @@ export interface QueryClient extends SQL, AsyncDisposable {
48
48
49
49
transaction < T = unknown > ( fn : TransactionContextCallback < T > ) : Promise < T >
50
50
transaction < T = unknown > ( options : TransactionExecuteOptions , fn : TransactionContextCallback < T > ) : Promise < T >
51
+
52
+ /**
53
+ * Create an UnsafeString that represents a DB identifier (table, column).
54
+ * When used in a query, the identifier will be escaped.
55
+ *
56
+ * **WARNING: This function does not offer any protection against SQL injections,
57
+ * so you must validate any user input beforehand.**
58
+ *
59
+ * @example ```ts
60
+ * const query = sql`SELECT * FROM ${sql.identifier('my-table')}`;
61
+ * // 'SELECT * FROM `my-table`'
62
+ * ```
63
+ */
64
+ identifier ( value : string | { toString ( ) : string } ) : UnsafeString
51
65
}
52
66
53
67
const doImpl = function < T = unknown > ( ) : Promise < T > {
@@ -191,6 +205,7 @@ export function query(driver: Driver): QueryClient {
191
205
do : doImpl ,
192
206
begin : txIml ,
193
207
transaction : txIml ,
208
+ identifier : identifier ,
194
209
async [ Symbol . asyncDispose ] ( ) { } ,
195
210
}
196
211
)
0 commit comments