capacitor-typeorm-cli
v0.0.2
Published
Capacitor SQLite TypeOrm CLI
Downloads
6
Readme
Maintainers
| Maintainer | GitHub | Social | | ----------------- | ----------------------------------------- | ------ | | Quéau Jean Pierre | jepiqueau | |
Installing the CLI
npm install -g capacitor-typeorm-cli
For Typescript
projects two others packages are required to be installed
npm install --save-dev @types/node
npm install --save-dev ts-node
Supported Command
| Name | Description
| :--------------------- | :------------------------------ |
| migration-generate
| Generate typeorm migration file |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! All the others commands from the typeOrm CLI are not supported. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To get the list of commands via the Help run
npx capacitor-typeorm-cli -h
Output
Usage: capacitor-typeorm-cli [options] [command]
A CLI tool for generating migrations for Capacitor SQite TypeOrm
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
migration-generate [options] generate typeorm migration file
help [command] display help for command
Usage migration-generate
Get it from the Help
npx capacitor-typeorm-cli help migration-generate
Output
Usage: capacitor-typeorm-cli migration-generate [options]
generate typeorm migration file
Options:
-c, --command <commandName> Alias command name
-e, --entity <entityPath> Alias for entity path
-m, --migration <migrationPath> Alias for migration path
-i, --indexJs [indexJs] Alias Index file extension for Javascript
instead of Typescript
-db, --database [databasePath] Alias for database path
-o, --outputJs [outputJs] Generate a migration file on Javascript
instead of Typescript
-t, --timestamp [timestamp] Custom timestamp for the migration name
-h, --help display help for command
EntityPath (Mandatory)
The entityPath
refers to the directory containing entity files, particularly the index.ts file. This index.ts file should export all entities. For example:
import { Item } from './item';
import { User } from './user';
export { User, Item };
MigrationPath (Mandatory)
The migrationPath
denotes the directory where migration files, generated by the CLI, are stored. Initially, an index.ts file must be created in this directory as follows:
export { };
IndexJs (Optional)
The indexJs
parameter is utilized to specify the file extension for the index file. If set to true, the extension will be .js for JavaScript files; otherwise, the default extension will be .ts for TypeScript files.
DatabasePath (Optional)
This parameter specifies the path to the database where the web database has been stored on disk for generating refactoring migrations. It is not required for the initial migration generation.
OutputJs (Optional)
When set to true, this parameter instructs the CLI to generate the migration files in JavaScript. By default, the files are generated in TypeScript.
Timestamp (Optional)
If you need to specify a timestamp for the migration name, use the -t option (alias for --timestamp) and provide the timestamp (should be a non-negative number). If not provided, the default timestamp is obtained from Date.now()
.
Project Folder Structure
src/
| ...
| entities/
... / (if needed)
| index.ts
| user.ts
| ...
| migrations/
... / (if needed)
| index.ts
| ...
Package.json Scripts
Add Capacitor Typeorm command under scripts section in package.json
For commonjs project
"scripts": { ... "captypeorm": "typeorm-ts-node-commonjs" }
For ESM project
"scripts": { ... "captypeorm": "capacitor-typeorm-esm", }
Then add scripts to generate the migrations
"scripts": { ... "cap:typeorm:migration:initialAuthor": "npm run captypeorm migration-generate -- src/databases/entities/author src/databases/migrations/author/InitialAuthorPost", "cap:typeorm:migration:refactorAuthor": "npm run captypeorm migration-generate -- -m src/databases/migrations/author/RefactorAuthorPost -t 1234567890123 -db ABSOLUTE_PATH_TO_YOUR_DB -e src/databases/entities/author", }
In case one do not want to use the script
captypeorm
, one can define the script like this For ESM module"scripts": { ... "cap:typeorm:migration:initialAuthor": "npx capacitor-typeorm-esm migration-generate src/databases/entities/author src/databases/migrations/author/InitialAuthorPost", "cap:typeorm:migration:refactorAuthor": "npx capacitor-typeorm-esm migration-generate -m src/databases/migrations/author/RefactorAuthorPost -t 1234567890123 -db ABSOLUTE_PATH_TO_YOUR_DB -e src/databases/entities/author", }
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!