feat: add driver interface, database resolution

This commit is contained in:
smartass
2026-06-11 23:36:00 +05:00
parent 8fb44dbfb3
commit 750430e91f
2 changed files with 115 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import type { ConnectionConfig } from '../../../src/config/types.js'
import { MissingDatabaseError, resolveDatabase } from '../../../src/db/driver.js'
const config: ConnectionConfig = {
name: 'c',
type: 'postgres',
host: 'h',
user: 'u',
readonly: false
}
describe('resolveDatabase', () => {
it('prefers the explicit parameter', () => {
expect(resolveDatabase({ ...config, database: 'default-db' }, 'explicit')).toBe('explicit')
})
it('falls back to the connection default', () => {
expect(resolveDatabase({ ...config, database: 'default-db' }, undefined)).toBe('default-db')
})
it('throws when neither is set', () => {
expect(() => resolveDatabase(config, undefined)).toThrow(MissingDatabaseError)
})
})