Skip to main content

Posts

Featured

When code doesn't communicate enough

 You have been assigned a code review, in Typescript, using Slonik to create semi-typed injection-safe SQL fragments. The purpose is to allow selecting rows where the foo column has a NULL value.  The following code: function getFooCondition(values: string[]) : FragmentSqlToken { return sql.fragment `foo = ANY( ${ sql.array(values, 'text' ) } )` ; } is being changed into this: function getFooCondition(values: (string | null)[]) : FragmentSqlToken { const parts: FragmentSqlToken[] = []; if (values.includes( null )) { parts.push(sql.fragment `foo IS NULL` ); values = values.filter((v) => v !== null ); } if (values.length) { parts.push(sql.fragment `foo = ANY( ${ sql.array(values, 'text' ) } )` ; } return sql.join(parts, ' OR ' ); } You check the tests, they look good, they add data to a testContainer database and verify that the condition works as expected. Test coverage is 100%. Stop and consider what criticism, if any, you ...

Latest Posts

Try jj vcs without risk in your git repo

If Agile isn't working, it's your fault

'Entity' is the wrong idea

Usability in programming language concept implementations

Using programming structures to communicate