-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
import { BaseEntity } from './base.entity'; | ||
|
||
@Entity() | ||
@Index(['sessionId'], { unique: true }) | ||
export class ScSession extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
public readonly id: bigint; | ||
|
||
@Column({ type: 'varchar' }) | ||
public sessionId: string; | ||
|
||
@Column({ type: 'varchar' }) | ||
public data: string; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/migrations/1731076287218-CreateTableScSession1731076287218.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class CreateTableScSession1731076287218 implements MigrationInterface { | ||
name = 'CreateTableScSession1731076287218'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "sc_session" ("createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "id" SERIAL NOT NULL, "sessionId" character varying NOT NULL, "data" character varying NOT NULL, CONSTRAINT "PK_fb10d649e63815947580f4c6407" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query( | ||
`CREATE UNIQUE INDEX "IDX_c8eae9e5d612665913e4346081" ON "sc_session" ("sessionId") `, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`DROP INDEX "public"."IDX_c8eae9e5d612665913e4346081"`, | ||
); | ||
await queryRunner.query(`DROP TABLE "sc_session"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { ScSession } from 'src/entities/scSession.entity'; | ||
|
||
import { BaseRepository } from './base.repository'; | ||
import { UnitOfWork } from '../unitOfWork'; | ||
|
||
@Injectable() | ||
export class ScSessionRepository extends BaseRepository<ScSession> { | ||
public constructor(unitOfWork: UnitOfWork) { | ||
super(ScSession, unitOfWork); | ||
} | ||
|
||
async getData(sessionId: string): Promise<string> { | ||
const res = await this.findOneBy({ sessionId }); | ||
return res?.data ?? ''; | ||
} | ||
|
||
async setData(sessionId: string, data: string): Promise<void> { | ||
return await this.upsert({ sessionId, data }, true, ['sessionId']); | ||
} | ||
} |