query store CRUD
This commit is contained in:
parent
2518a1046f
commit
7497787ae4
12 changed files with 327 additions and 5 deletions
12
src/command/queryStoreCommand.ts
Normal file
12
src/command/queryStoreCommand.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
export interface CreateQueryStoreCommand {
|
||||
query: string;
|
||||
}
|
||||
|
||||
export interface UpdateQueryStoreCommand {
|
||||
id: number;
|
||||
query: string;
|
||||
}
|
||||
|
||||
export interface DeleteQueryStoreCommand {
|
||||
id: number;
|
||||
}
|
66
src/command/queryStoreCommandHandler.ts
Normal file
66
src/command/queryStoreCommandHandler.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { query } from "../entity/query";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { CreateQueryStoreCommand, DeleteQueryStoreCommand, UpdateQueryStoreCommand } from "./queryStoreCommand";
|
||||
|
||||
export default abstract class QueryStoreCommandHandler {
|
||||
/**
|
||||
* @description create queryStore
|
||||
* @param CreateQueryStoreCommand
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createQueryStore: CreateQueryStoreCommand): Promise<number> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(query)
|
||||
.values({
|
||||
query: createQueryStore.query,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
return result.identifiers[0].id;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating queryStore", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update queryStore
|
||||
* @param UpdateQueryStoreCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateQueryStore: UpdateQueryStoreCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(query)
|
||||
.set({
|
||||
queryStore: updateQueryStore.query,
|
||||
})
|
||||
.where("id = :id", { id: updateQueryStore.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating queryStore", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete queryStore
|
||||
* @param DeleteQueryStoreCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletQueryStore: DeleteQueryStoreCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(query)
|
||||
.where("id = :id", { id: deletQueryStore.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting queryStore", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue