forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Move more
typeorm
operators to repositories (no-cha…
…ngelog) (n8n-io#8143) Follow-up to n8n-io#8139
- Loading branch information
Showing
11 changed files
with
82 additions
and
56 deletions.
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
31 changes: 30 additions & 1 deletion
31
packages/cli/src/databases/repositories/credentials.repository.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 |
---|---|---|
@@ -1,10 +1,39 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { | ||
DataSource, | ||
In, | ||
Not, | ||
Repository, | ||
type DeleteResult, | ||
type EntityManager, | ||
type FindOptionsWhere, | ||
Like, | ||
} from 'typeorm'; | ||
import { CredentialsEntity } from '../entities/CredentialsEntity'; | ||
import { SharedCredentials } from '../entities/SharedCredentials'; | ||
|
||
@Service() | ||
export class CredentialsRepository extends Repository<CredentialsEntity> { | ||
constructor(dataSource: DataSource) { | ||
super(CredentialsEntity, dataSource.manager); | ||
} | ||
|
||
async pruneSharings( | ||
transaction: EntityManager, | ||
credentialId: string, | ||
userIds: string[], | ||
): Promise<DeleteResult> { | ||
const conditions: FindOptionsWhere<SharedCredentials> = { | ||
credentialsId: credentialId, | ||
userId: Not(In(userIds)), | ||
}; | ||
return transaction.delete(SharedCredentials, conditions); | ||
} | ||
|
||
async findStartingWith(credentialName: string) { | ||
return this.find({ | ||
select: ['name'], | ||
where: { name: Like(`${credentialName}%`) }, | ||
}); | ||
} | ||
} |
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
11 changes: 10 additions & 1 deletion
11
packages/cli/src/databases/repositories/executionData.repository.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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { DataSource, In, Repository } from 'typeorm'; | ||
import { ExecutionData } from '../entities/ExecutionData'; | ||
|
||
@Service() | ||
export class ExecutionDataRepository extends Repository<ExecutionData> { | ||
constructor(dataSource: DataSource) { | ||
super(ExecutionData, dataSource.manager); | ||
} | ||
|
||
async findByExecutionIds(executionIds: string[]) { | ||
return this.find({ | ||
select: ['workflowData'], | ||
where: { | ||
executionId: In(executionIds), | ||
}, | ||
}).then((executionData) => executionData.map(({ workflowData }) => workflowData)); | ||
} | ||
} |
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
6 changes: 5 additions & 1 deletion
6
packages/cli/src/databases/repositories/workflowHistory.repository.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { DataSource, LessThan, Repository } from 'typeorm'; | ||
import { WorkflowHistory } from '../entities/WorkflowHistory'; | ||
|
||
@Service() | ||
export class WorkflowHistoryRepository extends Repository<WorkflowHistory> { | ||
constructor(dataSource: DataSource) { | ||
super(WorkflowHistory, dataSource.manager); | ||
} | ||
|
||
async deleteEarlierThan(date: Date) { | ||
return this.delete({ createdAt: LessThan(date) }); | ||
} | ||
} |
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