xialvjun / ts-sql-plugin

TypeScript Language Service Plugin for SQL with a tagged template strings SQL builder.

Repository from Github https://github.comxialvjun/ts-sql-pluginRepository from Github https://github.comxialvjun/ts-sql-plugin

sql.ins, sql.upd incorrect work with conditions

darky opened this issue · comments

Example:

sql.ins({
  ...someCheck ? {
    some_field: value // here correct database check
  } : {
    some_wrong_field: value // no database check
  }
})

Temporary workaround:

sql.ins({
  ...someCheck ? {
    some_field: value // here correct database check
  } : {},
  ...!someCheck ? {
    some_other_field: value // here correct database check
  } : {}
})

do it like

db.query(sql`insert into person ${someCheck ? sql.ins({ some_field: value }) : sql.ins({ some_other_field: value })}`);

Great thanks!