Skip to content

Commit

Permalink
Improved table display in Pongo shell to show all columns
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Oct 9, 2024
1 parent a625c7a commit 7d832a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/pongo-core",
"version": "0.16.0-alpha.9",
"version": "0.16.0-alpha.10",
"description": "Pongo - Mongo with strong consistency on top of Postgres",
"type": "module",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/dumbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/dumbo",
"version": "0.12.0-alpha.9",
"version": "0.12.0-alpha.10",
"description": "Dumbo - tools for dealing with PostgreSQL",
"type": "module",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/packages/pongo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/pongo",
"version": "0.16.0-alpha.9",
"version": "0.16.0-alpha.10",
"description": "Pongo - Mongo with strong consistency on top of Postgres",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -87,7 +87,7 @@
"pongo": "./dist/cli.js"
},
"peerDependencies": {
"@event-driven-io/dumbo": "0.12.0-alpha.9",
"@event-driven-io/dumbo": "0.12.0-alpha.10",
"@types/mongodb": "^4.0.7",
"@types/pg": "^8.11.6",
"@types/uuid": "^10.0.0",
Expand Down
20 changes: 16 additions & 4 deletions src/packages/pongo/src/commandLine/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ const displayResultsAsTable = (results: any[]): string => {
return chalk.yellow('No documents found.');
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const columnNames = Object.keys(results[0]);
const columnNames = results

.flatMap((result) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
typeof result === 'object' ? Object.keys(result) : typeof result,
)
.filter((value, index, array) => array.indexOf(value) === index);

const columnWidths = calculateColumnWidths(results, columnNames);

Expand All @@ -63,7 +68,14 @@ const displayResultsAsTable = (results: any[]): string => {
table.push(
columnNames.map((col) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
result[col] !== undefined ? String(result[col]) : '',
result[col] !== undefined
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Array.isArray(result[col])
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
displayResultsAsTable(result[col])
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
prettyJson(result[col])
: '',
),
);
});
Expand Down Expand Up @@ -102,7 +114,7 @@ const startRepl = async (options: {
setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);
setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);

console.log(chalk.green('Starting Pongo Shell (version: 0.16.0-alpha.9)'));
console.log(chalk.green('Starting Pongo Shell (version: 0.16.0-alpha.10)'));

const connectionString =
options.connectionString ??
Expand Down

0 comments on commit 7d832a3

Please sign in to comment.