Add database entity
This commit is contained in:
parent
832f88fd85
commit
50c237f6fa
3 changed files with 51 additions and 0 deletions
9
database/3.3.0/1719856023429-CreateMoon/Up/01-Moon.sql
Normal file
9
database/3.3.0/1719856023429-CreateMoon/Up/01-Moon.sql
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
CREATE TABLE `moon` (
|
||||||
|
`Id` varchar(255) NOT NULL,
|
||||||
|
`WhenCreated` datetime NOT NULL,
|
||||||
|
`WhenUpdated` datetime NOT NULL,
|
||||||
|
`ServerId` varchar(255) NOT NULL,
|
||||||
|
`UserId` varchar(255) NOT NULL,
|
||||||
|
`Description` varchar(255) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||||
|
|
27
src/database/entities/Moon.ts
Normal file
27
src/database/entities/Moon.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { Column, Entity } from "typeorm";
|
||||||
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
|
import AppDataSource from "../dataSources/appDataSource";
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export default class Moon extends BaseEntity {
|
||||||
|
constructor(description: string, userId: string) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.Description = description;
|
||||||
|
this.UserId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
Description: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
UserId: string;
|
||||||
|
|
||||||
|
public static async FetchMoonsByUserId(userId: string): Promise<Moon[] | null> {
|
||||||
|
const repository = AppDataSource.getRepository(Moon);
|
||||||
|
|
||||||
|
const all = await repository.find({ where: { UserId: userId } });
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
}
|
15
src/database/migrations/3.3/1719856023429-CreateMoon.ts
Normal file
15
src/database/migrations/3.3/1719856023429-CreateMoon.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||||
|
import MigrationHelper from "../../../helpers/MigrationHelper"
|
||||||
|
|
||||||
|
export class CreateMoon1719856023429 implements MigrationInterface {
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
MigrationHelper.Up('1719856023429-CreateMoon', '3.3.0', [
|
||||||
|
"01-Moon",
|
||||||
|
], queryRunner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue