-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xxchan <[email protected]>
- Loading branch information
Showing
6 changed files
with
286 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env zx | ||
|
||
// zx: A tool for writing better scripts | ||
// https://google.github.io/zx/ | ||
|
||
const { | ||
name: job_name, | ||
type: table_type, | ||
_: _command, | ||
} = minimist(process.argv.slice(3), { | ||
string: ["name", "type"], | ||
}); | ||
|
||
// Return an array of CSV string | ||
async function psql(query) { | ||
return ( | ||
await $` | ||
psql -h $RISEDEV_RW_FRONTEND_LISTEN_ADDRESS -p $RISEDEV_RW_FRONTEND_PORT -U root -d dev \ | ||
--csv --tuples-only -c ${query} | ||
` | ||
) | ||
.toString() | ||
.trim() | ||
.split("\n") | ||
.filter((line) => line.trim() != ""); | ||
} | ||
|
||
// If `table_type` is null, return all internal tables for the job. | ||
// If `job_name` is null, return all jobs' internal tables. | ||
async function select_internal_table(job_name, table_type) { | ||
// Note: if we have `t1`, and `t1_balabala`, the latter one will also be matched 😄. | ||
const internal_tables = await psql( | ||
`select name from rw_internal_tables where name like '__internal_${job_name}_%_${table_type}_%'` | ||
); | ||
if (internal_tables.length == 0) { | ||
throw new Error( | ||
`No internal tables found for the pattern '__internal_${job_name}_%_${table_type}_%'` | ||
); | ||
} | ||
|
||
const res = new Map( | ||
await Promise.all( | ||
internal_tables.map(async (t) => { | ||
let rows = await psql(`select * from ${t}`); | ||
if (rows.length == 0) { | ||
rows = ["(empty)"]; | ||
} | ||
return [t, rows]; | ||
}) | ||
) | ||
); | ||
return res; | ||
} | ||
|
||
const tables = await select_internal_table(job_name, table_type); | ||
if (tables.size > 1) { | ||
for (const [table_name, rows] of tables) { | ||
console.log(`Table: ${table_name}`); | ||
console.log(`${rows.join("\n")}`); | ||
} | ||
} else { | ||
for (const [_table_name, rows] of tables) { | ||
console.log(`${rows.join("\n")}`); | ||
} | ||
} |
Oops, something went wrong.