ArsenyYankovsky / typeorm-aurora-data-api-driver

A bridge between TypeORM and Aurora Data API
MIT License
175 stars 38 forks source link

fix: strictly compare parameter value to undefined #124

Closed CorentinDoue closed 2 years ago

CorentinDoue commented 2 years ago

fix https://github.com/ArsenyYankovsky/typeorm-aurora-data-api-driver/issues/83

At least it fixes the usage of empty sets:

  @Column({ type: 'set', enum: enumValues(NetworkType)})
  networkType: NetworkType[];

An empty array [] is transformed in empty string '' by typeorm. The parameter is { value: '' } which fails this condition https://github.com/ArsenyYankovsky/typeorm-aurora-data-api-driver/blob/c01d226382ff700f7986f75ae3078ef6aa7ce92a/src/query-transformer/mysql-query-transformer.ts#L154

The resulting parameter is

{
 name: "param_1",
 value: {
   value: '',
 },
}

which breaks later because it is invalid


console.error                                                                                                                                                                                                    
    Error: 'param_1' is an invalid type                                                                                                                                                                            
        at error (node_modules/typeorm-aurora-data-api-driver/node_modules/data-api-client/index.js:39:35)                                                                      
        at formatType (node_modules/typeorm-aurora-data-api-driver/node_modules/data-api-client/index.js:215:4)                                                                 
        at formatParam (node_modules/typeorm-aurora-data-api-driver/dist/typeorm-aurora-data-api-driver.umd.js:481:48)                                                          
        at node_modules/typeorm-aurora-data-api-driver/node_modules/data-api-client/index.js:136:20     
ArsenyYankovsky commented 2 years ago

I'm sorry I haven't had the time to check this earlier. Closing in the favor of #125 as it added tests as well.