Skip to content

Commit bf2b5a2

Browse files
committed
Added SQLite formatter for SQL template literal
1 parent 42fad32 commit bf2b5a2

File tree

5 files changed

+528
-3
lines changed

5 files changed

+528
-3
lines changed

src/packages/dumbo/src/core/sql/index.tagged-template.unit.spec.ts renamed to src/packages/dumbo/src/core/sql/pg-format/sqlFormatter.unit.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'assert';
22
import { describe, it } from 'node:test';
3+
import { pgFormatter } from '.';
34
import {
45
SQL,
56
identifier,
@@ -8,8 +9,7 @@ import {
89
plainString,
910
processDeferredSQL,
1011
rawSql,
11-
} from '.';
12-
import { pgFormatter } from './pg-format';
12+
} from '..';
1313

1414
export function processSQLForTesting(sql: SQL): string {
1515
const formatter = pgFormatter;

src/packages/dumbo/src/core/sql/sqlFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function formatValue(value: unknown, formatter: SQLFormatter): string {
3737

3838
return formatter.formatBigInt
3939
? formatter.formatBigInt(value)
40-
: formatter.formatLiteral(value.toString());
40+
: formatter.formatLiteral(value);
4141
} else if (value instanceof Date) {
4242
// Let the formatter handle dates consistently
4343
return formatter.formatDate
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { JSONSerializer } from '../../serializer';
2+
import { type SQLFormatter, registerFormatter } from '../sql';
3+
import format from './sqliteFormat';
4+
5+
const sqliteFormatter: SQLFormatter = {
6+
formatIdentifier: format.ident,
7+
formatLiteral: format.literal,
8+
formatString: format.string,
9+
formatArray: (array, itemFormatter) => {
10+
if (array.length === 0) return '()';
11+
return '(' + array.map(itemFormatter).join(', ') + ')';
12+
},
13+
formatDate: (value) => format.literal(value.toISOString()),
14+
formatObject: (value) =>
15+
`'${JSONSerializer.serialize(value).replace(/'/g, "''")}'`,
16+
};
17+
18+
registerFormatter('SQLite', sqliteFormatter);
19+
20+
export { format, sqliteFormatter };

0 commit comments

Comments
 (0)