Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

27: Add object count #115

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions src/providers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,34 @@ export default class DatabaseTreeProvider implements vscode.TreeDataProvider<Nod
console.log("SchemaReader: ", schema, schemas, schemaName);

if (schema) {
const promises = [
this.getSources(schema.id).then(s => s.length),
this.getViews(schema.id).then(v => v.length),
this.getMaterializedViews(schema.id).then(mv => mv.length),
this.getTables(schema.id).then(t => t.length),
this.getSinks(schema.id).then(s => s.length),
this.getCatalog().then(c => c.length),
this.getInternal().then(i => i.length)
];

const [
sourceCount,
viewCount,
materializedViewCount,
tableCount,
sinkCount,
catalogCount,
internalCount
] = await Promise.all(promises);

res([
new SourceTab("Sources", vscode.TreeItemCollapsibleState.Collapsed, schema),
new ViewTab("Views", vscode.TreeItemCollapsibleState.Collapsed, schema),
new MaterializedViewTab("Materialized Views", vscode.TreeItemCollapsibleState.Collapsed, schema),
new TableTab("Tables", vscode.TreeItemCollapsibleState.Collapsed, schema),
new SinkTab("Sinks", vscode.TreeItemCollapsibleState.Collapsed, schema),
new CatalogTab("Catalog", vscode.TreeItemCollapsibleState.Collapsed, schema),
new InternalTab("Internal", vscode.TreeItemCollapsibleState.Collapsed, schema)
new SourceTab(`Sources (${sourceCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema),
new ViewTab(`Views (${viewCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema),
new MaterializedViewTab(`Materialized Views (${materializedViewCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema),
new TableTab(`Tables (${tableCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema),
new SinkTab(`Sinks (${sinkCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema),
new CatalogTab(`Catalog (${catalogCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema),
new InternalTab(`Internal (${internalCount})`, vscode.TreeItemCollapsibleState.Collapsed, schema)
]);
} else {
console.error("[DatabaseTreeProvider]", "Error: Wrong state, the schema is missing.");
Expand Down Expand Up @@ -145,29 +165,29 @@ export default class DatabaseTreeProvider implements vscode.TreeDataProvider<Nod
}

private async getSources(schema: String): Promise<Array<Node>> {
const views: Promise<Array<Node>> = new Promise((res, rej) => {
this.query("SELECT id, name, owner_id FROM mz_sinks WHERE schema_id = $1", [schema]).then((results) => {
let views = results.map(({ id, name, owner_id: ownerId }) => {
const sources: Promise<Array<Node>> = new Promise((res, rej) => {
this.query("SELECT id, name, owner_id FROM mz_sources WHERE schema_id = $1", [schema]).then((results) => {
let sources = results.map(({ id, name, owner_id: ownerId }) => {
return new View(name, vscode.TreeItemCollapsibleState.Collapsed, { id, name, ownerId });
});
res(views);
res(sources);
}).catch(rej);
});

return views;
return sources;
}

private async getSinks(schema: String): Promise<Array<Node>> {
const views: Promise<Array<Node>> = new Promise((res, rej) => {
const sinks: Promise<Array<Node>> = new Promise((res, rej) => {
this.query("SELECT id, name, owner_id FROM mz_sinks WHERE schema_id = $1", [schema]).then((results) => {
let views = results.map(({ id, name, owner_id: ownerId }) => {
let sinks = results.map(({ id, name, owner_id: ownerId }) => {
return new View(name, vscode.TreeItemCollapsibleState.Collapsed, { id, name, ownerId });
});
res(views);
res(sinks);
}).catch(rej);
});

return views;
return sinks;
}

private async getViews(schema: String): Promise<Array<Node>> {
Expand Down Expand Up @@ -436,4 +456,4 @@ class Column extends vscode.TreeItem {
}

contextValue = ContextValue.column;
}
}