Running Scripts with the CLI
You can easily execute scripts from the CLI using the npx accel run
command. This command operates with an initialized database connection and leverages Vite internally, allowing you to pass TypeScript files directly.
If any of the following functions are defined in the script, they will be executed automatically:
- A function exported as
export default
- A function exported as
main
Script File and Execution Example
import { Account } from "./models/index.js";
export default async () => { const count = Account.count(); console.log(`Total accounts: ${count}`);};
$ npx accel run src/scripts/sample.tsTotal accounts: 10
Custom CLI Commands
In addition to running scripts, you can also register custom CLI commands in the files under src/commands/
. This allows you to execute custom processes with the database connection fully initialized.
Creating Custom Commands
import { program } from "accella/cli";import { Account } from "../models";
program .command("hello") .description("Hello command") .action(() => { console.log("Hello from Accella!"); const count = Account.count(); console.log(`Total accounts: ${count}`); });
Running Custom Commands
# Run the command$ npx accel helloHello from Accella!Total accounts: 5