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.
37 lines
1.8 KiB
TypeScript
37 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { KtxSqlServerDialect } from '../../../src/connectors/sqlserver/dialect.js';
|
|
|
|
describe('KtxSqlServerDialect', () => {
|
|
const dialect = new KtxSqlServerDialect();
|
|
|
|
it('quotes identifiers and formats schema-qualified table names', () => {
|
|
expect(dialect.quoteIdentifier('events')).toBe('[events]');
|
|
expect(dialect.quoteIdentifier('odd]name')).toBe('[odd]]name]');
|
|
expect(dialect.formatTableName({ catalog: 'warehouse', db: 'dbo', name: 'events' })).toBe(
|
|
'[warehouse].[dbo].[events]',
|
|
);
|
|
expect(dialect.formatTableName({ catalog: null, db: null, name: 'events' })).toBe('[events]');
|
|
});
|
|
|
|
it('maps SQL Server types to ktx dimension types', () => {
|
|
expect(dialect.mapToDimensionType('datetime2')).toBe('time');
|
|
expect(dialect.mapToDimensionType('decimal(18, 2)')).toBe('number');
|
|
expect(dialect.mapToDimensionType('bigint')).toBe('number');
|
|
expect(dialect.mapToDimensionType('bit')).toBe('boolean');
|
|
expect(dialect.mapToDimensionType('uniqueidentifier')).toBe('string');
|
|
expect(dialect.mapToDimensionType('')).toBe('string');
|
|
});
|
|
|
|
it('builds sampling, distinct-value, and pagination SQL', () => {
|
|
expect(dialect.generateSampleQuery('[dbo].[events]', 25, ['id', 'event_name'])).toBe(
|
|
'SELECT TOP 25 [id], [event_name] FROM [dbo].[events]',
|
|
);
|
|
expect(dialect.generateColumnSampleQuery('[dbo].[events]', 'event_name', 10)).toBe(
|
|
"SELECT TOP 10 [event_name] FROM [dbo].[events] WHERE [event_name] IS NOT NULL AND LTRIM(RTRIM(CAST([event_name] AS NVARCHAR(MAX)))) != ''",
|
|
);
|
|
expect(dialect.generateDistinctValuesQuery('[dbo].[events]', '[event_name]', 5)).toContain('SELECT TOP 5 val');
|
|
expect(dialect.getTopClause(10)).toBe('TOP (10)');
|
|
expect(dialect.getLimitOffsetClause(10, 20)).toBe('');
|
|
});
|
|
|
|
});
|