Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit bc6a4bc

Browse files
committed
feat: add dump command for dumping a database table
1 parent b41eec9 commit bc6a4bc

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ script:
1919
- npx ts-node src/cli.ts update nixos-18.09
2020
- make cover
2121
- make docs
22+
# Dump the packages to a TSV file for browsing (until we have a better way of browsing them)
23+
- npx ts-node src/cli.ts dump packages --tsv > docs/packages.tsv
2224

2325
# Generate Nix files
2426
# node2nix produce a lot of output on stderr which causes Travis to say

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ adds:
9595
- r-titrationcurves
9696
```
9797
98+
If you do not have Nixster installed it can be sometimes difficult to work out the right package name to use. Until we have a better solution, we currently dump a tab separated file of all packages to https://stencila.github.io/nixster/packages.tsv on each Travis build.
99+
98100
#### Use Github editor
99101
100102
Edit the `.yaml` file for the environment directly on Github using the `https://github.com/stencila/nixster/edit/master/envs/<ENIRONMENT-NAME>.yaml` URL. For example, for the `r-mega` environment, edit the `envs/r-mega.yaml` file with this [link](https://github.com/stencila/nixster/edit/master/envs/r-mega.yaml). Github should ask you if you want to fork the repository and create a new pull request for your edit. Follow the instructions above for adding/removing packages using a text editor.

src/cli.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,34 @@ yargs
400400
output({ list, term, type }, argv, searchPrettify)
401401
})
402402

403+
.command('dump [table]', 'Search in database', (yargs: any) => {
404+
yargs
405+
.positional('table', {
406+
describe: 'The database table to dump',
407+
type: 'string',
408+
default: 'packages'
409+
})
410+
// Usual output options, plus TSV
411+
outputOptions(yargs)
412+
yargs
413+
.option('tsv', {
414+
describe: 'Output as TSV (tab separated values)',
415+
type: 'boolean'
416+
})
417+
.conflicts('tsv', 'format')
418+
.conflicts('tsv', 'pretty')
419+
.conflicts('tsv', 'yaml')
420+
.conflicts('tsv', 'json')
421+
}, async (argv: any) => {
422+
const rows = await nix.dump(argv.table)
423+
if (argv.format === 'tsv' || argv.tsv) {
424+
console.log('name\ttype\tversion\tdescription')
425+
for (let row of rows) {
426+
console.log(`${row.name}\t${row.type}\t${row.version}\t${row.description}`)
427+
}
428+
} else output(rows, argv)
429+
})
430+
403431
.command('serve', 'Serve', (yargs: any) => {
404432
yargs
405433
.option('port', {

src/nix.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,28 @@ export async function search (term: string, type: string = '', limit: number = 1
240240
return stmt.all(limit)
241241
}
242242

243+
/**
244+
* Dump one of the tables in the Nixster database
245+
*
246+
* @param table The table to dump
247+
*/
248+
export async function dump (table: string): Promise<Array<any>> {
249+
let stmt
250+
if (table === 'packages') {
251+
stmt = db.prepare(`
252+
SELECT name, type, max(version) AS version, max(channel) AS channel, max(description) AS description
253+
FROM (
254+
SELECT name, type, version, channel, description
255+
FROM packages
256+
)
257+
GROUP BY name, type
258+
`)
259+
} else {
260+
throw new Error(`Dumping table "${table}" is not supported`)
261+
}
262+
return stmt.all()
263+
}
264+
243265
/**
244266
* Get the location of an environment within the Nix store
245267
*

0 commit comments

Comments
 (0)