type holyshared = Engineer<mixed>

技術的なことなど色々

TypeORM 1.0へアップグレードする

TypeORMが1.0になりました。
このため、0.3系から1.0にアップグレートを行いました。

やったことは接続のオプションの型指定と検索時のリレーションの指定方法です。

コネクションの型指定をPostgresConnectionOptionsからPostgresDataSourceOptionsに変更する

変更前

import type { PostgresConnectionOptions } from "typeorm/driver/postgres/PostgresConnectionOptions";

const defaultOptions: PostgresConnectionOptions = {
  type: "postgres",
  database: "example",
  entities: [User],
  synchronize: false,
  logging: true,
  migrations: ["./migrations/*{.ts,.js}"]
};

変更後

import type { PostgresDataSourceOptions } from "typeorm/driver/postgres/PostgresDataSourceOptions";

const defaultOptions: PostgresDataSourceOptions = {
  type: "postgres",
  database: "example",
  entities: [User],
  synchronize: false,
  logging: true,
  migrations: ["./migrations/*{.ts,.js}"]
};

relationsの指定をオブジェクト指定に置き換える

変更前

const results = await repo.findAndCount({
  where: {
    id: "id"
  },
  relations: ["group", "group.owner"]
});

変更後

const results = await repo.findAndCount({
  where: {
    id: "id"
  },
  relations: {
    group: {
      owner: true,
    },
  }
});