mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-13 08:15:14 +02:00
Align the tree with AGENTS.md/CLAUDE.md conventions: - Rewrite user-facing strings, docs, and tests to lowercase `ktx` (no bare uppercase `KTX` tokens remain outside literal identifiers). - Drop the legacy `historicSql` migration path and its now-unused helpers, per the no-backward-compat rule. - Remove `as unknown as` / `any` casts: narrow `BaseTool` generics to `z.ZodObject`, add a typed `createLookerClient`, and delete the dead `getParametersSchema`/`toAnthropicFormat` pre-AI-SDK helpers. - Use `InvalidArgumentError` for Commander parse failures. - Finish the adapter→connector prose conversion in the `ktx.yaml` docs while keeping the literal `adapters` config key.
34 lines
1.6 KiB
TypeScript
34 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { KtxPostgresDialect } from '../../../src/connectors/postgres/dialect.js';
|
|
|
|
describe('KtxPostgresDialect', () => {
|
|
const dialect = new KtxPostgresDialect();
|
|
|
|
it('quotes identifiers and formats schema-qualified tables', () => {
|
|
expect(dialect.quoteIdentifier('order"items')).toBe('"order""items"');
|
|
expect(dialect.formatTableName({ catalog: null, db: 'public', name: 'orders' })).toBe('"public"."orders"');
|
|
expect(dialect.formatTableName({ catalog: null, db: null, name: 'orders' })).toBe('"orders"');
|
|
});
|
|
|
|
it('maps native PostgreSQL types to ktx dimension types', () => {
|
|
expect(dialect.mapToDimensionType('timestamp with time zone')).toBe('time');
|
|
expect(dialect.mapToDimensionType('numeric(12,2)')).toBe('number');
|
|
expect(dialect.mapToDimensionType('uuid')).toBe('string');
|
|
expect(dialect.mapToDimensionType('boolean')).toBe('boolean');
|
|
expect(dialect.mapToDimensionType('jsonb')).toBe('string');
|
|
});
|
|
|
|
it('generates sample, distinct-value, and statistics SQL', () => {
|
|
expect(dialect.generateSampleQuery('"public"."orders"', 5, ['id', 'status'])).toBe(
|
|
'SELECT "id", "status" FROM "public"."orders" LIMIT 5',
|
|
);
|
|
expect(dialect.generateColumnSampleQuery('"public"."orders"', 'status', 10)).toContain(
|
|
'TRIM(CAST("status" AS TEXT)) != \'\'',
|
|
);
|
|
expect(dialect.generateDistinctValuesQuery('"public"."orders"', '"status"', 20)).toContain(
|
|
'SELECT DISTINCT "status"::text AS val',
|
|
);
|
|
expect(dialect.generateColumnStatisticsQuery('public', 'orders')).toContain('FROM pg_stats s');
|
|
});
|
|
|
|
});
|