Skip to content

Commit

Permalink
Extract objectToSQL.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Duvivier committed Nov 27, 2024
1 parent dae68e1 commit e83047a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/db/BadgeHubDataPostgresAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ import {
DBInsertAppMetadataJSON,
} from "@db/models/app/DBAppMetadataJSON";
import { DBCategory } from "@db/models/app/DBCategory";

function getInsertKeysAndValuesSql(user: Object) {
const definedEntries = getEntriesWithDefinedValues(user);
const keys = join(definedEntries.map(([key]) => raw(key))); // raw is ok here because these keys are checked against our typescript definitions by tsoa
const values = join(definedEntries.map(([, value]) => value));
return { keys, values };
}
import { getInsertKeysAndValuesSql } from "@db/sqlHelpers/objectToSQL";

function getUpdateAssigmentsSql(
definedEntries: Entry<Partial<Omit<ProjectCore, "slug">>>[]
Expand Down
9 changes: 9 additions & 0 deletions src/db/sqlHelpers/objectToSQL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getEntriesWithDefinedValues } from "@util/objectEntries";
import { join, raw } from "sql-template-tag";

export function getInsertKeysAndValuesSql(user: Object) {
const definedEntries = getEntriesWithDefinedValues(user);
const keys = join(definedEntries.map(([key]) => raw(key))); // raw is ok here because these keys are checked against our typescript definitions by tsoa
const values = join(definedEntries.map(([, value]) => value));
return { keys, values };
}

0 comments on commit e83047a

Please sign in to comment.