Skip to content

Commit 62f3d93

Browse files
author
Umed Khudoiberdiev
committed
added ormconfig.json file + added migrations and subscriber dirs
1 parent 35a53a2 commit 62f3d93

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
3. edit `./src/index.ts` and change your database configuration (you can also change a database type, but don't forget to install specific database drivers)
66
4. run `npm start`
77
5. enjoy!
8+
9+
## How to use CLI?
10+
11+
1. install `typeorm` globally: `npm i -g typeorm`
12+
2. run `typeorm -h` to show list of available commands

ormconfig.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
{
3+
"name": "default",
4+
"driver": {
5+
"type": "mysql",
6+
"host": "localhost",
7+
"port": 3306,
8+
"username": "test",
9+
"password": "test",
10+
"database": "test"
11+
},
12+
"autoSchemaSync": true,
13+
"entities": [
14+
"src/entity/*.js"
15+
],
16+
"subscribers": [
17+
"src/subscriber/*.js,"
18+
],
19+
"migrations": [
20+
"src/migration/*.js"
21+
],
22+
"cli": {
23+
"entitiesDir": "src/entity",
24+
"migrationsDir": "src/migration",
25+
"subscribersDir": "src/subscriber"
26+
}
27+
}
28+
]

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"typescript": "^2.0.2"
2727
},
2828
"dependencies": {
29-
"pg": "^6.1.0",
29+
"mysql": "^2.12.0",
3030
"reflect-metadata": "^0.1.8",
31-
"typeorm": "0.0.4"
31+
"typeorm": "0.0.5"
3232
},
3333
"scripts": {
3434
"start": "tsc && node src/index.js"

src/index.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,8 @@ import {createConnection} from "typeorm";
33
import {Post} from "./entity/Post";
44
import {Category} from "./entity/Category";
55

6-
createConnection({
7-
driver: {
8-
type: "postgres", // to use mysql instead, just change it to "mysql", change other params (port, credentials) and install driver: npm i mysql
9-
host: "localhost",
10-
port: 5432,
11-
username: "test",
12-
password: "test",
13-
database: "test"
14-
},
15-
entities: [
16-
Post,
17-
Category
18-
],
19-
autoSchemaSync: true
20-
}).then(async connection => {
6+
// connection settings are in the "ormconfig.json" file
7+
createConnection().then(async connection => {
218

229
const category1 = new Category();
2310
category1.name = "TypeScript";

src/migration/.gitkeep

Whitespace-only changes.

src/subscriber/.gitkeep

Whitespace-only changes.

tsconfig.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "2.0.2",
33
"compilerOptions": {
4-
"lib": ["es5", "es6", "dom"],
4+
"lib": ["es5", "es6"],
55
"target": "es6",
66
"module": "commonjs",
77
"moduleResolution": "node",
@@ -10,9 +10,6 @@
1010
"sourceMap": true
1111
},
1212
"exclude": [
13-
"build",
14-
"node_modules",
15-
"typings/browser.d.ts",
16-
"typings/browser"
13+
"node_modules"
1714
]
1815
}

0 commit comments

Comments
 (0)