mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add count command
This commit is contained in:
15
api/src/cli/commands/count/index.ts
Normal file
15
api/src/cli/commands/count/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export default async function rolesCreate(collection: string) {
|
||||
const database = require('../../../database/index').default;
|
||||
|
||||
if (!collection) {
|
||||
console.error('Collection is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const records = await database(collection).count('*', { as: 'count' });
|
||||
const count = Number(records[0].count);
|
||||
|
||||
console.log(count);
|
||||
|
||||
database.destroy();
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import dbInstall from './commands/database/install';
|
||||
import dbMigrate from './commands/database/migrate';
|
||||
import usersCreate from './commands/users/create';
|
||||
import rolesCreate from './commands/roles/create';
|
||||
import count from './commands/count';
|
||||
|
||||
program.name('directus').usage('[command] [options]');
|
||||
program.version(pkg.version, '-v, --version');
|
||||
@@ -51,4 +52,9 @@ rolesCommand
|
||||
.option('--admin', `whether or not the role has admin access`)
|
||||
.action(rolesCreate);
|
||||
|
||||
program
|
||||
.command('count <collection>')
|
||||
.description('Count the amount of items in a given collection')
|
||||
.action(count);
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
Reference in New Issue
Block a user