You can use TypeORM in connection with the cordova-sqlite-storage
plugin in your Ionic app.
This project demonstrates how that would work.
To run this example in production or development mode you have to make sure, ionic
and cordova
are installed globally on your machine. After that you can install all necessary dependencies for running this example.
- Check if
npm
is installed. Otherwise please installnode.js
andnpm
.
npm -v
- Install ionic and cordova command line interface globally.
npm install -g cordova ionic
- Install all dependencies listed in
package.json
.
npm install
ionic serve
- Add an iOS or Android to the project.
ionic cordova platform add ios
# or
ionic cordova platform add android
- Run the app on your device.
ionic cordova run ios
# or
ionic cordova run android
For further information please read ionic's deployment guide.
- Install the plugin
ionic cordova plugin add cordova-sqlite-storage --save
- Install TypeORM
npm install typeorm --save
- Install node.js-Types
npm install @types/node --save-dev
-
Add
"typeRoots": ["node_modules/@types"]
to yourtsconfig.json
undercompilerOptions
-
Create a custom webpack config file like the one included in this project to use the correct TypeORM version and add the config file to your
package.json
(Required with TypeORM >= 0.1.7)
Since Ionic make a lot of optimizations while building for production, the following limitations will occur:
-
Entities have to be marked with the table name (eg
@Entity('table_name')
) -
getRepository()
has to be called with the name of the entity instead of the class (eggetRepository('post') as Repository<Post>
) -
Date fields are not supported:
@Column()
birthdate: Date;
Error:
Installing "cordova-sqlite-storage" for android
Failed to install 'cordova-sqlite-storage': CordovaError: Using "requireCordovaModule" to load non-cordova module "q" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
at Context.requireCordovaModule (/Users/user/.nvm/versions/node/v14.4.0/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/Context.js:57:15)
at module.exports (/Users/user/Documents/Development/Cordova/typeorm-ionic-example/plugins/cordova-sqlite-storage/scripts/beforePluginInstall.js:13:21)
at runScriptViaModuleLoader (/Users/user/.nvm/versions/node/v14.4.0/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:157:32)
at runScript (/Users/user/.nvm/versions/node/v14.4.0/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:136:12)
at /Users/user/.nvm/versions/node/v14.4.0/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:108:40
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Using "requireCordovaModule" to load non-cordova module "q" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
[ERROR] An error occurred while running subprocess cordova.
cordova platform add android exited with exit code 1.
Re-running this command with the --verbose flag may provide more
information.
try these steps:
just android
ionic cordova platform rm android; ionic cordova plugin rm cordova-sqlite-storage; npm i cordova-sqlite-storage@latest && ionic cordova plugin add cordova-sqlite-storage; ionic cordova platform add android
try these steps:
ios & android
ionic cordova platform rm ios; ionic cordova platform rm android; ionic cordova plugin rm cordova-sqlite-storage; npm i cordova-sqlite-storage@latest && ionic cordova plugin add cordova-sqlite-storage; ionic cordova platform add ios; ionic cordova platform add android
https://medium.com/@jorgekg3/how-enable-clear-text-traffic-on-android-9-ad56603fb17d