@askdb/mysql 0.1.0-beta.1
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/LICENSE +201 -0
- package/README.md +60 -0
- package/dist/connector/describe.d.ts +78 -0
- package/dist/connector/describe.d.ts.map +1 -0
- package/dist/connector/describe.js +310 -0
- package/dist/connector/describe.js.map +1 -0
- package/dist/connector/glob.d.ts +3 -0
- package/dist/connector/glob.d.ts.map +1 -0
- package/dist/connector/glob.js +27 -0
- package/dist/connector/glob.js.map +1 -0
- package/dist/connector/ids.d.ts +9 -0
- package/dist/connector/ids.d.ts.map +1 -0
- package/dist/connector/ids.js +13 -0
- package/dist/connector/ids.js.map +1 -0
- package/dist/connector/index.d.ts +15 -0
- package/dist/connector/index.d.ts.map +1 -0
- package/dist/connector/index.js +10 -0
- package/dist/connector/index.js.map +1 -0
- package/dist/exec/mysql.d.ts +12 -0
- package/dist/exec/mysql.d.ts.map +1 -0
- package/dist/exec/mysql.js +54 -0
- package/dist/exec/mysql.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for, the acceptance of support, warranty, indemnity, or
|
|
168
|
+
other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Yahya Gilany
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# `@askdb/mysql`
|
|
2
|
+
|
|
3
|
+
MySQL / MariaDB integration for AskDB. Bundles three pieces:
|
|
4
|
+
|
|
5
|
+
1. **Dialect** — re-exports `MYSQL_DIALECT` and `MARIADB_DIALECT` from `@askdb/core`. Pass `dialect: MYSQL_DIALECT` (or `MARIADB_DIALECT`) to `ask()` to target MySQL or MariaDB.
|
|
6
|
+
2. **Connector** — `createMysqlConnector()` implements the `Connector` contract from `@askdb/introspect` for live introspection mode.
|
|
7
|
+
3. **Catalog runner** — `createMysqlCatalogQueryRunner(connectionString)` returns an introspection-only `CatalogQueryRunner` backed by `mysql2` (peer dependency, lazy-loaded).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @askdb/core @askdb/introspect @askdb/mysql
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`mysql2` is an **optional peer dependency** — install it only when using live introspection mode:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add mysql2
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### NL→SQL
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { ask, loadSchema } from "@askdb/core";
|
|
27
|
+
import { MYSQL_DIALECT } from "@askdb/mysql";
|
|
28
|
+
|
|
29
|
+
const schema = loadSchema("./my-app.schema");
|
|
30
|
+
|
|
31
|
+
const { sql } = await ask({
|
|
32
|
+
question: "How many paid orders were created last month?",
|
|
33
|
+
schema,
|
|
34
|
+
model,
|
|
35
|
+
dialect: MYSQL_DIALECT,
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Use `MARIADB_DIALECT` instead when your runtime engine is MariaDB.
|
|
40
|
+
|
|
41
|
+
### Introspection
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { introspect } from "@askdb/introspect";
|
|
45
|
+
import { createMysqlConnector, createMysqlCatalogQueryRunner } from "@askdb/mysql";
|
|
46
|
+
|
|
47
|
+
const result = await introspect(
|
|
48
|
+
{ mode: "live", runner: createMysqlCatalogQueryRunner(process.env.DATABASE_URL!) },
|
|
49
|
+
{ outDir: "./my-app.schema", schemaId: "my-app" },
|
|
50
|
+
{ connector: createMysqlConnector() },
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Captured metadata
|
|
55
|
+
|
|
56
|
+
Tables, views, columns (MySQL-native type strings), primary keys, unique constraints, foreign keys (with referential actions), and indexes.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
Apache-2.0
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CatalogQueryRunner, IntrospectionFilters, IntrospectionResult } from "@askdb/introspect";
|
|
2
|
+
import { compileTableFilters } from "./glob.js";
|
|
3
|
+
export type DescribeMysqlInput = {
|
|
4
|
+
runner: CatalogQueryRunner;
|
|
5
|
+
filters?: IntrospectionFilters;
|
|
6
|
+
/** Optional `schemaId` for the resulting `SqlSchema`. Defaults to `"introspected"`. */
|
|
7
|
+
schemaId?: string;
|
|
8
|
+
};
|
|
9
|
+
/** Internal: the catalog SQL strings, exposed for snapshot-based tests. */
|
|
10
|
+
export declare const MYSQL_CATALOG_SQL: {
|
|
11
|
+
readonly tables: "SELECT\n table_name AS table_name,\n table_type AS table_type,\n table_comment AS table_comment\nFROM information_schema.tables\nWHERE table_schema = DATABASE()\n AND table_type IN ('BASE TABLE', 'VIEW')\nORDER BY table_name";
|
|
12
|
+
readonly columns: "SELECT\n table_name AS table_name,\n column_name AS column_name,\n ordinal_position AS ordinal_position,\n column_default AS column_default,\n is_nullable AS is_nullable,\n data_type AS data_type,\n column_type AS column_type,\n column_key AS column_key,\n extra AS extra,\n column_comment AS column_comment\nFROM information_schema.columns\nWHERE table_schema = DATABASE()\nORDER BY table_name, ordinal_position";
|
|
13
|
+
readonly constraints: "SELECT\n tc.constraint_name AS constraint_name,\n tc.table_name AS table_name,\n kcu.column_name AS column_name,\n kcu.ordinal_position AS ordinal_position,\n tc.constraint_type AS constraint_type\nFROM information_schema.table_constraints tc\nJOIN information_schema.key_column_usage kcu\n ON kcu.constraint_schema = tc.constraint_schema\n AND kcu.constraint_name = tc.constraint_name\n AND kcu.table_name = tc.table_name\nWHERE tc.table_schema = DATABASE()\n AND tc.constraint_type IN ('PRIMARY KEY', 'UNIQUE')\nORDER BY tc.table_name, tc.constraint_name, kcu.ordinal_position";
|
|
14
|
+
readonly foreign_keys: "SELECT\n kcu.constraint_name AS constraint_name,\n kcu.table_name AS table_name,\n kcu.column_name AS column_name,\n kcu.referenced_table_name AS referenced_table_name,\n kcu.referenced_column_name AS referenced_column_name,\n kcu.ordinal_position AS ordinal_position,\n rc.update_rule AS update_rule,\n rc.delete_rule AS delete_rule\nFROM information_schema.key_column_usage kcu\nJOIN information_schema.referential_constraints rc\n ON rc.constraint_schema = kcu.constraint_schema\n AND rc.constraint_name = kcu.constraint_name\nWHERE kcu.table_schema = DATABASE()\n AND kcu.referenced_table_name IS NOT NULL\nORDER BY kcu.table_name, kcu.constraint_name, kcu.ordinal_position";
|
|
15
|
+
readonly indexes: "SELECT\n table_name AS table_name,\n index_name AS index_name,\n column_name AS column_name,\n seq_in_index AS seq_in_index,\n non_unique AS non_unique,\n index_type AS index_type\nFROM information_schema.statistics\nWHERE table_schema = DATABASE()\n AND index_name <> 'PRIMARY'\nORDER BY table_name, index_name, seq_in_index";
|
|
16
|
+
readonly views: "SELECT\n table_name AS table_name,\n view_definition AS view_definition\nFROM information_schema.views\nWHERE table_schema = DATABASE()\nORDER BY table_name";
|
|
17
|
+
};
|
|
18
|
+
type TableRow = {
|
|
19
|
+
table_name: string;
|
|
20
|
+
table_type: "BASE TABLE" | "VIEW" | string;
|
|
21
|
+
table_comment: string | null;
|
|
22
|
+
};
|
|
23
|
+
type ColumnRow = {
|
|
24
|
+
table_name: string;
|
|
25
|
+
column_name: string;
|
|
26
|
+
ordinal_position: number;
|
|
27
|
+
column_default: string | null;
|
|
28
|
+
is_nullable: "YES" | "NO" | string;
|
|
29
|
+
data_type: string;
|
|
30
|
+
column_type: string;
|
|
31
|
+
column_key: "PRI" | "UNI" | "MUL" | "" | string;
|
|
32
|
+
extra: string | null;
|
|
33
|
+
column_comment: string | null;
|
|
34
|
+
};
|
|
35
|
+
type ConstraintRow = {
|
|
36
|
+
constraint_name: string;
|
|
37
|
+
table_name: string;
|
|
38
|
+
column_name: string;
|
|
39
|
+
ordinal_position: number;
|
|
40
|
+
constraint_type: "PRIMARY KEY" | "UNIQUE" | string;
|
|
41
|
+
};
|
|
42
|
+
type ForeignKeyRow = {
|
|
43
|
+
constraint_name: string;
|
|
44
|
+
table_name: string;
|
|
45
|
+
column_name: string;
|
|
46
|
+
referenced_table_name: string;
|
|
47
|
+
referenced_column_name: string;
|
|
48
|
+
ordinal_position: number;
|
|
49
|
+
update_rule: string | null;
|
|
50
|
+
delete_rule: string | null;
|
|
51
|
+
};
|
|
52
|
+
type IndexRow = {
|
|
53
|
+
table_name: string;
|
|
54
|
+
index_name: string;
|
|
55
|
+
column_name: string | null;
|
|
56
|
+
seq_in_index: number;
|
|
57
|
+
non_unique: number;
|
|
58
|
+
index_type: string;
|
|
59
|
+
};
|
|
60
|
+
type ViewRow = {
|
|
61
|
+
table_name: string;
|
|
62
|
+
view_definition: string | null;
|
|
63
|
+
};
|
|
64
|
+
export declare function describeMysql(input: DescribeMysqlInput): Promise<IntrospectionResult>;
|
|
65
|
+
type FoldInput = {
|
|
66
|
+
schemaId: string;
|
|
67
|
+
tableFilter: ReturnType<typeof compileTableFilters>;
|
|
68
|
+
tableRows: TableRow[];
|
|
69
|
+
columnRows: ColumnRow[];
|
|
70
|
+
constraintRows: ConstraintRow[];
|
|
71
|
+
fkRows: ForeignKeyRow[];
|
|
72
|
+
indexRows: IndexRow[];
|
|
73
|
+
viewRows: ViewRow[];
|
|
74
|
+
declaredFilters: ReadonlyArray<string>;
|
|
75
|
+
};
|
|
76
|
+
export declare function foldMysqlResult(input: FoldInput): IntrospectionResult;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=describe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { compileTableFilters } from "./glob.js";
|
|
2
|
+
import { makeColumnId, makeTableId } from "./ids.js";
|
|
3
|
+
/**
|
|
4
|
+
* MySQL doesn't have Postgres-style schemas (each "schema" is a database).
|
|
5
|
+
* Hosts pick a database via the connection string; the connector emits its
|
|
6
|
+
* contents under a single namespace named `"public"` to match `@askdb/prisma`'s
|
|
7
|
+
* convention and keep table ids cross-engine stable.
|
|
8
|
+
*/
|
|
9
|
+
const NAMESPACE = "public";
|
|
10
|
+
// information_schema is well-documented; pinning the SQL inside the package
|
|
11
|
+
// keeps the surface stable. Each query restricts to `DATABASE()` so the runner's
|
|
12
|
+
// connection-bound database is the implicit filter.
|
|
13
|
+
const SQL_TABLES = `SELECT
|
|
14
|
+
table_name AS table_name,
|
|
15
|
+
table_type AS table_type,
|
|
16
|
+
table_comment AS table_comment
|
|
17
|
+
FROM information_schema.tables
|
|
18
|
+
WHERE table_schema = DATABASE()
|
|
19
|
+
AND table_type IN ('BASE TABLE', 'VIEW')
|
|
20
|
+
ORDER BY table_name`;
|
|
21
|
+
const SQL_COLUMNS = `SELECT
|
|
22
|
+
table_name AS table_name,
|
|
23
|
+
column_name AS column_name,
|
|
24
|
+
ordinal_position AS ordinal_position,
|
|
25
|
+
column_default AS column_default,
|
|
26
|
+
is_nullable AS is_nullable,
|
|
27
|
+
data_type AS data_type,
|
|
28
|
+
column_type AS column_type,
|
|
29
|
+
column_key AS column_key,
|
|
30
|
+
extra AS extra,
|
|
31
|
+
column_comment AS column_comment
|
|
32
|
+
FROM information_schema.columns
|
|
33
|
+
WHERE table_schema = DATABASE()
|
|
34
|
+
ORDER BY table_name, ordinal_position`;
|
|
35
|
+
const SQL_CONSTRAINTS = `SELECT
|
|
36
|
+
tc.constraint_name AS constraint_name,
|
|
37
|
+
tc.table_name AS table_name,
|
|
38
|
+
kcu.column_name AS column_name,
|
|
39
|
+
kcu.ordinal_position AS ordinal_position,
|
|
40
|
+
tc.constraint_type AS constraint_type
|
|
41
|
+
FROM information_schema.table_constraints tc
|
|
42
|
+
JOIN information_schema.key_column_usage kcu
|
|
43
|
+
ON kcu.constraint_schema = tc.constraint_schema
|
|
44
|
+
AND kcu.constraint_name = tc.constraint_name
|
|
45
|
+
AND kcu.table_name = tc.table_name
|
|
46
|
+
WHERE tc.table_schema = DATABASE()
|
|
47
|
+
AND tc.constraint_type IN ('PRIMARY KEY', 'UNIQUE')
|
|
48
|
+
ORDER BY tc.table_name, tc.constraint_name, kcu.ordinal_position`;
|
|
49
|
+
const SQL_FOREIGN_KEYS = `SELECT
|
|
50
|
+
kcu.constraint_name AS constraint_name,
|
|
51
|
+
kcu.table_name AS table_name,
|
|
52
|
+
kcu.column_name AS column_name,
|
|
53
|
+
kcu.referenced_table_name AS referenced_table_name,
|
|
54
|
+
kcu.referenced_column_name AS referenced_column_name,
|
|
55
|
+
kcu.ordinal_position AS ordinal_position,
|
|
56
|
+
rc.update_rule AS update_rule,
|
|
57
|
+
rc.delete_rule AS delete_rule
|
|
58
|
+
FROM information_schema.key_column_usage kcu
|
|
59
|
+
JOIN information_schema.referential_constraints rc
|
|
60
|
+
ON rc.constraint_schema = kcu.constraint_schema
|
|
61
|
+
AND rc.constraint_name = kcu.constraint_name
|
|
62
|
+
WHERE kcu.table_schema = DATABASE()
|
|
63
|
+
AND kcu.referenced_table_name IS NOT NULL
|
|
64
|
+
ORDER BY kcu.table_name, kcu.constraint_name, kcu.ordinal_position`;
|
|
65
|
+
const SQL_INDEXES = `SELECT
|
|
66
|
+
table_name AS table_name,
|
|
67
|
+
index_name AS index_name,
|
|
68
|
+
column_name AS column_name,
|
|
69
|
+
seq_in_index AS seq_in_index,
|
|
70
|
+
non_unique AS non_unique,
|
|
71
|
+
index_type AS index_type
|
|
72
|
+
FROM information_schema.statistics
|
|
73
|
+
WHERE table_schema = DATABASE()
|
|
74
|
+
AND index_name <> 'PRIMARY'
|
|
75
|
+
ORDER BY table_name, index_name, seq_in_index`;
|
|
76
|
+
const SQL_VIEWS = `SELECT
|
|
77
|
+
table_name AS table_name,
|
|
78
|
+
view_definition AS view_definition
|
|
79
|
+
FROM information_schema.views
|
|
80
|
+
WHERE table_schema = DATABASE()
|
|
81
|
+
ORDER BY table_name`;
|
|
82
|
+
/** Internal: the catalog SQL strings, exposed for snapshot-based tests. */
|
|
83
|
+
export const MYSQL_CATALOG_SQL = {
|
|
84
|
+
tables: SQL_TABLES,
|
|
85
|
+
columns: SQL_COLUMNS,
|
|
86
|
+
constraints: SQL_CONSTRAINTS,
|
|
87
|
+
foreign_keys: SQL_FOREIGN_KEYS,
|
|
88
|
+
indexes: SQL_INDEXES,
|
|
89
|
+
views: SQL_VIEWS,
|
|
90
|
+
};
|
|
91
|
+
export async function describeMysql(input) {
|
|
92
|
+
const runner = input.runner;
|
|
93
|
+
const tableFilter = compileTableFilters(input.filters?.tables);
|
|
94
|
+
const run = async (sql) => {
|
|
95
|
+
const result = await runner(sql);
|
|
96
|
+
if (result.rows.length === 0)
|
|
97
|
+
return [];
|
|
98
|
+
const idx = new Map();
|
|
99
|
+
for (let i = 0; i < result.columns.length; i++)
|
|
100
|
+
idx.set(result.columns[i], i);
|
|
101
|
+
return result.rows.map((row) => {
|
|
102
|
+
const record = {};
|
|
103
|
+
for (const [name, i] of idx)
|
|
104
|
+
record[name] = row[i];
|
|
105
|
+
return record;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const [tableRows, columnRows, constraintRows, fkRows, indexRows, viewRows] = await Promise.all([
|
|
109
|
+
run(SQL_TABLES),
|
|
110
|
+
run(SQL_COLUMNS),
|
|
111
|
+
run(SQL_CONSTRAINTS),
|
|
112
|
+
run(SQL_FOREIGN_KEYS),
|
|
113
|
+
run(SQL_INDEXES),
|
|
114
|
+
run(SQL_VIEWS),
|
|
115
|
+
]);
|
|
116
|
+
return foldMysqlResult({
|
|
117
|
+
schemaId: input.schemaId ?? "introspected",
|
|
118
|
+
tableFilter,
|
|
119
|
+
tableRows,
|
|
120
|
+
columnRows,
|
|
121
|
+
constraintRows,
|
|
122
|
+
fkRows,
|
|
123
|
+
indexRows,
|
|
124
|
+
viewRows,
|
|
125
|
+
declaredFilters: input.filters?.tables ?? [],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export function foldMysqlResult(input) {
|
|
129
|
+
const warnings = [];
|
|
130
|
+
const columnsByTable = groupBy(input.columnRows, (r) => r.table_name);
|
|
131
|
+
const constraintsByTable = groupBy(input.constraintRows, (r) => r.table_name);
|
|
132
|
+
const fksByTable = groupBy(input.fkRows, (r) => r.table_name);
|
|
133
|
+
const indexesByTable = groupBy(input.indexRows, (r) => r.table_name);
|
|
134
|
+
const viewDefByName = new Map();
|
|
135
|
+
for (const v of input.viewRows) {
|
|
136
|
+
if (v.view_definition)
|
|
137
|
+
viewDefByName.set(v.table_name, v.view_definition);
|
|
138
|
+
}
|
|
139
|
+
const tables = [];
|
|
140
|
+
const views = [];
|
|
141
|
+
const viewDefinitions = {};
|
|
142
|
+
for (const t of input.tableRows) {
|
|
143
|
+
const qualified = `${NAMESPACE}.${t.table_name}`;
|
|
144
|
+
if (!input.tableFilter(qualified))
|
|
145
|
+
continue;
|
|
146
|
+
const cols = (columnsByTable.get(t.table_name) ?? [])
|
|
147
|
+
.slice()
|
|
148
|
+
.sort((a, b) => a.ordinal_position - b.ordinal_position);
|
|
149
|
+
const constraints = constraintsByTable.get(t.table_name) ?? [];
|
|
150
|
+
const pkRows = constraints
|
|
151
|
+
.filter((c) => c.constraint_type === "PRIMARY KEY")
|
|
152
|
+
.sort((a, b) => a.ordinal_position - b.ordinal_position);
|
|
153
|
+
const pkColumns = pkRows.map((r) => r.column_name);
|
|
154
|
+
const pkSet = new Set(pkColumns);
|
|
155
|
+
const columns = cols.map((c) => buildColumn(t.table_name, c, pkSet));
|
|
156
|
+
if (t.table_type === "VIEW") {
|
|
157
|
+
const def = viewDefByName.get(t.table_name) ?? "";
|
|
158
|
+
const view = {
|
|
159
|
+
schema: NAMESPACE,
|
|
160
|
+
name: t.table_name,
|
|
161
|
+
definition: def,
|
|
162
|
+
columns,
|
|
163
|
+
};
|
|
164
|
+
views.push(view);
|
|
165
|
+
viewDefinitions[makeTableId(NAMESPACE, t.table_name)] = def;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
tables.push({
|
|
169
|
+
id: makeTableId(NAMESPACE, t.table_name),
|
|
170
|
+
schema: NAMESPACE,
|
|
171
|
+
name: t.table_name,
|
|
172
|
+
comment: t.table_comment ?? undefined,
|
|
173
|
+
columns,
|
|
174
|
+
primaryKey: pkColumns.length > 0 ? { columns: pkColumns } : undefined,
|
|
175
|
+
foreignKeys: buildForeignKeys(fksByTable.get(t.table_name) ?? []),
|
|
176
|
+
uniqueConstraints: buildUniques(constraints),
|
|
177
|
+
indexes: buildIndexes(indexesByTable.get(t.table_name) ?? []),
|
|
178
|
+
checkConstraints: [],
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// Sort for deterministic output.
|
|
182
|
+
tables.sort(byName);
|
|
183
|
+
views.sort(byName);
|
|
184
|
+
const namespace = {
|
|
185
|
+
name: NAMESPACE,
|
|
186
|
+
tables,
|
|
187
|
+
views,
|
|
188
|
+
enums: [],
|
|
189
|
+
sequences: [],
|
|
190
|
+
};
|
|
191
|
+
const isEmpty = tables.length === 0 && views.length === 0;
|
|
192
|
+
for (const pattern of input.declaredFilters) {
|
|
193
|
+
const matched = tables.some((t) => compileTableFilters([pattern])(`${NAMESPACE}.${t.name}`)) ||
|
|
194
|
+
views.some((v) => compileTableFilters([pattern])(`${NAMESPACE}.${v.name}`));
|
|
195
|
+
if (!matched)
|
|
196
|
+
warnings.push({ code: "ambiguous_filter", filter: pattern });
|
|
197
|
+
}
|
|
198
|
+
const schema = {
|
|
199
|
+
schemaId: input.schemaId,
|
|
200
|
+
schemas: isEmpty ? [] : [namespace],
|
|
201
|
+
};
|
|
202
|
+
return { schema, warnings, isEmpty, viewDefinitions, provider: "mysql" };
|
|
203
|
+
}
|
|
204
|
+
function buildColumn(table, c, pkSet) {
|
|
205
|
+
// `column_type` carries width/unsigned/enum-values info (e.g. `enum('a','b')`,
|
|
206
|
+
// `int(10) unsigned`); `data_type` is the bare type. Prefer `column_type` for
|
|
207
|
+
// accuracy in the NL→SQL prompt, fall back to `data_type`.
|
|
208
|
+
const dataType = c.column_type ?? c.data_type;
|
|
209
|
+
return {
|
|
210
|
+
id: makeColumnId(NAMESPACE, table, c.column_name),
|
|
211
|
+
name: c.column_name,
|
|
212
|
+
ordinalPosition: c.ordinal_position,
|
|
213
|
+
dataType,
|
|
214
|
+
udtName: c.data_type,
|
|
215
|
+
nullable: c.is_nullable === "YES",
|
|
216
|
+
primaryKey: pkSet.has(c.column_name) || c.column_key === "PRI",
|
|
217
|
+
defaultExpression: c.column_default ?? undefined,
|
|
218
|
+
comment: c.column_comment || undefined,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function buildUniques(constraints) {
|
|
222
|
+
const byName = new Map();
|
|
223
|
+
for (const c of constraints) {
|
|
224
|
+
if (c.constraint_type !== "UNIQUE")
|
|
225
|
+
continue;
|
|
226
|
+
const list = byName.get(c.constraint_name) ?? [];
|
|
227
|
+
list.push(c);
|
|
228
|
+
byName.set(c.constraint_name, list);
|
|
229
|
+
}
|
|
230
|
+
return Array.from(byName, ([name, list]) => ({
|
|
231
|
+
name,
|
|
232
|
+
columns: list
|
|
233
|
+
.slice()
|
|
234
|
+
.sort((a, b) => a.ordinal_position - b.ordinal_position)
|
|
235
|
+
.map((r) => r.column_name),
|
|
236
|
+
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
237
|
+
}
|
|
238
|
+
function buildForeignKeys(rows) {
|
|
239
|
+
const byName = new Map();
|
|
240
|
+
for (const r of rows) {
|
|
241
|
+
const list = byName.get(r.constraint_name) ?? [];
|
|
242
|
+
list.push(r);
|
|
243
|
+
byName.set(r.constraint_name, list);
|
|
244
|
+
}
|
|
245
|
+
const fks = [];
|
|
246
|
+
for (const [name, list] of byName) {
|
|
247
|
+
const ordered = list.slice().sort((a, b) => a.ordinal_position - b.ordinal_position);
|
|
248
|
+
const sample = ordered[0];
|
|
249
|
+
fks.push({
|
|
250
|
+
name,
|
|
251
|
+
columns: ordered.map((r) => r.column_name),
|
|
252
|
+
references: {
|
|
253
|
+
schema: NAMESPACE,
|
|
254
|
+
table: sample.referenced_table_name,
|
|
255
|
+
columns: ordered.map((r) => r.referenced_column_name),
|
|
256
|
+
},
|
|
257
|
+
onDelete: mapAction(sample.delete_rule),
|
|
258
|
+
onUpdate: mapAction(sample.update_rule),
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return fks.sort((a, b) => a.name.localeCompare(b.name));
|
|
262
|
+
}
|
|
263
|
+
function mapAction(rule) {
|
|
264
|
+
if (!rule)
|
|
265
|
+
return undefined;
|
|
266
|
+
const r = rule.toLowerCase();
|
|
267
|
+
if (r === "cascade")
|
|
268
|
+
return "cascade";
|
|
269
|
+
if (r === "restrict")
|
|
270
|
+
return "restrict";
|
|
271
|
+
if (r === "set null")
|
|
272
|
+
return "set null";
|
|
273
|
+
if (r === "set default")
|
|
274
|
+
return "set default";
|
|
275
|
+
if (r === "no action")
|
|
276
|
+
return "no action";
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
function buildIndexes(rows) {
|
|
280
|
+
const byName = new Map();
|
|
281
|
+
for (const r of rows) {
|
|
282
|
+
const list = byName.get(r.index_name) ?? [];
|
|
283
|
+
list.push(r);
|
|
284
|
+
byName.set(r.index_name, list);
|
|
285
|
+
}
|
|
286
|
+
return Array.from(byName, ([name, list]) => {
|
|
287
|
+
const ordered = list.slice().sort((a, b) => a.seq_in_index - b.seq_in_index);
|
|
288
|
+
const sample = ordered[0];
|
|
289
|
+
return {
|
|
290
|
+
name,
|
|
291
|
+
columns: ordered.map((r) => r.column_name ?? ""),
|
|
292
|
+
unique: sample.non_unique === 0,
|
|
293
|
+
method: sample.index_type,
|
|
294
|
+
};
|
|
295
|
+
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
296
|
+
}
|
|
297
|
+
function groupBy(rows, key) {
|
|
298
|
+
const out = new Map();
|
|
299
|
+
for (const row of rows) {
|
|
300
|
+
const k = key(row);
|
|
301
|
+
const list = out.get(k) ?? [];
|
|
302
|
+
list.push(row);
|
|
303
|
+
out.set(k, list);
|
|
304
|
+
}
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
function byName(a, b) {
|
|
308
|
+
return a.name.localeCompare(b.name);
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=describe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.js","sourceRoot":"","sources":["../../src/connector/describe.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErD;;;;;GAKG;AACH,MAAM,SAAS,GAAG,QAAQ,CAAC;AAS3B,4EAA4E;AAC5E,iFAAiF;AACjF,oDAAoD;AACpD,MAAM,UAAU,GAAG;;;;;;;oBAOC,CAAC;AAErB,MAAM,WAAW,GAAG;;;;;;;;;;;;;sCAakB,CAAC;AAEvC,MAAM,eAAe,GAAG;;;;;;;;;;;;;iEAayC,CAAC;AAElE,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;mEAe0C,CAAC;AAEpE,MAAM,WAAW,GAAG;;;;;;;;;;8CAU0B,CAAC;AAE/C,MAAM,SAAS,GAAG;;;;;oBAKE,CAAC;AAErB,2EAA2E;AAC3E,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,WAAW;IACpB,WAAW,EAAE,eAAe;IAC5B,YAAY,EAAE,gBAAgB;IAC9B,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,SAAS;CACR,CAAC;AAiDX,MAAM,CAAC,KAAK,UAA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AAK,CAAC;YAC/B,MAAM,EAAE,MAAM,CAAC,UAAU;SACP,CAAC;IACvB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,OAAO,CAAO,IAAS,EAAE,GAAkB;IAClD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,MAAM,CAA6B,CAAI,EAAE,CAAI;IACpD,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/connector/glob.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC;AAE7D,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,GAC1C,WAAW,CAIb"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal glob matcher for `IntrospectionFilters.tables`. Matches against
|
|
3
|
+
* `"<schema>.<name>"` strings; supports `*` (any run) and `?` (single char).
|
|
4
|
+
* Identical to the postgres connector's matcher.
|
|
5
|
+
*/
|
|
6
|
+
function compileGlob(pattern) {
|
|
7
|
+
let out = "^";
|
|
8
|
+
for (const ch of pattern) {
|
|
9
|
+
if (ch === "*")
|
|
10
|
+
out += ".*";
|
|
11
|
+
else if (ch === "?")
|
|
12
|
+
out += ".";
|
|
13
|
+
else if (/[.+^${}()|[\]\\]/.test(ch))
|
|
14
|
+
out += "\\" + ch;
|
|
15
|
+
else
|
|
16
|
+
out += ch;
|
|
17
|
+
}
|
|
18
|
+
out += "$";
|
|
19
|
+
return new RegExp(out);
|
|
20
|
+
}
|
|
21
|
+
export function compileTableFilters(patterns) {
|
|
22
|
+
if (!patterns || patterns.length === 0)
|
|
23
|
+
return () => true;
|
|
24
|
+
const compiled = patterns.map(compileGlob);
|
|
25
|
+
return (qualifiedName) => compiled.some((re) => re.test(qualifiedName));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=glob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../src/connector/glob.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,SAAS,WAAW,CAAC,OAAe;IAClC,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACzB,IAAI,EAAE,KAAK,GAAG;YAAE,GAAG,IAAI,IAAI,CAAC;aACvB,IAAI,EAAE,KAAK,GAAG;YAAE,GAAG,IAAI,GAAG,CAAC;aAC3B,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;;YAClD,GAAG,IAAI,EAAE,CAAC;IACjB,CAAC;IACD,GAAG,IAAI,GAAG,CAAC;IACX,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAID,MAAM,UAAU,mBAAmB,CACjC,QAA2C;IAE3C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC;IAC1D,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema v2 ID conventions — kept aligned with `@askdb/postgres/connector/ids.ts`.
|
|
3
|
+
* MySQL doesn't have Postgres-style schemas, but to keep IDs stable and
|
|
4
|
+
* cross-engine queryable we always use the namespace `"public"` (the same
|
|
5
|
+
* convention `@askdb/prisma` uses for MySQL).
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeTableId(schemaName: string, tableName: string): string;
|
|
8
|
+
export declare function makeColumnId(schemaName: string, tableName: string, columnName: string): string;
|
|
9
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/connector/ids.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema v2 ID conventions — kept aligned with `@askdb/postgres/connector/ids.ts`.
|
|
3
|
+
* MySQL doesn't have Postgres-style schemas, but to keep IDs stable and
|
|
4
|
+
* cross-engine queryable we always use the namespace `"public"` (the same
|
|
5
|
+
* convention `@askdb/prisma` uses for MySQL).
|
|
6
|
+
*/
|
|
7
|
+
export function makeTableId(schemaName, tableName) {
|
|
8
|
+
return `table:${schemaName}.${tableName}`;
|
|
9
|
+
}
|
|
10
|
+
export function makeColumnId(schemaName, tableName, columnName) {
|
|
11
|
+
return `table:${schemaName}.${tableName}#${columnName}`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/connector/ids.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,UAAkB,EAAE,SAAiB;IAC/D,OAAO,SAAS,UAAU,IAAI,SAAS,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,UAAkB,EAClB,SAAiB,EACjB,UAAkB;IAElB,OAAO,SAAS,UAAU,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CatalogQueryRunner, Connector, IntrospectionFilters } from "@askdb/introspect";
|
|
2
|
+
/**
|
|
3
|
+
* Connector input for `@askdb/mysql`. Live introspection only — supply a
|
|
4
|
+
* `CatalogQueryRunner` (e.g. from {@link createMysqlCatalogQueryRunner}).
|
|
5
|
+
* From-export bundle mode (à la `@askdb/postgres`) is not implemented here yet.
|
|
6
|
+
*/
|
|
7
|
+
export type MysqlIntrospectionInput = {
|
|
8
|
+
mode: "live";
|
|
9
|
+
runner: CatalogQueryRunner;
|
|
10
|
+
filters?: IntrospectionFilters;
|
|
11
|
+
};
|
|
12
|
+
export declare function createMysqlConnector(): Connector<MysqlIntrospectionInput>;
|
|
13
|
+
export { describeMysql, MYSQL_CATALOG_SQL } from "./describe.js";
|
|
14
|
+
export type { DescribeMysqlInput } from "./describe.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EAErB,MAAM,mBAAmB,CAAC;AAG3B;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC;AAEF,wBAAgB,oBAAoB,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAMzE;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describeMysql } from "./describe.js";
|
|
2
|
+
export function createMysqlConnector() {
|
|
3
|
+
return {
|
|
4
|
+
async describe(input) {
|
|
5
|
+
return describeMysql({ runner: input.runner, filters: input.filters });
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export { describeMysql, MYSQL_CATALOG_SQL } from "./describe.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAa9C,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,KAAK,CAAC,QAAQ,CAAC,KAA8B;YAC3C,OAAO,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACzE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CatalogQueryRunner } from "@askdb/introspect";
|
|
2
|
+
export type { CatalogQueryResult, CatalogQueryRunner } from "@askdb/introspect";
|
|
3
|
+
/** @internal exposed for tests that need to reset the lazy `mysql2` cache. */
|
|
4
|
+
export declare function __resetMysql2ModuleCacheForTests(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Build the built-in `mysql2`-backed catalog query runner used by live MySQL
|
|
7
|
+
* introspection. The connection string follows the standard MySQL URI form
|
|
8
|
+
* (`mysql://user:pass@host:port/database`); the named database is the target
|
|
9
|
+
* namespace for introspection.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createMysqlCatalogQueryRunner(connectionString: string): CatalogQueryRunner;
|
|
12
|
+
//# sourceMappingURL=mysql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/exec/mysql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEhF,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAuBhF,8EAA8E;AAC9E,wBAAgB,gCAAgC,IAAI,IAAI,CAEvD;AA8BD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,gBAAgB,EAAE,MAAM,GAAG,kBAAkB,CAE1F"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AskDbError } from "@askdb/core";
|
|
2
|
+
/**
|
|
3
|
+
* Lazily resolve the optional `mysql2` peer dependency. Mirrors the pattern in
|
|
4
|
+
* `@askdb/postgres` so consumers with a custom `CatalogQueryRunner` can use
|
|
5
|
+
* `@askdb/mysql` without installing `mysql2`.
|
|
6
|
+
*/
|
|
7
|
+
let mysql2ModulePromise;
|
|
8
|
+
async function loadMysql2OrThrow() {
|
|
9
|
+
if (!mysql2ModulePromise) {
|
|
10
|
+
mysql2ModulePromise = import("mysql2/promise").catch((cause) => {
|
|
11
|
+
mysql2ModulePromise = undefined;
|
|
12
|
+
throw new AskDbError("The built-in MySQL catalog query runner requires the optional `mysql2` peer dependency. " +
|
|
13
|
+
"Install it (e.g. `pnpm add mysql2`) or pass a custom catalog query runner to the MySQL connector.", cause);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return mysql2ModulePromise;
|
|
17
|
+
}
|
|
18
|
+
/** @internal exposed for tests that need to reset the lazy `mysql2` cache. */
|
|
19
|
+
export function __resetMysql2ModuleCacheForTests() {
|
|
20
|
+
mysql2ModulePromise = undefined;
|
|
21
|
+
}
|
|
22
|
+
async function runMysqlCatalogQuery(connectionString, sql, params) {
|
|
23
|
+
const mod = await loadMysql2OrThrow();
|
|
24
|
+
const mysql = mod.default ?? mod;
|
|
25
|
+
const connection = await mysql.createConnection(connectionString);
|
|
26
|
+
try {
|
|
27
|
+
// information_schema is read-only by construction; we still force-disable
|
|
28
|
+
// the multi-statement protocol via mysql2 defaults and don't open a tx.
|
|
29
|
+
const [rows, fields] = (await connection.query(sql, params ? params : undefined));
|
|
30
|
+
const columns = (fields ?? []).map((f) => f.name);
|
|
31
|
+
const rowList = Array.isArray(rows) ? rows : [];
|
|
32
|
+
const data = rowList.map((row) => columns.map((c) => row[c] ?? null));
|
|
33
|
+
return { columns, rows: data };
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
if (e instanceof AskDbError)
|
|
37
|
+
throw e;
|
|
38
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
39
|
+
throw new AskDbError(`MySQL catalog query failed: ${message}`, e);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await connection.end();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build the built-in `mysql2`-backed catalog query runner used by live MySQL
|
|
47
|
+
* introspection. The connection string follows the standard MySQL URI form
|
|
48
|
+
* (`mysql://user:pass@host:port/database`); the named database is the target
|
|
49
|
+
* namespace for introspection.
|
|
50
|
+
*/
|
|
51
|
+
export function createMysqlCatalogQueryRunner(connectionString) {
|
|
52
|
+
return (sql, params) => runMysqlCatalogQuery(connectionString, sql, params);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=mysql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.js","sourceRoot":"","sources":["../../src/exec/mysql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC;;;;GAIG;AACH,IAAI,mBAAyE,CAAC;AAE9E,KAAK,UAAU,iBAAiB;IAC9B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,mBAAmB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAC7D,mBAAmB,GAAG,SAAS,CAAC;YAChC,MAAM,IAAI,UAAU,CAClB,0FAA0F;gBACxF,mGAAmG,EACrG,KAAK,CACN,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,gCAAgC;IAC9C,mBAAmB,GAAG,SAAS,CAAC;AAClC,CAAC;AAED,KAAK,UAAU,oBAAoB,CACjC,gBAAwB,EACxB,GAAW,EACX,MAA+B;IAE/B,MAAM,GAAG,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACtC,MAAM,KAAK,GAAI,GAA2C,CAAC,OAAO,IAAI,GAAG,CAAC;IAC1E,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAClE,IAAI,CAAC;QACH,0EAA0E;QAC1E,wEAAwE;QACxE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,UAAU,CAAC,KAAK,CAC5C,GAAG,EACH,MAAM,CAAC,CAAC,CAAE,MAAoB,CAAC,CAAC,CAAC,SAAS,CAC3C,CAA8D,CAAC;QA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DIALECT`) from `@askdb/core`. This
|
|
5
|
+
* package ships only the introspection connector and the `mysql2`-backed
|
|
6
|
+
* catalog runner; the NL→SQL prompt + validator live in `@askdb/core`.
|
|
7
|
+
*/
|
|
8
|
+
export { MYSQL_DIALECT, MARIADB_DIALECT, type DialectSpec as MysqlDialect, } from "@askdb/core";
|
|
9
|
+
export { createMysqlConnector, describeMysql, MYSQL_CATALOG_SQL, type DescribeMysqlInput, type MysqlIntrospectionInput, } from "./connector/index.js";
|
|
10
|
+
export { createMysqlCatalogQueryRunner, type CatalogQueryResult, type CatalogQueryRunner, } from "./exec/mysql.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,aAAa,EACb,eAAe,EACf,KAAK,WAAW,IAAI,YAAY,GACjC,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,6BAA6B,EAC7B,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@askdb/mysql` — MySQL/MariaDB integration for AskDB.
|
|
3
|
+
*
|
|
4
|
+
* Pairs with `MYSQL_DIALECT` (or `MARIADB_DIALECT`) from `@askdb/core`. This
|
|
5
|
+
* package ships only the introspection connector and the `mysql2`-backed
|
|
6
|
+
* catalog runner; the NL→SQL prompt + validator live in `@askdb/core`.
|
|
7
|
+
*/
|
|
8
|
+
export { MYSQL_DIALECT, MARIADB_DIALECT, } from "@askdb/core";
|
|
9
|
+
export { createMysqlConnector, describeMysql, MYSQL_CATALOG_SQL, } from "./connector/index.js";
|
|
10
|
+
export { createMysqlCatalogQueryRunner, } from "./exec/mysql.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,aAAa,EACb,eAAe,GAEhB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GAGlB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,6BAA6B,GAG9B,MAAM,iBAAiB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@askdb/mysql",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "AskDB MySQL integration: introspection connector via information_schema and a mysql2-backed catalog query runner. Pairs with @askdb/core's MYSQL_DIALECT.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"askdb",
|
|
7
|
+
"mysql",
|
|
8
|
+
"mariadb",
|
|
9
|
+
"nl-to-sql",
|
|
10
|
+
"natural-language-to-sql",
|
|
11
|
+
"schema-v2",
|
|
12
|
+
"introspection",
|
|
13
|
+
"information-schema"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/Ygilany/AskDB#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Ygilany/AskDB/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Ygilany/AskDB.git",
|
|
22
|
+
"directory": "packages/mysql"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"author": "Yahya Gilany",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"NOTICE"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@askdb/core": "0.5.0-beta.4",
|
|
46
|
+
"@askdb/introspect": "0.3.0-beta.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"mysql2": ">=3"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"mysql2": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"mysql2": "^3.11.5",
|
|
58
|
+
"typescript": "^5.7.3",
|
|
59
|
+
"vitest": "^3.0.9"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc -p tsconfig.build.json",
|
|
63
|
+
"lint": "tsc -p tsconfig.build.json --noEmit",
|
|
64
|
+
"test": "vitest run --config ../../vitest.config.ts"
|
|
65
|
+
}
|
|
66
|
+
}
|