Skip to content

Commit

Permalink
Use json queries for proposal field values
Browse files Browse the repository at this point in the history
Issue #821 Change our query approach to use DB-level json functions
  • Loading branch information
slifty committed May 10, 2024
1 parent 87c7991 commit 366a176
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/database/operations/create/createProposalFieldValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { db as defaultDb } from '../../db';
import type {
ProposalFieldValue,
InternallyWritableProposalFieldValue,
JsonResultSet,
} from '../../../types';

const createProposalFieldValue = async (
Expand All @@ -15,7 +16,7 @@ const createProposalFieldValue = async (
value,
isValid,
} = createValues;
const result = await db.sql<ProposalFieldValue>(
const result = await db.sql<JsonResultSet<ProposalFieldValue>>(
'proposalFieldValues.insertOne',
{
proposalVersionId,
Expand All @@ -25,7 +26,7 @@ const createProposalFieldValue = async (
isValid,
},
);
const object = result.rows[0];
const { object } = result.rows[0] ?? {};
if (object === undefined) {
throw new Error(

Check warning on line 31 in src/database/operations/create/createProposalFieldValue.ts

View check run for this annotation

Codecov / codecov/patch

src/database/operations/create/createProposalFieldValue.ts#L31

Added line #L31 was not covered by tests
'The entity creation did not appear to fail, but no data was returned by the operation.',
Expand Down
9 changes: 1 addition & 8 deletions src/database/queries/proposalFieldValues/insertOne.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@ INSERT INTO proposal_field_values (
:position,
:isValid
)
RETURNING
id as "id",
proposal_version_id as "proposalVersionId",
application_form_field_id as "applicationFormFieldId",
value as "value",
position as "position",
is_valid as "isValid",
created_at AS "createdAt"
RETURNING proposal_field_value_to_json(proposal_field_values) AS "object";

0 comments on commit 366a176

Please sign in to comment.