feat:服务模版 抽离

This commit is contained in:
‘Liammcl’
2024-12-27 01:10:16 +08:00
parent bde0a8fd65
commit b9ea7218e3
16 changed files with 1078 additions and 883 deletions

View File

@@ -64,20 +64,28 @@ class SupabaseService {
}
}
// 通用 UPDATE 请求
// 优化 UPDATE 请求
async update(table, match, updates) {
try {
const { data, error } = await supabase
let query = supabase
.from(table)
.update(updates)
.match(match)
.select()
.update(updates);
if (error) throw error
return data
// 如果是对象,使用 match 方法
if (typeof match === 'object') {
query = query.match(match);
} else {
// 如果是单个 id使用 eq 方法
query = query.eq('id', match);
}
const { data, error } = await query.select();
if (error) throw error;
return data;
} catch (error) {
console.error(`Error updating ${table}:`, error.message)
throw error
console.error(`Error updating ${table}:`, error.message);
throw error;
}
}