@deepagents/text2sql 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +69 -11
- package/dist/index.js.map +3 -3
- package/dist/lib/adapters/adapter.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.d.ts +0 -3
- package/dist/lib/adapters/bigquery/index.d.ts.map +1 -1
- package/dist/lib/adapters/bigquery/index.js +0 -108
- package/dist/lib/adapters/bigquery/index.js.map +4 -4
- package/dist/lib/adapters/groundings/context.d.ts +0 -2
- package/dist/lib/adapters/groundings/context.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/index.d.ts +0 -1
- package/dist/lib/adapters/groundings/index.d.ts.map +1 -1
- package/dist/lib/adapters/groundings/index.js +0 -101
- package/dist/lib/adapters/groundings/index.js.map +3 -3
- package/dist/lib/adapters/mysql/index.d.ts +0 -3
- package/dist/lib/adapters/mysql/index.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/index.js +0 -108
- package/dist/lib/adapters/mysql/index.js.map +4 -4
- package/dist/lib/adapters/postgres/index.d.ts +2 -5
- package/dist/lib/adapters/postgres/index.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/index.js +142 -250
- package/dist/lib/adapters/postgres/index.js.map +4 -4
- package/dist/lib/adapters/spreadsheet/index.js +34 -52
- package/dist/lib/adapters/spreadsheet/index.js.map +3 -3
- package/dist/lib/adapters/sqlite/index.d.ts +2 -5
- package/dist/lib/adapters/sqlite/index.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/index.js +101 -209
- package/dist/lib/adapters/sqlite/index.js.map +4 -4
- package/dist/lib/adapters/sqlserver/index.d.ts +2 -5
- package/dist/lib/adapters/sqlserver/index.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/index.js +100 -208
- package/dist/lib/adapters/sqlserver/index.js.map +4 -4
- package/dist/lib/agents/result-tools.d.ts.map +1 -1
- package/dist/lib/synthesis/decorators/deduplicated-producer.d.ts +1 -0
- package/dist/lib/synthesis/decorators/deduplicated-producer.d.ts.map +1 -1
- package/dist/lib/synthesis/decorators/filtered-producer.d.ts +3 -0
- package/dist/lib/synthesis/decorators/filtered-producer.d.ts.map +1 -1
- package/dist/lib/synthesis/index.js +31 -6
- package/dist/lib/synthesis/index.js.map +4 -4
- package/package.json +4 -4
- package/dist/lib/adapters/groundings/report.grounding.d.ts +0 -38
- package/dist/lib/adapters/groundings/report.grounding.d.ts.map +0 -1
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { type Adapter } from '../adapter.ts';
|
|
2
2
|
import { type ColumnStatsGroundingConfig } from '../groundings/column-stats.grounding.ts';
|
|
3
|
+
import { type ColumnValuesGroundingConfig } from '../groundings/column-values.grounding.ts';
|
|
3
4
|
import { type ConstraintGroundingConfig } from '../groundings/constraint.grounding.ts';
|
|
4
5
|
import { type IndexesGroundingConfig } from '../groundings/indexes.grounding.ts';
|
|
5
6
|
import { type InfoGroundingConfig } from '../groundings/info.grounding.ts';
|
|
6
|
-
import { type ColumnValuesGroundingConfig } from '../groundings/column-values.grounding.ts';
|
|
7
|
-
import { ReportGrounding, type ReportGroundingConfig } from '../groundings/report.grounding.ts';
|
|
8
7
|
import { type RowCountGroundingConfig } from '../groundings/row-count.grounding.ts';
|
|
9
8
|
import { type TableGroundingConfig } from '../groundings/table.grounding.ts';
|
|
10
9
|
import type { ViewGroundingConfig } from '../groundings/view.grounding.ts';
|
|
11
10
|
import { SqlServerColumnStatsGrounding } from './column-stats.sqlserver.grounding.ts';
|
|
11
|
+
import { SqlServerColumnValuesGrounding } from './column-values.sqlserver.grounding.ts';
|
|
12
12
|
import { SqlServerConstraintGrounding } from './constraint.sqlserver.grounding.ts';
|
|
13
13
|
import { SqlServerIndexesGrounding } from './indexes.sqlserver.grounding.ts';
|
|
14
14
|
import { SqlServerInfoGrounding } from './info.sqlserver.grounding.ts';
|
|
15
|
-
import { SqlServerColumnValuesGrounding } from './column-values.sqlserver.grounding.ts';
|
|
16
15
|
import { SqlServerRowCountGrounding } from './row-count.sqlserver.grounding.ts';
|
|
17
16
|
import { SqlServer } from './sqlserver.ts';
|
|
18
17
|
import { SqlServerTableGrounding } from './table.sqlserver.grounding.ts';
|
|
@@ -26,7 +25,6 @@ export declare function columnValues(config?: ColumnValuesGroundingConfig): (ada
|
|
|
26
25
|
export declare function indexes(config?: IndexesGroundingConfig): (adapter: Adapter) => SqlServerIndexesGrounding;
|
|
27
26
|
export declare function rowCount(config?: RowCountGroundingConfig): (adapter: Adapter) => SqlServerRowCountGrounding;
|
|
28
27
|
export declare function constraints(config?: ConstraintGroundingConfig): (adapter: Adapter) => SqlServerConstraintGrounding;
|
|
29
|
-
export declare function report(config?: ReportGroundingConfig): (adapter: Adapter) => ReportGrounding;
|
|
30
28
|
declare const _default: {
|
|
31
29
|
tables: typeof tables;
|
|
32
30
|
info: typeof info;
|
|
@@ -36,7 +34,6 @@ declare const _default: {
|
|
|
36
34
|
indexes: typeof indexes;
|
|
37
35
|
rowCount: typeof rowCount;
|
|
38
36
|
constraints: typeof constraints;
|
|
39
|
-
report: typeof report;
|
|
40
37
|
SqlServer: typeof SqlServer;
|
|
41
38
|
};
|
|
42
39
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/sqlserver/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/sqlserver/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,cAAc,gBAAgB,CAAC;AAE/B,wBAAgB,MAAM,CAAC,MAAM,GAAE,oBAAyB,IAC9C,SAAS,OAAO,6BACzB;AAED,wBAAgB,IAAI,CAAC,MAAM,GAAE,mBAAwB,IAC3C,SAAS,OAAO,4BACzB;AAED,wBAAgB,KAAK,CAAC,MAAM,GAAE,mBAAwB,IAC5C,SAAS,OAAO,4BAGzB;AAED,wBAAgB,WAAW,CAAC,MAAM,GAAE,0BAA+B,IACzD,SAAS,OAAO,mCAGzB;AAED,wBAAgB,YAAY,CAAC,MAAM,GAAE,2BAAgC,IAC3D,SAAS,OAAO,oCAGzB;AAED,wBAAgB,OAAO,CAAC,MAAM,GAAE,sBAA2B,IACjD,SAAS,OAAO,+BAGzB;AAED,wBAAgB,QAAQ,CAAC,MAAM,GAAE,uBAA4B,IACnD,SAAS,OAAO,gCAGzB;AAED,wBAAgB,WAAW,CAAC,MAAM,GAAE,yBAA8B,IACxD,SAAS,OAAO,kCAGzB;;;;;;;;;;;;AAED,wBAUE"}
|
|
@@ -346,9 +346,6 @@ var Adapter = class {
|
|
|
346
346
|
this.#relationshipToFragment(rel, sourceTable, targetTable)
|
|
347
347
|
);
|
|
348
348
|
}
|
|
349
|
-
if (ctx.report) {
|
|
350
|
-
fragments.push({ name: "businessContext", data: ctx.report });
|
|
351
|
-
}
|
|
352
349
|
return fragments;
|
|
353
350
|
}
|
|
354
351
|
/**
|
|
@@ -658,64 +655,6 @@ var ColumnStatsGrounding = class extends AbstractGrounding {
|
|
|
658
655
|
}
|
|
659
656
|
};
|
|
660
657
|
|
|
661
|
-
// packages/text2sql/src/lib/adapters/groundings/constraint.grounding.ts
|
|
662
|
-
var ConstraintGrounding = class extends AbstractGrounding {
|
|
663
|
-
constructor(config = {}) {
|
|
664
|
-
super("constraint");
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Execute the grounding process.
|
|
668
|
-
* Annotates tables in ctx.tables with their constraints.
|
|
669
|
-
*/
|
|
670
|
-
async execute(ctx) {
|
|
671
|
-
for (const table2 of ctx.tables) {
|
|
672
|
-
try {
|
|
673
|
-
table2.constraints = await this.getConstraints(table2.name);
|
|
674
|
-
} catch (error) {
|
|
675
|
-
console.warn("Error collecting constraints for", table2.name, error);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
// packages/text2sql/src/lib/adapters/groundings/indexes.grounding.ts
|
|
682
|
-
var IndexesGrounding = class extends AbstractGrounding {
|
|
683
|
-
constructor(config = {}) {
|
|
684
|
-
super("index");
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Execute the grounding process.
|
|
688
|
-
* Annotates tables in ctx.tables with their indexes and marks indexed columns.
|
|
689
|
-
*/
|
|
690
|
-
async execute(ctx) {
|
|
691
|
-
for (const table2 of ctx.tables) {
|
|
692
|
-
table2.indexes = await this.getIndexes(table2.name);
|
|
693
|
-
for (const index2 of table2.indexes ?? []) {
|
|
694
|
-
for (const colName of index2.columns) {
|
|
695
|
-
const column2 = table2.columns.find((c) => c.name === colName);
|
|
696
|
-
if (column2) {
|
|
697
|
-
column2.isIndexed = true;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
// packages/text2sql/src/lib/adapters/groundings/info.grounding.ts
|
|
706
|
-
var InfoGrounding = class extends AbstractGrounding {
|
|
707
|
-
constructor(config = {}) {
|
|
708
|
-
super("dialectInfo");
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Execute the grounding process.
|
|
712
|
-
* Writes database info to ctx.info.
|
|
713
|
-
*/
|
|
714
|
-
async execute(ctx) {
|
|
715
|
-
ctx.info = await this.collectInfo();
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
|
|
719
658
|
// packages/text2sql/src/lib/adapters/groundings/column-values.grounding.ts
|
|
720
659
|
var ColumnValuesGrounding = class extends AbstractGrounding {
|
|
721
660
|
lowCardinalityLimit;
|
|
@@ -855,103 +794,61 @@ var ColumnValuesGrounding = class extends AbstractGrounding {
|
|
|
855
794
|
}
|
|
856
795
|
};
|
|
857
796
|
|
|
858
|
-
// packages/text2sql/src/lib/adapters/groundings/
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
import z from "zod";
|
|
863
|
-
import "@deepagents/agent";
|
|
864
|
-
import {
|
|
865
|
-
ContextEngine,
|
|
866
|
-
InMemoryContextStore,
|
|
867
|
-
agent,
|
|
868
|
-
fragment,
|
|
869
|
-
persona,
|
|
870
|
-
user
|
|
871
|
-
} from "@deepagents/context";
|
|
872
|
-
var ReportGrounding = class extends AbstractGrounding {
|
|
873
|
-
#adapter;
|
|
874
|
-
#model;
|
|
875
|
-
#cache;
|
|
876
|
-
#forceRefresh;
|
|
877
|
-
constructor(adapter, config = {}) {
|
|
878
|
-
super("business_context");
|
|
879
|
-
this.#adapter = adapter;
|
|
880
|
-
this.#model = config.model ?? groq("openai/gpt-oss-20b");
|
|
881
|
-
this.#cache = config.cache;
|
|
882
|
-
this.#forceRefresh = config.forceRefresh ?? false;
|
|
797
|
+
// packages/text2sql/src/lib/adapters/groundings/constraint.grounding.ts
|
|
798
|
+
var ConstraintGrounding = class extends AbstractGrounding {
|
|
799
|
+
constructor(config = {}) {
|
|
800
|
+
super("constraint");
|
|
883
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Execute the grounding process.
|
|
804
|
+
* Annotates tables in ctx.tables with their constraints.
|
|
805
|
+
*/
|
|
884
806
|
async execute(ctx) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
807
|
+
for (const table2 of ctx.tables) {
|
|
808
|
+
try {
|
|
809
|
+
table2.constraints = await this.getConstraints(table2.name);
|
|
810
|
+
} catch (error) {
|
|
811
|
+
console.warn("Error collecting constraints for", table2.name, error);
|
|
890
812
|
}
|
|
891
813
|
}
|
|
892
|
-
const report2 = await this.#generateReport();
|
|
893
|
-
ctx.report = report2;
|
|
894
|
-
if (this.#cache) {
|
|
895
|
-
await this.#cache.set(report2);
|
|
896
|
-
}
|
|
897
814
|
}
|
|
898
|
-
|
|
899
|
-
const context = new ContextEngine({
|
|
900
|
-
store: new InMemoryContextStore(),
|
|
901
|
-
chatId: `report-gen-${crypto.randomUUID()}`,
|
|
902
|
-
userId: "system"
|
|
903
|
-
});
|
|
904
|
-
context.set(
|
|
905
|
-
persona({
|
|
906
|
-
name: "db-report-agent",
|
|
907
|
-
role: "Database analyst",
|
|
908
|
-
objective: "Analyze the database and write a contextual report about what it represents"
|
|
909
|
-
}),
|
|
910
|
-
fragment(
|
|
911
|
-
"instructions",
|
|
912
|
-
dedent`
|
|
913
|
-
Write a business context that helps another agent answer questions accurately.
|
|
914
|
-
|
|
915
|
-
For EACH table, do queries ONE AT A TIME:
|
|
916
|
-
1. SELECT COUNT(*) to get row count
|
|
917
|
-
2. SELECT * LIMIT 3 to see sample data
|
|
918
|
-
|
|
919
|
-
Then write a report with:
|
|
920
|
-
- What business this database is for
|
|
921
|
-
- For each table: purpose, row count, and example of what the data looks like
|
|
922
|
-
|
|
923
|
-
Include concrete examples like "Track prices are $0.99",
|
|
924
|
-
"Customer names like 'Luís Gonçalves'", etc.
|
|
815
|
+
};
|
|
925
816
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
purpose: z.string().describe(
|
|
944
|
-
"What insight you are trying to gather with this query"
|
|
945
|
-
)
|
|
946
|
-
}),
|
|
947
|
-
execute: ({ sql }) => {
|
|
948
|
-
return adapter.execute(sql);
|
|
817
|
+
// packages/text2sql/src/lib/adapters/groundings/indexes.grounding.ts
|
|
818
|
+
var IndexesGrounding = class extends AbstractGrounding {
|
|
819
|
+
constructor(config = {}) {
|
|
820
|
+
super("index");
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Execute the grounding process.
|
|
824
|
+
* Annotates tables in ctx.tables with their indexes and marks indexed columns.
|
|
825
|
+
*/
|
|
826
|
+
async execute(ctx) {
|
|
827
|
+
for (const table2 of ctx.tables) {
|
|
828
|
+
table2.indexes = await this.getIndexes(table2.name);
|
|
829
|
+
for (const index2 of table2.indexes ?? []) {
|
|
830
|
+
for (const colName of index2.columns) {
|
|
831
|
+
const column2 = table2.columns.find((c) => c.name === colName);
|
|
832
|
+
if (column2) {
|
|
833
|
+
column2.isIndexed = true;
|
|
949
834
|
}
|
|
950
|
-
}
|
|
835
|
+
}
|
|
951
836
|
}
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
// packages/text2sql/src/lib/adapters/groundings/info.grounding.ts
|
|
842
|
+
var InfoGrounding = class extends AbstractGrounding {
|
|
843
|
+
constructor(config = {}) {
|
|
844
|
+
super("dialectInfo");
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Execute the grounding process.
|
|
848
|
+
* Writes database info to ctx.info.
|
|
849
|
+
*/
|
|
850
|
+
async execute(ctx) {
|
|
851
|
+
ctx.info = await this.collectInfo();
|
|
955
852
|
}
|
|
956
853
|
};
|
|
957
854
|
|
|
@@ -1217,6 +1114,59 @@ var SqlServerColumnStatsGrounding = class extends ColumnStatsGrounding {
|
|
|
1217
1114
|
}
|
|
1218
1115
|
};
|
|
1219
1116
|
|
|
1117
|
+
// packages/text2sql/src/lib/adapters/sqlserver/column-values.sqlserver.grounding.ts
|
|
1118
|
+
var SqlServerColumnValuesGrounding = class extends ColumnValuesGrounding {
|
|
1119
|
+
#adapter;
|
|
1120
|
+
constructor(adapter, config = {}) {
|
|
1121
|
+
super(config);
|
|
1122
|
+
this.#adapter = adapter;
|
|
1123
|
+
}
|
|
1124
|
+
#isHighCardinality(column2) {
|
|
1125
|
+
const nDistinct = column2.stats?.nDistinct;
|
|
1126
|
+
if (nDistinct != null) {
|
|
1127
|
+
if (nDistinct > 0) return nDistinct > this.lowCardinalityLimit;
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
const type = column2.type.toLowerCase();
|
|
1131
|
+
if (/nvarchar\s*\(\s*max\s*\)|varchar\s*\(\s*max\s*\)|text|ntext|xml|image|varbinary\s*\(\s*max\s*\)|uniqueidentifier/.test(
|
|
1132
|
+
type
|
|
1133
|
+
)) {
|
|
1134
|
+
return true;
|
|
1135
|
+
}
|
|
1136
|
+
const varcharMatch = type.match(/n?varchar\s*\(\s*(\d+)\s*\)/);
|
|
1137
|
+
if (varcharMatch && parseInt(varcharMatch[1]) > 255) {
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
async collectLowCardinality(tableName, column2) {
|
|
1143
|
+
if (this.#isHighCardinality(column2)) {
|
|
1144
|
+
return void 0;
|
|
1145
|
+
}
|
|
1146
|
+
const { schema, table: table2 } = this.#adapter.parseTableName(tableName);
|
|
1147
|
+
const tableIdentifier = `[${this.#adapter.escape(schema)}].[${this.#adapter.escape(table2)}]`;
|
|
1148
|
+
const columnIdentifier = `[${this.#adapter.escape(column2.name)}]`;
|
|
1149
|
+
const limit = this.lowCardinalityLimit + 1;
|
|
1150
|
+
const sql = `
|
|
1151
|
+
SELECT DISTINCT TOP ${limit} CAST(${columnIdentifier} AS NVARCHAR(MAX)) AS value
|
|
1152
|
+
FROM ${tableIdentifier}
|
|
1153
|
+
WHERE ${columnIdentifier} IS NOT NULL
|
|
1154
|
+
`;
|
|
1155
|
+
const rows = await this.#adapter.runQuery(sql);
|
|
1156
|
+
if (!rows.length || rows.length > this.lowCardinalityLimit) {
|
|
1157
|
+
return void 0;
|
|
1158
|
+
}
|
|
1159
|
+
const values = [];
|
|
1160
|
+
for (const row of rows) {
|
|
1161
|
+
if (row.value == null) {
|
|
1162
|
+
return void 0;
|
|
1163
|
+
}
|
|
1164
|
+
values.push(row.value);
|
|
1165
|
+
}
|
|
1166
|
+
return values.length ? values : void 0;
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1220
1170
|
// packages/text2sql/src/lib/adapters/sqlserver/constraint.sqlserver.grounding.ts
|
|
1221
1171
|
var SqlServerConstraintGrounding = class extends ConstraintGrounding {
|
|
1222
1172
|
#adapter;
|
|
@@ -1448,59 +1398,6 @@ var SqlServerInfoGrounding = class extends InfoGrounding {
|
|
|
1448
1398
|
}
|
|
1449
1399
|
};
|
|
1450
1400
|
|
|
1451
|
-
// packages/text2sql/src/lib/adapters/sqlserver/column-values.sqlserver.grounding.ts
|
|
1452
|
-
var SqlServerColumnValuesGrounding = class extends ColumnValuesGrounding {
|
|
1453
|
-
#adapter;
|
|
1454
|
-
constructor(adapter, config = {}) {
|
|
1455
|
-
super(config);
|
|
1456
|
-
this.#adapter = adapter;
|
|
1457
|
-
}
|
|
1458
|
-
#isHighCardinality(column2) {
|
|
1459
|
-
const nDistinct = column2.stats?.nDistinct;
|
|
1460
|
-
if (nDistinct != null) {
|
|
1461
|
-
if (nDistinct > 0) return nDistinct > this.lowCardinalityLimit;
|
|
1462
|
-
return true;
|
|
1463
|
-
}
|
|
1464
|
-
const type = column2.type.toLowerCase();
|
|
1465
|
-
if (/nvarchar\s*\(\s*max\s*\)|varchar\s*\(\s*max\s*\)|text|ntext|xml|image|varbinary\s*\(\s*max\s*\)|uniqueidentifier/.test(
|
|
1466
|
-
type
|
|
1467
|
-
)) {
|
|
1468
|
-
return true;
|
|
1469
|
-
}
|
|
1470
|
-
const varcharMatch = type.match(/n?varchar\s*\(\s*(\d+)\s*\)/);
|
|
1471
|
-
if (varcharMatch && parseInt(varcharMatch[1]) > 255) {
|
|
1472
|
-
return true;
|
|
1473
|
-
}
|
|
1474
|
-
return false;
|
|
1475
|
-
}
|
|
1476
|
-
async collectLowCardinality(tableName, column2) {
|
|
1477
|
-
if (this.#isHighCardinality(column2)) {
|
|
1478
|
-
return void 0;
|
|
1479
|
-
}
|
|
1480
|
-
const { schema, table: table2 } = this.#adapter.parseTableName(tableName);
|
|
1481
|
-
const tableIdentifier = `[${this.#adapter.escape(schema)}].[${this.#adapter.escape(table2)}]`;
|
|
1482
|
-
const columnIdentifier = `[${this.#adapter.escape(column2.name)}]`;
|
|
1483
|
-
const limit = this.lowCardinalityLimit + 1;
|
|
1484
|
-
const sql = `
|
|
1485
|
-
SELECT DISTINCT TOP ${limit} CAST(${columnIdentifier} AS NVARCHAR(MAX)) AS value
|
|
1486
|
-
FROM ${tableIdentifier}
|
|
1487
|
-
WHERE ${columnIdentifier} IS NOT NULL
|
|
1488
|
-
`;
|
|
1489
|
-
const rows = await this.#adapter.runQuery(sql);
|
|
1490
|
-
if (!rows.length || rows.length > this.lowCardinalityLimit) {
|
|
1491
|
-
return void 0;
|
|
1492
|
-
}
|
|
1493
|
-
const values = [];
|
|
1494
|
-
for (const row of rows) {
|
|
1495
|
-
if (row.value == null) {
|
|
1496
|
-
return void 0;
|
|
1497
|
-
}
|
|
1498
|
-
values.push(row.value);
|
|
1499
|
-
}
|
|
1500
|
-
return values.length ? values : void 0;
|
|
1501
|
-
}
|
|
1502
|
-
};
|
|
1503
|
-
|
|
1504
1401
|
// packages/text2sql/src/lib/adapters/sqlserver/row-count.sqlserver.grounding.ts
|
|
1505
1402
|
var SqlServerRowCountGrounding = class extends RowCountGrounding {
|
|
1506
1403
|
#adapter;
|
|
@@ -2260,9 +2157,6 @@ function constraints(config = {}) {
|
|
|
2260
2157
|
return new SqlServerConstraintGrounding(adapter, config);
|
|
2261
2158
|
};
|
|
2262
2159
|
}
|
|
2263
|
-
function report(config = {}) {
|
|
2264
|
-
return (adapter) => new ReportGrounding(adapter, config);
|
|
2265
|
-
}
|
|
2266
2160
|
var sqlserver_default = {
|
|
2267
2161
|
tables,
|
|
2268
2162
|
info,
|
|
@@ -2272,7 +2166,6 @@ var sqlserver_default = {
|
|
|
2272
2166
|
indexes,
|
|
2273
2167
|
rowCount,
|
|
2274
2168
|
constraints,
|
|
2275
|
-
report,
|
|
2276
2169
|
SqlServer
|
|
2277
2170
|
};
|
|
2278
2171
|
export {
|
|
@@ -2284,7 +2177,6 @@ export {
|
|
|
2284
2177
|
formatSqlServerError,
|
|
2285
2178
|
indexes,
|
|
2286
2179
|
info,
|
|
2287
|
-
report,
|
|
2288
2180
|
rowCount,
|
|
2289
2181
|
tables,
|
|
2290
2182
|
views
|