スキップしてメイン コンテンツに移動

投稿

ラベル(TypORM)が付いた投稿を表示しています

[Angular][Nest.js] Add TypeOrm

Intro This time I added TypeOrm into the Nest.js project. [Angular 10 + NgRx + Nest.js] Create project Use TypeOrm Install To use TypeOrm I installed some packages.  [PostgreSQL] Play with TypeORM 1   And to integrate the Nest.js project, I add an additional package. npm install --save @nestjs/typeorm typeorm pg Database | NestJS - A progressive Node.js framework Configuration Last time I used "ormconfig.json" for TypeOrm configuration. In Nest.js projects, I also could write them in "app.module.ts". server/app.module.ts import { Module } from '@nestjs/common'; import { AngularUniversalModule } from '@nestjs/ng-universal'; import { TypeOrmModule } from '@nestjs/typeorm'; import { join } from 'path'; import { Workflow } from './entities/workflow.entity'; @Module({ imports: [ AngularUniversalModule.forRoot({ viewsPath: join(process.cwd(), 'dist/browser'), bundle: require('../serve...

[PostgreSQL] Play with TypeORM 2

Intro In this post, I tried migration and setting foreign key. [PostgreSQL] Play with TypeORM 1 GitHub - typeorm/typeorm TypeORM - Amazing ORM for TypeScript and JavaScript (ES7, ES6, ES5). Migration To migrate tables, I created migration files by command. npx typeorm migration:create -n AddUpdateDate The file was created in src/migration. 1591186678545-AddUpdateDate.ts import {MigrationInterface, QueryRunner} from "typeorm"; export class AddUpdateDate1591186678545 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise<void> { } public async down(queryRunner: QueryRunner): Promise<void> { } } This time, I wanted to add "updateDate" column into "SampleUser" table. 1591186678545-AddUpdateDate.ts import {MigrationInterface, QueryRunner} from "typeorm"; export class AddUpdateDate1591186678545 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise<...

[PostgreSQL] Play with TypeORM 1

Intro This time, I tried accessing Database by TypeORM. Because I wanted to manage Database tables by ORM, I created a table first.  GitHub - typeorm/typeorm   TypeORM - Amazing ORM for TypeScript and JavaScript (ES7, ES6, ES5). Installation and creating a project Installation TypeORM needed "reflect-metadata" and database driver. npm install --save typeorm reflect-metadata pg typescript tsc npm install --save-dev @types/node And I also installed "ts-node" to skip compiling. npm install --save ts-node Preparing References I could generate a TypeORM project by TypeORM command. npx typeorm init --name gen-typeorm-sample --database postgres I refered Most of all settings from it. Adding files and folders First, I added tsconfig.json. npx tsc --init And I edited like below. tsconfig.json { "compilerOptions": { /* Basic Options */ "incremental": true, "target": "es5", "module": "comm...