mirror of
https://github.com/immich-app/immich.git
synced 2026-03-04 09:57:33 +03:00
feat: rename schema (#19891)
This commit is contained in:
@@ -21,50 +21,50 @@ export class LibraryRepository {
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
get(id: string, withDeleted = false) {
|
||||
return this.db
|
||||
.selectFrom('libraries')
|
||||
.selectAll('libraries')
|
||||
.where('libraries.id', '=', id)
|
||||
.$if(!withDeleted, (qb) => qb.where('libraries.deletedAt', 'is', null))
|
||||
.selectFrom('library')
|
||||
.selectAll('library')
|
||||
.where('library.id', '=', id)
|
||||
.$if(!withDeleted, (qb) => qb.where('library.deletedAt', 'is', null))
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [] })
|
||||
getAll(withDeleted = false) {
|
||||
return this.db
|
||||
.selectFrom('libraries')
|
||||
.selectAll('libraries')
|
||||
.selectFrom('library')
|
||||
.selectAll('library')
|
||||
.orderBy('createdAt', 'asc')
|
||||
.$if(!withDeleted, (qb) => qb.where('libraries.deletedAt', 'is', null))
|
||||
.$if(!withDeleted, (qb) => qb.where('library.deletedAt', 'is', null))
|
||||
.execute();
|
||||
}
|
||||
|
||||
@GenerateSql()
|
||||
getAllDeleted() {
|
||||
return this.db
|
||||
.selectFrom('libraries')
|
||||
.selectAll('libraries')
|
||||
.where('libraries.deletedAt', 'is not', null)
|
||||
.selectFrom('library')
|
||||
.selectAll('library')
|
||||
.where('library.deletedAt', 'is not', null)
|
||||
.orderBy('createdAt', 'asc')
|
||||
.execute();
|
||||
}
|
||||
|
||||
create(library: Insertable<LibraryTable>) {
|
||||
return this.db.insertInto('libraries').values(library).returningAll().executeTakeFirstOrThrow();
|
||||
return this.db.insertInto('library').values(library).returningAll().executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
await this.db.deleteFrom('libraries').where('libraries.id', '=', id).execute();
|
||||
await this.db.deleteFrom('library').where('library.id', '=', id).execute();
|
||||
}
|
||||
|
||||
async softDelete(id: string) {
|
||||
await this.db.updateTable('libraries').set({ deletedAt: new Date() }).where('libraries.id', '=', id).execute();
|
||||
await this.db.updateTable('library').set({ deletedAt: new Date() }).where('library.id', '=', id).execute();
|
||||
}
|
||||
|
||||
update(id: string, library: Updateable<LibraryTable>) {
|
||||
return this.db
|
||||
.updateTable('libraries')
|
||||
.updateTable('library')
|
||||
.set(library)
|
||||
.where('libraries.id', '=', id)
|
||||
.where('library.id', '=', id)
|
||||
.returningAll()
|
||||
.executeTakeFirstOrThrow();
|
||||
}
|
||||
@@ -72,14 +72,14 @@ export class LibraryRepository {
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
async getStatistics(id: string): Promise<LibraryStatsResponseDto | undefined> {
|
||||
const stats = await this.db
|
||||
.selectFrom('libraries')
|
||||
.innerJoin('assets', 'assets.libraryId', 'libraries.id')
|
||||
.leftJoin('exif', 'exif.assetId', 'assets.id')
|
||||
.selectFrom('library')
|
||||
.innerJoin('asset', 'asset.libraryId', 'library.id')
|
||||
.leftJoin('asset_exif', 'asset_exif.assetId', 'asset.id')
|
||||
.select((eb) =>
|
||||
eb.fn
|
||||
.countAll<number>()
|
||||
.filterWhere((eb) =>
|
||||
eb.and([eb('assets.type', '=', AssetType.IMAGE), eb('assets.visibility', '!=', AssetVisibility.HIDDEN)]),
|
||||
eb.and([eb('asset.type', '=', AssetType.IMAGE), eb('asset.visibility', '!=', AssetVisibility.HIDDEN)]),
|
||||
)
|
||||
.as('photos'),
|
||||
)
|
||||
@@ -87,25 +87,25 @@ export class LibraryRepository {
|
||||
eb.fn
|
||||
.countAll<number>()
|
||||
.filterWhere((eb) =>
|
||||
eb.and([eb('assets.type', '=', AssetType.VIDEO), eb('assets.visibility', '!=', AssetVisibility.HIDDEN)]),
|
||||
eb.and([eb('asset.type', '=', AssetType.VIDEO), eb('asset.visibility', '!=', AssetVisibility.HIDDEN)]),
|
||||
)
|
||||
.as('videos'),
|
||||
)
|
||||
.select((eb) => eb.fn.coalesce((eb) => eb.fn.sum('exif.fileSizeInByte'), eb.val(0)).as('usage'))
|
||||
.groupBy('libraries.id')
|
||||
.where('libraries.id', '=', id)
|
||||
.select((eb) => eb.fn.coalesce((eb) => eb.fn.sum('asset_exif.fileSizeInByte'), eb.val(0)).as('usage'))
|
||||
.groupBy('library.id')
|
||||
.where('library.id', '=', id)
|
||||
.executeTakeFirst();
|
||||
|
||||
// possibly a new library with 0 assets
|
||||
if (!stats) {
|
||||
const zero = sql<number>`0::int`;
|
||||
return this.db
|
||||
.selectFrom('libraries')
|
||||
.selectFrom('library')
|
||||
.select(zero.as('photos'))
|
||||
.select(zero.as('videos'))
|
||||
.select(zero.as('usage'))
|
||||
.select(zero.as('total'))
|
||||
.where('libraries.id', '=', id)
|
||||
.where('library.id', '=', id)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
@@ -118,6 +118,6 @@ export class LibraryRepository {
|
||||
}
|
||||
|
||||
streamAssetIds(libraryId: string) {
|
||||
return this.db.selectFrom('assets').select(['id']).where('libraryId', '=', libraryId).stream();
|
||||
return this.db.selectFrom('asset').select(['id']).where('libraryId', '=', libraryId).stream();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user