fix: sql guard gaps, date tz, timeouts, payload
This commit is contained in:
@@ -41,9 +41,14 @@ const pgState = vi.hoisted(() => {
|
||||
return { state, FakePool }
|
||||
})
|
||||
|
||||
vi.mock('pg', () => ({
|
||||
default: { Pool: pgState.FakePool }
|
||||
}))
|
||||
vi.mock('pg', async () => {
|
||||
// Use the real TypeOverrides so the driver's date/timestamp parser overrides
|
||||
// are exercised against pg's genuine default parsers (e.g. timestamptz).
|
||||
const actual = (await vi.importActual('pg')) as { default: { TypeOverrides: unknown } }
|
||||
return {
|
||||
default: { Pool: pgState.FakePool, TypeOverrides: actual.default.TypeOverrides }
|
||||
}
|
||||
})
|
||||
|
||||
import type { ConnectionConfig } from '../../../src/config/types.js'
|
||||
import { createPostgresDriver } from '../../../src/db/postgres.js'
|
||||
@@ -87,6 +92,27 @@ describe('createPostgresDriver', () => {
|
||||
expect(pgState.state.pools[1].options).toMatchObject({ database: 'other' })
|
||||
})
|
||||
|
||||
it('sets a connection timeout on every pool', async () => {
|
||||
const driver = createPostgresDriver(target())
|
||||
await driver.query({ sql: 'select 1', rowLimit: 10 })
|
||||
expect(pgState.state.pools[0].options.connectionTimeoutMillis).toBe(10_000)
|
||||
})
|
||||
|
||||
it('returns wall-clock date/timestamp types as raw strings, keeps tz absolute', async () => {
|
||||
const driver = createPostgresDriver(target())
|
||||
await driver.query({ sql: 'select 1', rowLimit: 10 })
|
||||
const types = pgState.state.pools[0].options.types as {
|
||||
getTypeParser: (oid: number, format?: string) => (value: string) => unknown
|
||||
}
|
||||
// DATE (1082) and TIMESTAMP without tz (1114) stay raw strings.
|
||||
expect(types.getTypeParser(1082)('2026-06-11')).toBe('2026-06-11')
|
||||
expect(types.getTypeParser(1114)('2026-06-11 12:34:56')).toBe('2026-06-11 12:34:56')
|
||||
// TIMESTAMPTZ (1184) keeps the default parser, which is not identity.
|
||||
expect(types.getTypeParser(1184)('2026-06-11 12:34:56+00')).not.toBe(
|
||||
'2026-06-11 12:34:56+00'
|
||||
)
|
||||
})
|
||||
|
||||
it('passes readonly as a startup option', async () => {
|
||||
const driver = createPostgresDriver(target({ readonly: true }))
|
||||
await driver.query({ sql: 'select 1', rowLimit: 10 })
|
||||
|
||||
Reference in New Issue
Block a user