├── .editorconfig ├── .gitignore ├── README.md ├── config.xml ├── config └── webpack.config.js ├── ionic.config.json ├── package-lock.json ├── package.json ├── resources ├── README.md ├── android │ ├── icon │ │ ├── drawable-hdpi-icon.png │ │ ├── drawable-ldpi-icon.png │ │ ├── drawable-mdpi-icon.png │ │ ├── drawable-xhdpi-icon.png │ │ ├── drawable-xxhdpi-icon.png │ │ └── drawable-xxxhdpi-icon.png │ └── splash │ │ ├── drawable-land-hdpi-screen.png │ │ ├── drawable-land-ldpi-screen.png │ │ ├── drawable-land-mdpi-screen.png │ │ ├── drawable-land-xhdpi-screen.png │ │ ├── drawable-land-xxhdpi-screen.png │ │ ├── drawable-land-xxxhdpi-screen.png │ │ ├── drawable-port-hdpi-screen.png │ │ ├── drawable-port-ldpi-screen.png │ │ ├── drawable-port-mdpi-screen.png │ │ ├── drawable-port-xhdpi-screen.png │ │ ├── drawable-port-xxhdpi-screen.png │ │ └── drawable-port-xxxhdpi-screen.png ├── icon.png ├── icon.png.md5 ├── ios │ ├── icon │ │ ├── icon-1024.png │ │ ├── icon-40.png │ │ ├── icon-40@2x.png │ │ ├── icon-40@3x.png │ │ ├── icon-50.png │ │ ├── icon-50@2x.png │ │ ├── icon-60.png │ │ ├── icon-60@2x.png │ │ ├── icon-60@3x.png │ │ ├── icon-72.png │ │ ├── icon-72@2x.png │ │ ├── icon-76.png │ │ ├── icon-76@2x.png │ │ ├── icon-83.5@2x.png │ │ ├── icon-small.png │ │ ├── icon-small@2x.png │ │ ├── icon-small@3x.png │ │ ├── icon.png │ │ └── icon@2x.png │ └── splash │ │ ├── Default-568h@2x~iphone.png │ │ ├── Default-667h.png │ │ ├── Default-736h.png │ │ ├── Default-Landscape-736h.png │ │ ├── Default-Landscape@2x~ipad.png │ │ ├── Default-Landscape@~ipadpro.png │ │ ├── Default-Landscape~ipad.png │ │ ├── Default-Portrait@2x~ipad.png │ │ ├── Default-Portrait@~ipadpro.png │ │ ├── Default-Portrait~ipad.png │ │ ├── Default@2x~iphone.png │ │ ├── Default@2x~universal~anyany.png │ │ └── Default~iphone.png ├── splash.png └── splash.png.md5 ├── screenshot.png ├── src ├── app │ ├── app.component.ts │ ├── app.html │ ├── app.module.ts │ ├── app.scss │ └── main.ts ├── assets │ └── icon │ │ └── favicon.ico ├── entities │ ├── author.ts │ ├── category.ts │ └── post.ts ├── index.html ├── manifest.json ├── pages │ └── home │ │ ├── home.html │ │ ├── home.scss │ │ └── home.ts ├── service-worker.js └── theme │ └── variables.scss ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | indent_size = 2 9 | 10 | # We recommend you to keep these unchanged 11 | end_of_line = lf 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | [*.md] 17 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Specifies intentionally untracked files to ignore when using Git 2 | # http://git-scm.com/docs/gitignore 3 | 4 | *~ 5 | *.sw[mnpcod] 6 | *.log 7 | *.tmp 8 | *.tmp.* 9 | log.txt 10 | *.sublime-project 11 | *.sublime-workspace 12 | .vscode/ 13 | npm-debug.log* 14 | 15 | .idea/ 16 | .sourcemaps/ 17 | .sass-cache/ 18 | .tmp/ 19 | .versions/ 20 | coverage/ 21 | dist/ 22 | node_modules/ 23 | tmp/ 24 | temp/ 25 | hooks/ 26 | platforms/ 27 | plugins/ 28 | plugins/android.json 29 | plugins/ios.json 30 | www/ 31 | $RECYCLE.BIN/ 32 | 33 | .DS_Store 34 | Thumbs.db 35 | UserInterfaceState.xcuserstate 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using TypeORM in an Ionic project 2 | You can use TypeORM in connection with the `cordova-sqlite-storage` plugin in your Ionic app. 3 | This project demonstrates how that would work. 4 | 5 | ## Installation 6 | 7 | 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. 8 | 9 | 0. Check if `npm` is installed. Otherwise please [install `node.js` and `npm`](https://nodejs.org/en/download/package-manager/). 10 | ```bash 11 | npm -v 12 | ``` 13 | 14 | 1. Install ionic and cordova command line interface globally. 15 | ```bash 16 | npm install -g cordova ionic 17 | ``` 18 | 19 | 2. Install all dependencies listed in [`package.json`](/package.json). 20 | ```bash 21 | npm install 22 | ``` 23 | 24 | ### Running the example in your browser 25 | ```bash 26 | ionic serve 27 | ``` 28 | 29 | ### Running the example on your device 30 | 3. Add an iOS or Android to the project. 31 | ```bash 32 | ionic cordova platform add ios 33 | # or 34 | ionic cordova platform add android 35 | ``` 36 | 37 | 4. Run the app on your device. 38 | ```bash 39 | ionic cordova run ios 40 | # or 41 | ionic cordova run android 42 | ``` 43 | 44 | *For further information please read [ionic's deployment guide](https://ionicframework.com/docs/intro/deploying/).* 45 | 46 | ![screenshot](./screenshot.png) 47 | 48 | ### Using TypeORM in your own app 49 | 1. Install the plugin 50 | ```bash 51 | ionic cordova plugin add cordova-sqlite-storage --save 52 | ``` 53 | 54 | 2. Install TypeORM 55 | ```bash 56 | npm install typeorm --save 57 | ``` 58 | 59 | 3. Install node.js-Types 60 | ```bash 61 | npm install @types/node --save-dev 62 | ``` 63 | 64 | 4. Add `"typeRoots": ["node_modules/@types"]` to your `tsconfig.json` under `compilerOptions` 65 | 66 | 5. Create a custom webpack config file like the one [included in this project](config/webpack.config.js) to use the correct TypeORM version and add the config file to your [`package.json`](package.json#L12-14) (Required with TypeORM >= 0.1.7) 67 | 68 | ### Limitations to TypeORM when using production builds 69 | 70 | Since Ionic make a lot of optimizations while building for production, the following limitations will occur: 71 | 72 | 1. Entities have to be marked with the table name (eg `@Entity('table_name')`) 73 | 74 | 2. `getRepository()` has to be called with the name of the entity instead of the class (*eg `getRepository('post') as Repository`*) 75 | 76 | 3. Date fields are **not supported**: 77 | ```ts 78 | @Column() 79 | birthdate: Date; 80 | ``` 81 | -------------------------------------------------------------------------------- /config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | TypeORM-Ionic 4 | A simple app to test typeorm with cordova sqlite in ionic 5 | 6 | Daniel Lang 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /config/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The webpack config exports an object that has a valid webpack configuration 3 | * For each environment name. By default, there are two Ionic environments: 4 | * "dev" and "prod". As such, the webpack.config.js exports a dictionary object 5 | * with "keys" for "dev" and "prod", where the value is a valid webpack configuration 6 | * For details on configuring webpack, see their documentation here 7 | * https://webpack.js.org/configuration/ 8 | */ 9 | 10 | var webpack = require('webpack'); 11 | 12 | const CopyPlugin = require('copy-webpack-plugin'); 13 | 14 | var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js'); 15 | 16 | useDefaultConfig.dev.plugins.push( 17 | new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) { 18 | result.request = result.request.replace(/typeorm/, "typeorm/browser"); 19 | }), 20 | new webpack.ProvidePlugin({ 21 | 'window.SQL': 'sql.js/dist/sql-wasm-debug.js' 22 | }), 23 | new CopyPlugin([ { from: 'node_modules/sql.js/dist/sql-wasm-debug.wasm', to: "../sql-wasm-debug.wasm" } ]), 24 | ); 25 | 26 | useDefaultConfig.dev.plugins.push( 27 | new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) { 28 | result.request = result.request.replace(/typeorm/, "typeorm/browser"); 29 | }), 30 | new webpack.ProvidePlugin({ 31 | 'window.SQL': 'sql.js/dist/sql-wasm.js' 32 | }), 33 | new CopyPlugin([ { from: 'node_modules/sql.js/dist/sql-wasm.wasm', to: "../sql-wasm.wasm" } ]), 34 | ); 35 | 36 | module.exports = function () { 37 | return useDefaultConfig; 38 | }; 39 | -------------------------------------------------------------------------------- /ionic.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-example", 3 | "app_id": "", 4 | "type": "ionic-angular", 5 | "integrations": { 6 | "cordova": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-example", 3 | "version": "1.0.0", 4 | "author": "Daniel Lang", 5 | "scripts": { 6 | "clean": "ionic-app-scripts clean", 7 | "build": "ionic-app-scripts build", 8 | "lint": "ionic-app-scripts lint", 9 | "ionic:build": "ionic-app-scripts build", 10 | "ionic:serve": "ionic-app-scripts serve" 11 | }, 12 | "config": { 13 | "ionic_webpack": "./config/webpack.config.js" 14 | }, 15 | "dependencies": { 16 | "@angular/common": "4.4.3", 17 | "@angular/compiler": "4.4.3", 18 | "@angular/compiler-cli": "4.4.3", 19 | "@angular/core": "4.4.3", 20 | "@angular/forms": "4.4.3", 21 | "@angular/http": "4.4.3", 22 | "@angular/platform-browser": "4.4.3", 23 | "@angular/platform-browser-dynamic": "4.4.3", 24 | "@ionic-native/core": "4.3.0", 25 | "@ionic-native/splash-screen": "4.3.0", 26 | "@ionic-native/status-bar": "4.3.0", 27 | "@ionic/storage": "2.0.1", 28 | "cordova-android": "^6.4.0", 29 | "cordova-ios": "^4.5.0", 30 | "cordova-plugin-device": "^1.1.7", 31 | "cordova-plugin-splashscreen": "^4.1.0", 32 | "cordova-plugin-statusbar": "^2.4.1", 33 | "cordova-plugin-whitelist": "^1.3.3", 34 | "cordova-sqlite-storage": "^2.2.1", 35 | "ionic-angular": "3.7.0", 36 | "ionic-plugin-keyboard": "^2.2.1", 37 | "ionicons": "3.0.0", 38 | "rxjs": "5.4.3", 39 | "sw-toolbox": "3.6.0", 40 | "typeorm": "^0.2.28", 41 | "zone.js": "0.8.17" 42 | }, 43 | "devDependencies": { 44 | "@ionic/app-scripts": "^3.0.0", 45 | "@types/node": "^10.0.31", 46 | "copy-webpack-plugin": "^4.6.0", 47 | "sql.js": "^1.3.2", 48 | "typescript": "^3.3.3333" 49 | }, 50 | "description": "An Ionic project", 51 | "cordova": { 52 | "plugins": { 53 | "cordova-plugin-device": {}, 54 | "cordova-plugin-splashscreen": {}, 55 | "cordova-plugin-statusbar": {}, 56 | "cordova-plugin-whitelist": {}, 57 | "ionic-plugin-keyboard": {}, 58 | "cordova-sqlite-storage": {} 59 | }, 60 | "platforms": [ 61 | "android", 62 | "ios" 63 | ] 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /resources/README.md: -------------------------------------------------------------------------------- 1 | These are Cordova resources. You can replace icon.png and splash.png and run 2 | `ionic cordova resources` to generate custom icons and splash screens for your 3 | app. See `ionic cordova resources --help` for details. 4 | 5 | Cordova reference documentation: 6 | 7 | - Icons: https://cordova.apache.org/docs/en/latest/config_ref/images.html 8 | - Splash Screens: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/ 9 | -------------------------------------------------------------------------------- /resources/android/icon/drawable-hdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/icon/drawable-hdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-ldpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/icon/drawable-ldpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-mdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/icon/drawable-mdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-xhdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/icon/drawable-xhdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-xxhdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/icon/drawable-xxhdpi-icon.png -------------------------------------------------------------------------------- /resources/android/icon/drawable-xxxhdpi-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/icon/drawable-xxxhdpi-icon.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-hdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-land-hdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-ldpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-land-ldpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-mdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-land-mdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-xhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-land-xhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-xxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-land-xxhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-land-xxxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-land-xxxhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-hdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-port-hdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-ldpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-port-ldpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-mdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-port-mdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-xhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-port-xhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-xxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-port-xxhdpi-screen.png -------------------------------------------------------------------------------- /resources/android/splash/drawable-port-xxxhdpi-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/android/splash/drawable-port-xxxhdpi-screen.png -------------------------------------------------------------------------------- /resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/icon.png -------------------------------------------------------------------------------- /resources/icon.png.md5: -------------------------------------------------------------------------------- 1 | 3f1bbdf1aefcb5ce7b60770ce907c68f -------------------------------------------------------------------------------- /resources/ios/icon/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-1024.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-40.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-40@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-40@3x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-50.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-50@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-60.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-60@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-60@3x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-72.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-72@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-76.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-76@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-83.5@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-small.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-small@2x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon-small@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon-small@3x.png -------------------------------------------------------------------------------- /resources/ios/icon/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon.png -------------------------------------------------------------------------------- /resources/ios/icon/icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/icon/icon@2x.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-568h@2x~iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-568h@2x~iphone.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-667h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-667h.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-736h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-736h.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape-736h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Landscape-736h.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape@2x~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Landscape@2x~ipad.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape@~ipadpro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Landscape@~ipadpro.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Landscape~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Landscape~ipad.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Portrait@2x~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Portrait@2x~ipad.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Portrait@~ipadpro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Portrait@~ipadpro.png -------------------------------------------------------------------------------- /resources/ios/splash/Default-Portrait~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default-Portrait~ipad.png -------------------------------------------------------------------------------- /resources/ios/splash/Default@2x~iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default@2x~iphone.png -------------------------------------------------------------------------------- /resources/ios/splash/Default@2x~universal~anyany.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default@2x~universal~anyany.png -------------------------------------------------------------------------------- /resources/ios/splash/Default~iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/ios/splash/Default~iphone.png -------------------------------------------------------------------------------- /resources/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/resources/splash.png -------------------------------------------------------------------------------- /resources/splash.png.md5: -------------------------------------------------------------------------------- 1 | 0dcf1df8c92c1ece4382d3357d9f8562 -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/screenshot.png -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Platform } from 'ionic-angular'; 3 | import { StatusBar } from '@ionic-native/status-bar'; 4 | import { SplashScreen } from '@ionic-native/splash-screen'; 5 | import { createConnection } from 'typeorm' 6 | 7 | import { HomePage } from '../pages/home/home'; 8 | 9 | import { Author } from '../entities/author'; 10 | import { Category } from '../entities/category'; 11 | import { Post } from '../entities/post'; 12 | 13 | @Component({ 14 | templateUrl: 'app.html' 15 | }) 16 | export class MyApp { 17 | rootPage: any; 18 | 19 | constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { 20 | platform.ready().then(async () => { 21 | // Okay, so the platform is ready and our plugins are available. 22 | // Here you can do any higher level native things you might need. 23 | statusBar.styleDefault(); 24 | splashScreen.hide(); 25 | 26 | // Depending on the machine the app is running on, configure 27 | // different database connections 28 | if(platform.is('cordova')) { 29 | // Running on device or emulator 30 | await createConnection({ 31 | type: 'cordova', 32 | database: 'test', 33 | location: 'default', 34 | logging: ['error', 'query', 'schema'], 35 | synchronize: true, 36 | entities: [ 37 | Author, 38 | Category, 39 | Post 40 | ] 41 | }); 42 | } else { 43 | // Running app in browser 44 | await createConnection({ 45 | type: 'sqljs', 46 | autoSave: true, 47 | location: 'browser', 48 | logging: ['error', 'query', 'schema'], 49 | synchronize: true, 50 | entities: [ 51 | Author, 52 | Category, 53 | Post 54 | ] 55 | }); 56 | } 57 | 58 | this.rootPage = HomePage; 59 | }); 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/app/app.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { ErrorHandler, NgModule } from '@angular/core'; 3 | import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; 4 | import { SplashScreen } from '@ionic-native/splash-screen'; 5 | import { StatusBar } from '@ionic-native/status-bar'; 6 | 7 | import { MyApp } from './app.component'; 8 | import { HomePage } from '../pages/home/home'; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | MyApp, 13 | HomePage 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | IonicModule.forRoot(MyApp) 18 | ], 19 | bootstrap: [IonicApp], 20 | entryComponents: [ 21 | MyApp, 22 | HomePage 23 | ], 24 | providers: [ 25 | StatusBar, 26 | SplashScreen, 27 | {provide: ErrorHandler, useClass: IonicErrorHandler} 28 | ] 29 | }) 30 | export class AppModule {} 31 | -------------------------------------------------------------------------------- /src/app/app.scss: -------------------------------------------------------------------------------- 1 | // http://ionicframework.com/docs/theming/ 2 | 3 | 4 | // App Global Sass 5 | // -------------------------------------------------- 6 | // Put style rules here that you want to apply globally. These 7 | // styles are for the entire app and not just one component. 8 | // Additionally, this file can be also used as an entry point 9 | // to import other Sass files to be included in the output CSS. 10 | // 11 | // Shared Sass variables, which can be used to adjust Ionic's 12 | // default Sass variables, belong in "theme/variables.scss". 13 | // 14 | // To declare rules for a specific mode, create a child rule 15 | // for the .md, .ios, or .wp mode classes. The mode class is 16 | // automatically applied to the element in the app. 17 | -------------------------------------------------------------------------------- /src/app/main.ts: -------------------------------------------------------------------------------- 1 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 2 | 3 | import { AppModule } from './app.module'; 4 | 5 | platformBrowserDynamic().bootstrapModule(AppModule); 6 | -------------------------------------------------------------------------------- /src/assets/icon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typeorm/ionic-example/84542d3913867ca79e4c1437fd6dee5bdc9aa397/src/assets/icon/favicon.ico -------------------------------------------------------------------------------- /src/entities/author.ts: -------------------------------------------------------------------------------- 1 | import {Entity, Column, PrimaryGeneratedColumn, OneToMany} from "typeorm"; 2 | import {Post} from "./post"; 3 | 4 | @Entity('author') 5 | export class Author { 6 | 7 | @PrimaryGeneratedColumn() 8 | id: number; 9 | 10 | @Column() 11 | name: string; 12 | 13 | @Column({nullable: true}) 14 | birthdate: string; 15 | 16 | @OneToMany(type => Post, post => post.author) 17 | posts: Post[]; 18 | } 19 | -------------------------------------------------------------------------------- /src/entities/category.ts: -------------------------------------------------------------------------------- 1 | import {Entity, PrimaryGeneratedColumn, Column} from "typeorm"; 2 | 3 | @Entity('category') 4 | export class Category { 5 | 6 | @PrimaryGeneratedColumn() 7 | id: number; 8 | 9 | @Column() 10 | name: string; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/entities/post.ts: -------------------------------------------------------------------------------- 1 | import {Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, ManyToOne} from "typeorm"; 2 | import {Category} from "./category"; 3 | import {Author} from "./author" 4 | 5 | @Entity('post') 6 | export class Post { 7 | 8 | @PrimaryGeneratedColumn() 9 | id: number; 10 | 11 | @Column() 12 | title: string; 13 | 14 | @Column("text") 15 | text: string; 16 | 17 | @ManyToMany(type => Category, { 18 | cascade: ['insert'] 19 | }) 20 | @JoinTable() 21 | categories: Category[]; 22 | 23 | @ManyToOne(type => Author, author => author.posts, { 24 | cascade: ['insert'] 25 | }) 26 | author: Author; 27 | } 28 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ionic App 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Ionic", 3 | "short_name": "Ionic", 4 | "start_url": "index.html", 5 | "display": "standalone", 6 | "icons": [{ 7 | "src": "assets/imgs/logo.png", 8 | "sizes": "512x512", 9 | "type": "image/png" 10 | }], 11 | "background_color": "#4e8ef7", 12 | "theme_color": "#4e8ef7" 13 | } -------------------------------------------------------------------------------- /src/pages/home/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TypeORM Demo 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Post saved 15 | 16 | Loaded Post 17 | Post not loaded 18 | 19 | ID: {{loadedPost?.id}} 20 | Title: {{loadedPost?.title}} 21 | Author: {{loadedPost?.author.name}} 22 | Categories: {{getCategories()}} 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/pages/home/home.scss: -------------------------------------------------------------------------------- 1 | page-home { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /src/pages/home/home.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { NavController } from 'ionic-angular'; 3 | import { getRepository, Repository } from 'typeorm'; 4 | 5 | import { Author } from '../../entities/author'; 6 | import { Category } from '../../entities/category'; 7 | import { Post } from '../../entities/post'; 8 | 9 | @Component({ 10 | selector: 'page-home', 11 | templateUrl: 'home.html' 12 | }) 13 | export class HomePage { 14 | private savedPost: boolean = false; 15 | private loadedPost: Post = null; 16 | 17 | constructor(public navCtrl: NavController) { } 18 | 19 | ionViewDidLoad() { 20 | this.runDemo(); 21 | } 22 | 23 | async runDemo() { 24 | const category1 = new Category(); 25 | category1.name = "TypeScript"; 26 | 27 | const category2 = new Category(); 28 | category2.name = "Programming"; 29 | 30 | const author = new Author(); 31 | author.name = "Person"; 32 | 33 | const post = new Post(); 34 | post.title = "Control flow based type analysis"; 35 | post.text = `TypeScript 2.0 implements a control flow-based type analysis for local variables and parameters.`; 36 | post.categories = [category1, category2]; 37 | post.author = author; 38 | 39 | const postRepository = getRepository('post') as Repository; 40 | await postRepository.save(post); 41 | 42 | console.log("Post has been saved"); 43 | this.savedPost = true; 44 | 45 | const loadedPost = await postRepository.createQueryBuilder('post') 46 | .innerJoinAndSelect('post.author', 'author') 47 | .innerJoinAndSelect('post.categories', 'categories') 48 | .where('post.id = :id', {id: post.id}) 49 | .getOne(); 50 | 51 | console.log("Post has been loaded: ", loadedPost); 52 | this.loadedPost = loadedPost; 53 | } 54 | 55 | getCategories() { 56 | if(this.loadedPost) { 57 | return this.loadedPost.categories.map(cat => cat.name).join(", "); 58 | } 59 | 60 | return ''; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/service-worker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Check out https://googlechrome.github.io/sw-toolbox/ for 3 | * more info on how to use sw-toolbox to custom configure your service worker. 4 | */ 5 | 6 | 7 | 'use strict'; 8 | importScripts('./build/sw-toolbox.js'); 9 | 10 | self.toolbox.options.cache = { 11 | name: 'ionic-cache' 12 | }; 13 | 14 | // pre-cache our key assets 15 | self.toolbox.precache( 16 | [ 17 | './build/main.js', 18 | './build/vendor.js', 19 | './build/main.css', 20 | './build/polyfills.js', 21 | 'index.html', 22 | 'manifest.json' 23 | ] 24 | ); 25 | 26 | // dynamically cache any other local assets 27 | self.toolbox.router.any('/*', self.toolbox.cacheFirst); 28 | 29 | // for any other requests go to the network, cache, 30 | // and then only use that cached resource if your user goes offline 31 | self.toolbox.router.default = self.toolbox.networkFirst; 32 | -------------------------------------------------------------------------------- /src/theme/variables.scss: -------------------------------------------------------------------------------- 1 | // Ionic Variables and Theming. For more info, please see: 2 | // http://ionicframework.com/docs/theming/ 3 | 4 | // Font path is used to include ionicons, 5 | // roboto, and noto sans fonts 6 | $font-path: "../assets/fonts"; 7 | 8 | 9 | // The app direction is used to include 10 | // rtl styles in your app. For more info, please see: 11 | // http://ionicframework.com/docs/theming/rtl-support/ 12 | $app-direction: ltr; 13 | 14 | 15 | @import "ionic.globals"; 16 | 17 | 18 | // Shared Variables 19 | // -------------------------------------------------- 20 | // To customize the look and feel of this app, you can override 21 | // the Sass variables found in Ionic's source scss files. 22 | // To view all the possible Ionic variables, see: 23 | // http://ionicframework.com/docs/theming/overriding-ionic-variables/ 24 | 25 | 26 | 27 | 28 | // Named Color Variables 29 | // -------------------------------------------------- 30 | // Named colors makes it easy to reuse colors on various components. 31 | // It's highly recommended to change the default colors 32 | // to match your app's branding. Ionic uses a Sass map of 33 | // colors so you can add, rename and remove colors as needed. 34 | // The "primary" color is the only required color in the map. 35 | 36 | $colors: ( 37 | primary: #488aff, 38 | secondary: #32db64, 39 | danger: #f53d3d, 40 | light: #f4f4f4, 41 | dark: #222 42 | ); 43 | 44 | 45 | // App iOS Variables 46 | // -------------------------------------------------- 47 | // iOS only Sass variables can go here 48 | 49 | 50 | 51 | 52 | // App Material Design Variables 53 | // -------------------------------------------------- 54 | // Material Design only Sass variables can go here 55 | 56 | 57 | 58 | 59 | // App Windows Variables 60 | // -------------------------------------------------- 61 | // Windows only Sass variables can go here 62 | 63 | 64 | 65 | 66 | // App Theme 67 | // -------------------------------------------------- 68 | // Ionic apps can have different themes applied, which can 69 | // then be future customized. This import comes last 70 | // so that the above variables are used and Ionic's 71 | // default are overridden. 72 | 73 | @import "ionic.theme.default"; 74 | 75 | 76 | // Ionicons 77 | // -------------------------------------------------- 78 | // The premium icon font for Ionic. For more info, please see: 79 | // http://ionicframework.com/docs/ionicons/ 80 | 81 | @import "ionic.ionicons"; 82 | 83 | 84 | // Fonts 85 | // -------------------------------------------------- 86 | 87 | @import "roboto"; 88 | @import "noto-sans"; 89 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": [ 8 | "dom", 9 | "es2015" 10 | ], 11 | "module": "es2015", 12 | "moduleResolution": "node", 13 | "sourceMap": true, 14 | "target": "es5", 15 | "typeRoots": [ 16 | "node_modules/@types" 17 | ] 18 | }, 19 | "include": [ 20 | "src/**/*.ts" 21 | ], 22 | "exclude": [ 23 | "node_modules" 24 | ], 25 | "compileOnSave": false, 26 | "atom": { 27 | "rewriteTsconfig": false 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-duplicate-variable": true, 4 | "no-unused-variable": [ 5 | true 6 | ] 7 | }, 8 | "rulesDirectory": [ 9 | "node_modules/tslint-eslint-rules/dist/rules" 10 | ] 11 | } 12 | --------------------------------------------------------------------------------