@deepagents/text2sql 0.32.0 → 0.33.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 { SqliteColumnStatsGrounding } from './column-stats.sqlite.grounding.ts';
|
|
11
|
+
import { SqliteColumnValuesGrounding } from './column-values.sqlite.grounding.ts';
|
|
12
12
|
import { SqliteConstraintGrounding } from './constraint.sqlite.grounding.ts';
|
|
13
13
|
import { SqliteIndexesGrounding } from './indexes.sqlite.grounding.ts';
|
|
14
14
|
import { SqliteInfoGrounding } from './info.sqlite.grounding.ts';
|
|
15
|
-
import { SqliteColumnValuesGrounding } from './column-values.sqlite.grounding.ts';
|
|
16
15
|
import { SqliteRowCountGrounding } from './row-count.sqlite.grounding.ts';
|
|
17
16
|
import { Sqlite } from './sqlite.ts';
|
|
18
17
|
import { SqliteTableGrounding } from './table.sqlite.grounding.ts';
|
|
@@ -26,7 +25,6 @@ export declare function columnValues(config?: ColumnValuesGroundingConfig): (ada
|
|
|
26
25
|
export declare function indexes(config?: IndexesGroundingConfig): (adapter: Adapter) => SqliteIndexesGrounding;
|
|
27
26
|
export declare function rowCount(config?: RowCountGroundingConfig): (adapter: Adapter) => SqliteRowCountGrounding;
|
|
28
27
|
export declare function constraints(config?: ConstraintGroundingConfig): (adapter: Adapter) => SqliteConstraintGrounding;
|
|
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
|
Sqlite: typeof Sqlite;
|
|
41
38
|
};
|
|
42
39
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapters/sqlite/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/sqlite/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,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,cAAc,aAAa,CAAC;AAE5B,wBAAgB,MAAM,CAAC,MAAM,GAAE,oBAAyB,IAC9C,SAAS,OAAO,0BACzB;AAED,wBAAgB,IAAI,CAAC,MAAM,GAAE,mBAAwB,IAC3C,SAAS,OAAO,yBACzB;AAED,wBAAgB,KAAK,CAAC,MAAM,GAAE,mBAAwB,IAC5C,SAAS,OAAO,yBAGzB;AAED,wBAAgB,WAAW,CAAC,MAAM,GAAE,0BAA+B,IACzD,SAAS,OAAO,gCAGzB;AAED,wBAAgB,YAAY,CAAC,MAAM,GAAE,2BAAgC,IAC3D,SAAS,OAAO,iCAGzB;AAED,wBAAgB,OAAO,CAAC,MAAM,GAAE,sBAA2B,IACjD,SAAS,OAAO,4BAGzB;AAED,wBAAgB,QAAQ,CAAC,MAAM,GAAE,uBAA4B,IACnD,SAAS,OAAO,6BAGzB;AAED,wBAAgB,WAAW,CAAC,MAAM,GAAE,yBAA8B,IACxD,SAAS,OAAO,+BAGzB;;;;;;;;;;;;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
|
|
|
@@ -1186,6 +1083,60 @@ var SqliteColumnStatsGrounding = class extends ColumnStatsGrounding {
|
|
|
1186
1083
|
}
|
|
1187
1084
|
};
|
|
1188
1085
|
|
|
1086
|
+
// packages/text2sql/src/lib/adapters/sqlite/column-values.sqlite.grounding.ts
|
|
1087
|
+
var SqliteColumnValuesGrounding = class extends ColumnValuesGrounding {
|
|
1088
|
+
#adapter;
|
|
1089
|
+
constructor(adapter, config = {}) {
|
|
1090
|
+
super(config);
|
|
1091
|
+
this.#adapter = adapter;
|
|
1092
|
+
}
|
|
1093
|
+
async collectLowCardinality(tableName, column2) {
|
|
1094
|
+
const tableIdentifier = this.#adapter.quoteIdentifier(tableName);
|
|
1095
|
+
const columnIdentifier = this.#adapter.quoteIdentifier(column2.name);
|
|
1096
|
+
const limit = this.lowCardinalityLimit + 1;
|
|
1097
|
+
const sql = `
|
|
1098
|
+
SELECT DISTINCT ${columnIdentifier} AS value
|
|
1099
|
+
FROM ${tableIdentifier}
|
|
1100
|
+
WHERE ${columnIdentifier} IS NOT NULL
|
|
1101
|
+
LIMIT ${limit}
|
|
1102
|
+
`;
|
|
1103
|
+
const rows = await this.#adapter.runQuery(sql);
|
|
1104
|
+
if (!rows.length || rows.length > this.lowCardinalityLimit) {
|
|
1105
|
+
return void 0;
|
|
1106
|
+
}
|
|
1107
|
+
const values = [];
|
|
1108
|
+
for (const row of rows) {
|
|
1109
|
+
const formatted = this.#normalizeValue(row.value);
|
|
1110
|
+
if (formatted == null) {
|
|
1111
|
+
return void 0;
|
|
1112
|
+
}
|
|
1113
|
+
values.push(formatted);
|
|
1114
|
+
}
|
|
1115
|
+
return values.length ? values : void 0;
|
|
1116
|
+
}
|
|
1117
|
+
#normalizeValue(value) {
|
|
1118
|
+
if (value === null || value === void 0) {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
if (typeof value === "string") {
|
|
1122
|
+
return value;
|
|
1123
|
+
}
|
|
1124
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
1125
|
+
return String(value);
|
|
1126
|
+
}
|
|
1127
|
+
if (typeof value === "boolean") {
|
|
1128
|
+
return value ? "true" : "false";
|
|
1129
|
+
}
|
|
1130
|
+
if (value instanceof Date) {
|
|
1131
|
+
return value.toISOString();
|
|
1132
|
+
}
|
|
1133
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) {
|
|
1134
|
+
return value.toString("utf-8");
|
|
1135
|
+
}
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1189
1140
|
// packages/text2sql/src/lib/adapters/sqlite/constraint.sqlite.grounding.ts
|
|
1190
1141
|
var SqliteConstraintGrounding = class extends ConstraintGrounding {
|
|
1191
1142
|
#adapter;
|
|
@@ -1365,60 +1316,6 @@ var SqliteInfoGrounding = class extends InfoGrounding {
|
|
|
1365
1316
|
}
|
|
1366
1317
|
};
|
|
1367
1318
|
|
|
1368
|
-
// packages/text2sql/src/lib/adapters/sqlite/column-values.sqlite.grounding.ts
|
|
1369
|
-
var SqliteColumnValuesGrounding = class extends ColumnValuesGrounding {
|
|
1370
|
-
#adapter;
|
|
1371
|
-
constructor(adapter, config = {}) {
|
|
1372
|
-
super(config);
|
|
1373
|
-
this.#adapter = adapter;
|
|
1374
|
-
}
|
|
1375
|
-
async collectLowCardinality(tableName, column2) {
|
|
1376
|
-
const tableIdentifier = this.#adapter.quoteIdentifier(tableName);
|
|
1377
|
-
const columnIdentifier = this.#adapter.quoteIdentifier(column2.name);
|
|
1378
|
-
const limit = this.lowCardinalityLimit + 1;
|
|
1379
|
-
const sql = `
|
|
1380
|
-
SELECT DISTINCT ${columnIdentifier} AS value
|
|
1381
|
-
FROM ${tableIdentifier}
|
|
1382
|
-
WHERE ${columnIdentifier} IS NOT NULL
|
|
1383
|
-
LIMIT ${limit}
|
|
1384
|
-
`;
|
|
1385
|
-
const rows = await this.#adapter.runQuery(sql);
|
|
1386
|
-
if (!rows.length || rows.length > this.lowCardinalityLimit) {
|
|
1387
|
-
return void 0;
|
|
1388
|
-
}
|
|
1389
|
-
const values = [];
|
|
1390
|
-
for (const row of rows) {
|
|
1391
|
-
const formatted = this.#normalizeValue(row.value);
|
|
1392
|
-
if (formatted == null) {
|
|
1393
|
-
return void 0;
|
|
1394
|
-
}
|
|
1395
|
-
values.push(formatted);
|
|
1396
|
-
}
|
|
1397
|
-
return values.length ? values : void 0;
|
|
1398
|
-
}
|
|
1399
|
-
#normalizeValue(value) {
|
|
1400
|
-
if (value === null || value === void 0) {
|
|
1401
|
-
return null;
|
|
1402
|
-
}
|
|
1403
|
-
if (typeof value === "string") {
|
|
1404
|
-
return value;
|
|
1405
|
-
}
|
|
1406
|
-
if (typeof value === "number" || typeof value === "bigint") {
|
|
1407
|
-
return String(value);
|
|
1408
|
-
}
|
|
1409
|
-
if (typeof value === "boolean") {
|
|
1410
|
-
return value ? "true" : "false";
|
|
1411
|
-
}
|
|
1412
|
-
if (value instanceof Date) {
|
|
1413
|
-
return value.toISOString();
|
|
1414
|
-
}
|
|
1415
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) {
|
|
1416
|
-
return value.toString("utf-8");
|
|
1417
|
-
}
|
|
1418
|
-
return null;
|
|
1419
|
-
}
|
|
1420
|
-
};
|
|
1421
|
-
|
|
1422
1319
|
// packages/text2sql/src/lib/adapters/sqlite/row-count.sqlite.grounding.ts
|
|
1423
1320
|
var SqliteRowCountGrounding = class extends RowCountGrounding {
|
|
1424
1321
|
#adapter;
|
|
@@ -1729,9 +1626,6 @@ function constraints(config = {}) {
|
|
|
1729
1626
|
return new SqliteConstraintGrounding(adapter, config);
|
|
1730
1627
|
};
|
|
1731
1628
|
}
|
|
1732
|
-
function report(config = {}) {
|
|
1733
|
-
return (adapter) => new ReportGrounding(adapter, config);
|
|
1734
|
-
}
|
|
1735
1629
|
var sqlite_default = {
|
|
1736
1630
|
tables,
|
|
1737
1631
|
info,
|
|
@@ -1741,7 +1635,6 @@ var sqlite_default = {
|
|
|
1741
1635
|
indexes,
|
|
1742
1636
|
rowCount,
|
|
1743
1637
|
constraints,
|
|
1744
|
-
report,
|
|
1745
1638
|
Sqlite
|
|
1746
1639
|
};
|
|
1747
1640
|
export {
|
|
@@ -1753,7 +1646,6 @@ export {
|
|
|
1753
1646
|
formatError,
|
|
1754
1647
|
indexes,
|
|
1755
1648
|
info,
|
|
1756
|
-
report,
|
|
1757
1649
|
rowCount,
|
|
1758
1650
|
tables,
|
|
1759
1651
|
views
|