@ -748,13 +748,13 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
// MultiSelect to SingleSelect
if ( column . uidt === UITypes . MultiSelect && colBody . uidt === UITypes . SingleSelect ) {
if ( driverType === 'mysql' || driverType === 'mysql2' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = SUBSTRING_INDEX(??, ',', 1) WHERE ?? LIKE '%,%'; ` , [ table . table_name , column . titl e, column . titl e, column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = SUBSTRING_INDEX(??, ',', 1) WHERE ?? LIKE '%,%'; ` , [ table . table_name , column . column_nam e, column . column_nam e, column . column_nam e] ) ;
} else if ( driverType === 'pg' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = split_part(??, ',', 1); ` , [ table . table_name , column . titl e, column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = split_part(??, ',', 1); ` , [ table . table_name , column . column_nam e, column . column_nam e] ) ;
} else if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = LEFT(cast(?? as varchar(max)), CHARINDEX(',', ??) - 1) WHERE CHARINDEX(',', ??) > 0; ` , [ table . table_name , column . titl e, column . titl e, column . titl e, column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = LEFT(cast(?? as varchar(max)), CHARINDEX(',', ??) - 1) WHERE CHARINDEX(',', ??) > 0; ` , [ table . table_name , column . column_nam e, column . column_nam e, column . column_nam e, column . column_nam e] ) ;
} else if ( driverType === 'sqlite3' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = substr(??, 1, instr(??, ',') - 1) WHERE ?? LIKE '%,%'; ` , [ table . table_name , column . titl e, column . titl e, column . titl e, column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = substr(??, 1, instr(??, ',') - 1) WHERE ?? LIKE '%,%'; ` , [ table . table_name , column . column_nam e, column . column_nam e, column . column_nam e, column . column_nam e] ) ;
}
}
@ -811,19 +811,19 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
}
if ( column . uidt === UITypes . SingleSelect ) {
if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = NULL WHERE ?? LIKE ? ` , [ table . table_name , column . titl e, column . titl e, option . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = NULL WHERE ?? LIKE ? ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title ] ) ;
} else {
await baseModel . bulkUpdateAll ( { where : ` ( ${ column . titl e} ,eq, ${ option . title } ) ` } , { [ column . titl e] : null } ) ;
await baseModel . bulkUpdateAll ( { where : ` ( ${ column . column_nam e} ,eq, ${ option . title } ) ` } , { [ column . column_nam e] : null } ) ;
}
} else if ( column . uidt === UITypes . MultiSelect ) {
if ( driverType === 'mysql' || driverType === 'mysql2' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), ',')) WHERE FIND_IN_SET(?, ??) ` , [ table . table_name , column . titl e, column . titl e, option . title , option . title , column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), ',')) WHERE FIND_IN_SET(?, ??) ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title , option . title , column . column_nam e] ) ;
} else if ( driverType === 'pg' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = array_to_string(array_remove(string_to_array(??, ','), ?), ',') ` , [ table . table_name , column . titl e, column . titl e, option . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = array_to_string(array_remove(string_to_array(??, ','), ?), ',') ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title ] ) ;
} else if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = substring(replace(concat(',', ??, ','), concat(',', ?, ','), ','), 2, len(replace(concat(',', ??, ','), concat(',', ?, ','), ',')) - 2) ` , [ table . table_name , column . titl e, column . titl e, option . title , column . titl e, option . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = substring(replace(concat(',', ??, ','), concat(',', ?, ','), ','), 2, len(replace(concat(',', ??, ','), concat(',', ?, ','), ',')) - 2) ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title , column . column_nam e, option . title ] ) ;
} else if ( driverType === 'sqlite3' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(REPLACE(',' || ?? || ',', ',' || ? || ',', ','), ',') ` , [ table . table_name , column . titl e, column . titl e, option . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(REPLACE(',' || ?? || ',', ',' || ? || ',', ','), ',') ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title ] ) ;
}
}
}
@ -909,19 +909,19 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
if ( column . uidt === UITypes . SingleSelect ) {
if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = ? WHERE ?? LIKE ? ` , [ table . table_name , column . titl e, newOp . title , column . titl e, option . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = ? WHERE ?? LIKE ? ` , [ table . table_name , column . column_nam e, newOp . title , column . column_nam e, option . title ] ) ;
} else {
await baseModel . bulkUpdateAll ( { where : ` ( ${ column . titl e} ,eq, ${ option . title } ) ` } , { [ column . titl e] : newOp . title } ) ;
await baseModel . bulkUpdateAll ( { where : ` ( ${ column . column_nam e} ,eq, ${ option . title } ) ` } , { [ column . column_nam e] : newOp . title } ) ;
}
} else if ( column . uidt === UITypes . MultiSelect ) {
if ( driverType === 'mysql' || driverType === 'mysql2' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??) ` , [ table . table_name , column . titl e, column . titl e, option . title , newOp . title , option . title , column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??) ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title , newOp . title , option . title , column . column_nam e] ) ;
} else if ( driverType === 'pg' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = array_to_string(array_replace(string_to_array(??, ','), ?, ?), ',') ` , [ table . table_name , column . titl e, column . titl e, option . title , newOp . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = array_to_string(array_replace(string_to_array(??, ','), ?, ?), ',') ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title , newOp . title ] ) ;
} else if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = substring(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ',')), 2, len(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ','))) - 2) ` , [ table . table_name , column . titl e, column . titl e, option . title , newOp . title , column . titl e, option . title , newOp . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = substring(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ',')), 2, len(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ','))) - 2) ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title , newOp . title , column . column_nam e, option . title , newOp . title ] ) ;
} else if ( driverType === 'sqlite3' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(REPLACE(',' || ?? || ',', ',' || ? || ',', ',' || ? || ','), ',') ` , [ table . table_name , column . titl e, column . titl e, option . title , newOp . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(REPLACE(',' || ?? || ',', ',' || ? || ',', ',' || ? || ','), ',') ` , [ table . table_name , column . column_nam e, column . column_nam e, option . title , newOp . title ] ) ;
}
}
}
@ -930,19 +930,19 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
let newOp = ch . def_option ;
if ( column . uidt === UITypes . SingleSelect ) {
if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = ? WHERE ?? LIKE ? ` , [ table . table_name , column . titl e, newOp . title , column . titl e, ch . temp_title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = ? WHERE ?? LIKE ? ` , [ table . table_name , column . column_nam e, newOp . title , column . column_nam e, ch . temp_title ] ) ;
} else {
await baseModel . bulkUpdateAll ( { where : ` ( ${ column . titl e} ,eq, ${ ch . temp_title } ) ` } , { [ column . titl e] : newOp . title } ) ;
await baseModel . bulkUpdateAll ( { where : ` ( ${ column . column_nam e} ,eq, ${ ch . temp_title } ) ` } , { [ column . column_nam e] : newOp . title } ) ;
}
} else if ( column . uidt === UITypes . MultiSelect ) {
if ( driverType === 'mysql' || driverType === 'mysql2' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??) ` , [ table . table_name , column . titl e, column . titl e, ch . temp_title , newOp . title , ch . temp_title , column . titl e] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??) ` , [ table . table_name , column . column_nam e, column . column_nam e, ch . temp_title , newOp . title , ch . temp_title , column . column_nam e] ) ;
} else if ( driverType === 'pg' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = array_to_string(array_replace(string_to_array(??, ','), ?, ?), ',') ` , [ table . table_name , column . titl e, column . titl e, ch . temp_title , newOp . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = array_to_string(array_replace(string_to_array(??, ','), ?, ?), ',') ` , [ table . table_name , column . column_nam e, column . column_nam e, ch . temp_title , newOp . title ] ) ;
} else if ( driverType === 'mssql' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = substring(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ',')), 2, len(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ','))) - 2) ` , [ table . table_name , column . titl e, column . titl e, ch . temp_title , newOp . title , column . titl e, ch . temp_title , newOp . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = substring(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ',')), 2, len(replace(concat(',', ??, ','), concat(',', ?, ','), concat(',', ?, ','))) - 2) ` , [ table . table_name , column . column_nam e, column . column_nam e, ch . temp_title , newOp . title , column . column_nam e, ch . temp_title , newOp . title ] ) ;
} else if ( driverType === 'sqlite3' ) {
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(REPLACE(',' || ?? || ',', ',' || ? || ',', ',' || ? || ','), ',') ` , [ table . table_name , column . titl e, column . titl e, ch . temp_title , newOp . title ] ) ;
await dbDriver . raw ( ` UPDATE ?? SET ?? = TRIM(REPLACE(',' || ?? || ',', ',' || ? || ',', ',' || ? || ','), ',') ` , [ table . table_name , column . column_nam e, column . column_nam e, ch . temp_title , newOp . title ] ) ;
}
}
}