forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpressions.ts
25 lines (22 loc) · 860 Bytes
/
expressions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { bindIfParam } from '~/expressions';
import type { Placeholder, SQL, SQLChunk, SQLWrapper } from '~/sql';
import { sql } from '~/sql';
import type { AnyMySqlColumn } from './columns/common';
export * from '~/expressions';
export function concat(column: AnyMySqlColumn | SQL.Aliased, value: string | Placeholder | SQLWrapper): SQL {
return sql`${column} || ${bindIfParam(value, column)}`;
}
export function substring(
column: AnyMySqlColumn | SQL.Aliased,
{ from, for: _for }: { from?: number | Placeholder | SQLWrapper; for?: number | Placeholder | SQLWrapper },
): SQL {
const chunks: SQLChunk[] = [sql`substring(`, column];
if (from !== undefined) {
chunks.push(sql` from `, bindIfParam(from, column));
}
if (_for !== undefined) {
chunks.push(sql` for `, bindIfParam(_for, column));
}
chunks.push(sql`)`);
return sql.join(chunks);
}