#author("2022-11-19T08:56:02+00:00","default:wikiadmin","wikiadmin") -TypeScriptのOR Mapper *チート集 [#t0bdbe1d] |SQL直実行|dataSource.query()|配列が戻り値| |カウント|dataSource.getRepository(Trips).count({ where: { carId: carId } })|条件付けないならcount()| |where条件直記載|dataSource.getRepository(PosRecords).count({where: {recorded: Raw((alias) => `${alias} between :from AND :to`,{from: '2022-10-1', to: '2022-11-1'})}});|toとfromをパラメータ化| *参考サイト [#c238c89a] **ManyToMany [#x42985f8] https://zenn.dev/msksgm/articles/20211124-typeorm-many2many 自然に任せると勝手にテーブル推定してわけわからんので指定すること!StoreテーブルのPrefectureがこれ! @ManyToMany(() => Prefecture) @JoinTable({ name: "store_prefecture", // table name for the junction table of this relation joinColumn: { name: "store_id", referencedColumnName: "id" }, inverseJoinColumn: { name: "prefecture_id", referencedColumnName: "id" } }) *トラブルシューティング [#y7ce6745] **migrationでdatetimeのデフォルト値エラー [#tbe63378] -CURRENT_TIMESTAMP(6)が生成される。 create table test (`created` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) -CURRENT_TIMESTAMP()ならOK create table test (`created` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) -同じ列の型がすべて揃ってないといけないので以下で解決 @UpdateDateColumn({ name: 'modified', type: 'datetime', width: 6, precision: 0})