--ระบบ ที่สมบูรของ search column และ condition
This commit is contained in:
@@ -54,7 +54,9 @@ export class GeneralService {
|
||||
|
||||
for (const [key, value] of Object.entries(conditions)) {
|
||||
if (value === undefined || value === null || value === '') continue
|
||||
|
||||
const match = String(value).match(/^(ILIKE|LIKE)\s+(.+)$/i)
|
||||
|
||||
if (match) {
|
||||
const operator = match[1].toUpperCase()
|
||||
const pattern = match[2].trim()
|
||||
@@ -69,6 +71,7 @@ export class GeneralService {
|
||||
|
||||
let finalQuery = baseQuery
|
||||
if (whereClauses.length > 0) finalQuery += ' AND ' + whereClauses.join(' AND ')
|
||||
|
||||
const formattedSQL = finalQuery.replace(/\${database}/g, database)
|
||||
|
||||
try {
|
||||
@@ -77,15 +80,20 @@ export class GeneralService {
|
||||
sql: formattedSQL,
|
||||
params
|
||||
})
|
||||
|
||||
const result = await connection.query(formattedSQL, params)
|
||||
|
||||
this.devhint(2, 'executeQueryConditions', `✅ Query Success (${result.rowCount} rows)`)
|
||||
return result.rows
|
||||
|
||||
return result.rows
|
||||
|
||||
} catch (err) {
|
||||
this.devhint(1, 'executeQueryConditions', `❌ SQL Error`, err.message)
|
||||
console.error('🧨 SQL Error:', err.message)
|
||||
throw new Error(`SQL_EXECUTION_FAILED::${err.message}`) // ✅ “เจ๊งจริง” ส่งถึง controller แน่นอน
|
||||
throw new Error(`SQL_EXECUTION_FAILED::${err.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// ===================================================
|
||||
// Export สำหรับ controller หรืออื่นๆ เรียกใช้ได้ด้วย
|
||||
|
||||
Reference in New Issue
Block a user