mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
chore: migrate version-history repository to kysely (#15267)
* chore: generate sql for version-history repository * chore: run kysely-codegen * chore: migrate version-history repository to kysely * fix: change `| null` to `| undefined` * chore: clean up unneeded async
This commit is contained in:
parent
beb31cebed
commit
cab201270c
4 changed files with 40 additions and 20 deletions
19
server/src/db.d.ts
vendored
19
server/src/db.d.ts
vendored
|
@ -62,6 +62,7 @@ export interface Albums {
|
|||
export interface AlbumsAssetsAssets {
|
||||
albumsId: string;
|
||||
assetsId: string;
|
||||
createdAt: Generated<Timestamp>;
|
||||
}
|
||||
|
||||
export interface AlbumsSharedUsersUsers {
|
||||
|
@ -201,7 +202,6 @@ export interface GeodataPlaces {
|
|||
admin2Name: string | null;
|
||||
alternateNames: string | null;
|
||||
countryCode: string;
|
||||
earthCoord: Generated<string | null>;
|
||||
id: number;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
|
@ -257,7 +257,7 @@ export interface NaturalearthCountries {
|
|||
admin: string;
|
||||
admin_a3: string;
|
||||
coordinates: string;
|
||||
id: Generated<number>;
|
||||
id: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
|
@ -311,13 +311,6 @@ export interface SharedLinks {
|
|||
userId: string;
|
||||
}
|
||||
|
||||
export interface SmartInfo {
|
||||
assetId: string;
|
||||
objects: string[] | null;
|
||||
smartInfoTextSearchableColumn: Generated<string>;
|
||||
tags: string[] | null;
|
||||
}
|
||||
|
||||
export interface SmartSearch {
|
||||
assetId: string;
|
||||
embedding: string;
|
||||
|
@ -399,6 +392,12 @@ export interface VectorsPgVectorIndexStat {
|
|||
tablerelid: number | null;
|
||||
}
|
||||
|
||||
export interface VersionHistory {
|
||||
createdAt: Generated<Timestamp>;
|
||||
id: Generated<string>;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export interface DB {
|
||||
activity: Activity;
|
||||
albums: Albums;
|
||||
|
@ -425,7 +424,6 @@ export interface DB {
|
|||
sessions: Sessions;
|
||||
shared_link__asset: SharedLinkAsset;
|
||||
shared_links: SharedLinks;
|
||||
smart_info: SmartInfo;
|
||||
smart_search: SmartSearch;
|
||||
socket_io_attachments: SocketIoAttachments;
|
||||
system_config: SystemConfig;
|
||||
|
@ -436,4 +434,5 @@ export interface DB {
|
|||
user_metadata: UserMetadata;
|
||||
users: Users;
|
||||
'vectors.pg_vector_index_stat': VectorsPgVectorIndexStat;
|
||||
version_history: VersionHistory;
|
||||
}
|
||||
|
|
|
@ -5,5 +5,5 @@ export const IVersionHistoryRepository = 'IVersionHistoryRepository';
|
|||
export interface IVersionHistoryRepository {
|
||||
create(version: Omit<VersionHistoryEntity, 'id' | 'createdAt'>): Promise<VersionHistoryEntity>;
|
||||
getAll(): Promise<VersionHistoryEntity[]>;
|
||||
getLatest(): Promise<VersionHistoryEntity | null>;
|
||||
getLatest(): Promise<VersionHistoryEntity | undefined>;
|
||||
}
|
||||
|
|
17
server/src/queries/version.history.repository.sql
Normal file
17
server/src/queries/version.history.repository.sql
Normal file
|
@ -0,0 +1,17 @@
|
|||
-- NOTE: This file is auto generated by ./sql-generator
|
||||
|
||||
-- VersionHistoryRepository.getAll
|
||||
select
|
||||
*
|
||||
from
|
||||
"version_history"
|
||||
order by
|
||||
"createdAt" desc
|
||||
|
||||
-- VersionHistoryRepository.getLatest
|
||||
select
|
||||
*
|
||||
from
|
||||
"version_history"
|
||||
order by
|
||||
"createdAt" desc
|
|
@ -1,23 +1,27 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Kysely } from 'kysely';
|
||||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import { DB } from 'src/db';
|
||||
import { DummyValue, GenerateSql } from 'src/decorators';
|
||||
import { VersionHistoryEntity } from 'src/entities/version-history.entity';
|
||||
import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class VersionHistoryRepository implements IVersionHistoryRepository {
|
||||
constructor(@InjectRepository(VersionHistoryEntity) private repository: Repository<VersionHistoryEntity>) {}
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
async getAll(): Promise<VersionHistoryEntity[]> {
|
||||
return this.repository.find({ order: { createdAt: 'DESC' } });
|
||||
@GenerateSql()
|
||||
getAll(): Promise<VersionHistoryEntity[]> {
|
||||
return this.db.selectFrom('version_history').selectAll().orderBy('createdAt', 'desc').execute();
|
||||
}
|
||||
|
||||
async getLatest(): Promise<VersionHistoryEntity | null> {
|
||||
const results = await this.repository.find({ order: { createdAt: 'DESC' }, take: 1 });
|
||||
return results[0] || null;
|
||||
@GenerateSql()
|
||||
getLatest(): Promise<VersionHistoryEntity | undefined> {
|
||||
return this.db.selectFrom('version_history').selectAll().orderBy('createdAt', 'desc').executeTakeFirst();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.STRING] })
|
||||
create(version: Omit<VersionHistoryEntity, 'id' | 'createdAt'>): Promise<VersionHistoryEntity> {
|
||||
return this.repository.save(version);
|
||||
return this.db.insertInto('version_history').values(version).returningAll().executeTakeFirstOrThrow();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue