feat:服务模版 抽离
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user