Skip to main content

CLI

The package installs the orm command. Run it from the root of the project, where knexfile.js lives.

orm migration​

Compares your models with the current database schema and writes the matching Knex migration files.

npx orm migration
npx knex migrate:latest

The command first compiles the TypeScript project: fix compilation errors before migrating. If tables would be dropped, it asks for confirmation.

  • -p, --project <directory>: project directory;
  • -t, --table <table>: generate the migration for a single model;
  • --runMigration: run the migrations without asking;
  • --authorizeDeletion: allow dropping tables without asking.

Without --runMigration, apply the migrations with knex migrate:latest, as the command reminds you.

orm queryrow <name>​

Creates the file of a new model for the name table.

npx orm queryrow posts
  • -p, --project <directory>: directory to create the file in (./src by default).

orm accessor​

Generates the getters and setters of models from their columns.

npx orm accessor
npx orm accessor --table users
  • -p, --project <directory>: project directory (./src by default);
  • -t, --table <table>: only handle one model.