11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nestjsで既存のDBテーブル構造を使う方法

11
Posted at

※ 備忘録

nestjs、AngularやIonic Frameworkととても親和性の高いフレームワークなのですが、ORMを使おうと思うとtableスキーマをローカルに持つ必要があります。新規プロジェクトだとそれでいいのですが、既存プロジェクトだとつらい単純作業になりますよね。

そこで、typeorm-model-generatorを使って、自動生成してしまいましょう。

使い方

npmでインストールして使います。

$npm i typeorm-model-generator -g

そうしたら typeorm-model-generator コマンドを使えるようになりますので、nestjsのプロジェクトトップディレクトリに移動して

$ typeorm-model-generator -h <host> -d <database> -p [port] -u <user> -x
[password] -e [engine]

と入力すれば、table構造を読み取ってoutput/フォルダを自動生成します。例えばローカルのDBNameというデータベースからtable構造を読み取るなら

$ typeorm-model-generator -h 127.0.0.1 -d DBName -p 3306 -u root -x root -e mysql 

となります。便利ですね。

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?