Skip to content

Commit 5482125

Browse files
committed
Resolve schemas
Signed-off-by: worksofliam <[email protected]>
1 parent d9f61a2 commit 5482125

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/aiProviders/context.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,20 @@ export async function getSqlContextItems(input: string): Promise<ContextDefiniti
204204
const contextItems = (await Promise.all(
205205
allObjects.map(async (o) => {
206206
try {
207-
const content = await Schemas.generateSQL(o.schema, o.name, o.sqlType);
207+
if (o.sqlType === `SCHEMA`) {
208+
// TODO: maybe we want to include info about a schema here?
209+
return undefined;
210+
211+
} else {
212+
const content = await Schemas.generateSQL(o.schema, o.name, o.sqlType);
208213

209-
return {
210-
id: o.name,
211-
type: o.sqlType,
212-
content: content,
214+
return {
215+
id: o.name,
216+
type: o.sqlType,
217+
content: content,
218+
}
213219
}
220+
214221
} catch (e) {
215222
return undefined;
216223
}

src/database/schemas.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ function getFilterClause(againstColumn: string, filter: string, noAnd?: boolean)
4646
};
4747
}
4848

49+
const BASE_RESOLVE_SELECT = [
50+
`select `,
51+
`OBJLONGNAME as name, `,
52+
`OBJLONGSCHEMA as schema, `,
53+
`case `,
54+
` when objtype = '*LIB' then 'SCHEMA'`,
55+
` else SQL_OBJECT_TYPE`,
56+
`end as sqlType`,
57+
].join(` `);
58+
4959
export default class Schemas {
5060
/**
51-
* Resolves to the following SQL types: TABLE, VIEW, ALIAS, INDEX, FUNCTION and PROCEDURE
61+
* Resolves to the following SQL types: SCHEMA, TABLE, VIEW, ALIAS, INDEX, FUNCTION and PROCEDURE
5262
*/
5363
static async resolveObjects(sqlObjects: {name: string, schema?: string}[]): Promise<ResolvedSqlObject[]> {
5464
let statements: string[] = [];
@@ -59,12 +69,12 @@ export default class Schemas {
5969
for (const obj of sqlObjects) {
6070
if (obj.schema) {
6171
statements.push(
62-
`select OBJLONGNAME as name, OBJLONGSCHEMA as schema, SQL_OBJECT_TYPE as sqlType from table(qsys2.object_statistics(?, '*ALL', object_name => ?)) where SQL_OBJECT_TYPE IS NOT NULL`
72+
`${BASE_RESOLVE_SELECT} from table(qsys2.object_statistics(?, '*ALL', object_name => ?)) where SQL_OBJECT_TYPE IS NOT NULL`
6373
);
6474
parameters.push(obj.schema, obj.name);
6575
} else {
6676
statements.push(
67-
`select OBJLONGNAME as name, OBJLONGSCHEMA as schema, SQL_OBJECT_TYPE as sqlType from table(qsys2.object_statistics('*LIBL', '*ALL', object_name => ?)) where SQL_OBJECT_TYPE IS NOT NULL`
77+
`${BASE_RESOLVE_SELECT} from table(qsys2.object_statistics('*LIBL', '*ALL', object_name => ?)) where SQL_OBJECT_TYPE IS NOT NULL`
6878
);
6979
parameters.push(obj.name);
7080
}

0 commit comments

Comments
 (0)