Switched to a typeorm-friendlier structure
This commit is contained in:
parent
4b26e5cb62
commit
598ce8c518
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"type": "postgres",
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"username": "test",
|
||||
"password": "test",
|
||||
"database": "test",
|
||||
"synchronize": true,
|
||||
"logging": false,
|
||||
"entities": [
|
||||
"src/entity/**/*.ts"
|
||||
],
|
||||
"migrations": [
|
||||
"src/migration/**/*.ts"
|
||||
],
|
||||
"subscribers": [
|
||||
"src/subscriber/**/*.ts"
|
||||
],
|
||||
"cli": {
|
||||
"entitiesDir": "src/entity",
|
||||
"migrationsDir": "src/migration",
|
||||
"subscribersDir": "src/subscriber"
|
||||
}
|
||||
}
|
47
package.json
47
package.json
|
@ -1,22 +1,29 @@
|
|||
{
|
||||
"name": "samurai",
|
||||
"version": "0.0.1",
|
||||
"description": "Our own Invoice Stuff",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.odit.services:odit/samurai-next.git"
|
||||
},
|
||||
"keywords": [
|
||||
"invoice",
|
||||
"crm"
|
||||
],
|
||||
"author": "ODIT.Services",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"typeorm": "^0.2.29"
|
||||
}
|
||||
"name": "samurai",
|
||||
"version": "0.0.1",
|
||||
"description": "Our own Invoice Stuff",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"dev": "ts-node src/index.ts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.odit.services:odit/samurai-next.git"
|
||||
},
|
||||
"keywords": [
|
||||
"invoice",
|
||||
"crm"
|
||||
],
|
||||
"author": "ODIT.Services",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"pg": "^8.4.2",
|
||||
"reflect-metadata": "^0.1.10",
|
||||
"typeorm": "0.2.29"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^8.0.29",
|
||||
"ts-node": "3.3.0",
|
||||
"typescript": "3.3.3333"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export class Address {
|
|||
street: string;
|
||||
|
||||
@Column()
|
||||
housenumber: string;
|
||||
number: string;
|
||||
|
||||
@Column()
|
||||
city: string;
|
|
@ -1,4 +1,4 @@
|
|||
import {Entity, PrimaryGeneratedColumn, Column, JoinColumn} from "typeorm";
|
||||
import {Entity, PrimaryGeneratedColumn, Column, JoinColumn, OneToOne} from "typeorm";
|
||||
import {Address} from "./Address";
|
||||
|
||||
@Entity()
|
||||
|
@ -14,7 +14,6 @@ export class Customer {
|
|||
lastName: string;
|
||||
|
||||
@OneToOne(() => Address)
|
||||
@JoinColumn
|
||||
@Column()
|
||||
@JoinColumn()
|
||||
invoiceAddress: Address;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
import "reflect-metadata";
|
||||
import {createConnection} from "typeorm";
|
||||
import {Address} from "./entity/Address";
|
||||
|
||||
createConnection().then(async connection => {
|
||||
|
||||
console.log("Inserting a new user into the database...");
|
||||
const addr = new Address();
|
||||
addr.street = "Test";
|
||||
addr.number = "1";
|
||||
addr.city = "herzo";
|
||||
addr.plz = "91074";
|
||||
addr.state = "Franken";
|
||||
addr.country = "Germany"
|
||||
await connection.manager.save(addr);
|
||||
console.log("Saved a new addr with id: " + addr.id);
|
||||
|
||||
console.log("Loading addr from the database...");
|
||||
const addrs = await connection.manager.find(Address);
|
||||
console.log("Loaded addr: ", addrs);
|
||||
|
||||
}).catch(error => console.log(error));
|
|
@ -1,36 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es5", "es6"],
|
||||
"outDir": "build/compiled",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": true,
|
||||
"noImplicitAny": true,
|
||||
"declaration": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"stripInternal": true,
|
||||
"pretty": true,
|
||||
"strictNullChecks": true,
|
||||
"noUnusedLocals": true,
|
||||
"downlevelIteration": true
|
||||
},
|
||||
"include": [
|
||||
"sample",
|
||||
"src",
|
||||
"test",
|
||||
"models"
|
||||
],
|
||||
"exclude": [
|
||||
"tmp",
|
||||
"temp",
|
||||
"build",
|
||||
"node_modules"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"es5",
|
||||
"es6"
|
||||
],
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./build",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
Reference in New Issue