Skip to content

Commit deb5ade

Browse files
Fix issue in Database.sql(sql, ...params)
- when used as regular function, not as template `ticks`
1 parent e4effee commit deb5ade

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export class Database extends EventEmitter {
410410
} else {
411411
if (typeof sql === 'string') {
412412
if (values?.length > 0) {
413-
preparedSql = prepareSql(preparedSql, ...values)
413+
preparedSql = prepareSql(sql, ...values)
414414
} else {
415415
preparedSql = sql
416416
}

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// index.ts - re-export all the public APIs
33
//
44

5+
export { Database } from './database'
6+
export { Statement } from './statement'
7+
58
export { SQLiteCloudConfig, SQLCloudRowsetMetadata, SQLiteCloudError, ErrorCallback } from './types'
69
export { SQLiteCloudRowset, SQLiteCloudRow } from './rowset'
710
export { SQLiteCloudConnection } from './connection'
811

9-
export { Database } from './database'
10-
export { Statement } from './statement'
12+
export { escapeSqlParameter, prepareSql } from './utilities'

test/database.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ describe('Database.sql (async)', () => {
259259
chinook.close()
260260
})
261261

262+
it('should work with regular function parameters', async () => {
263+
const database = await getTestingDatabase()
264+
const results = await database.sql('SELECT * FROM people WHERE name = ?', 'Emma Johnson')
265+
expect(results).toHaveLength(1)
266+
database.close()
267+
})
268+
262269
it('should select and return multiple rows', async () => {
263270
const database = await getTestingDatabase()
264271
const results = await database.sql('SELECT * FROM people ORDER BY id')

0 commit comments

Comments
 (0)