Skip to content

Commit

Permalink
Merge pull request #262 from morishin/fix-duplicate-query
Browse files Browse the repository at this point in the history
  • Loading branch information
morishin authored Jun 13, 2023
2 parents 28a6931 + fa4214d commit 9e799d5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib/Database/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ export default class Query {
return query;
}

static async create(title: string, dataSourceId: number, body: string): Promise<QueryType> {
static async create(
title: string,
dataSourceId: number,
body: string
): Promise<Pick<QueryType, "id" | "title" | "body" | "dataSourceId" | "createdAt">> {
const now = moment();
const nowAsString = now.format("YYYY-MM-DD HH:mm:ss");

const sql = `
insert into queries
(dataSourceId, title, updatedAt, createdAt)
values (?, ?, "${nowAsString}", "${nowAsString}")
(dataSourceId, title, body, createdAt, updatedAt)
values (?, ?, ?, "${nowAsString}", "${nowAsString}")
`;
const id = await connection.insert(sql, dataSourceId, title);
const id = await connection.insert(sql, dataSourceId, title, body);

return { id, dataSourceId, title, body, createdAt: now, updatedAt: now };
return { id, dataSourceId, title, body, createdAt: now };
}

static update(id: number, params: Partial<DatabaseQueryType>): Promise<void> {
Expand Down

0 comments on commit 9e799d5

Please sign in to comment.