import db from "../index.js" class SiteConfigModel { // 获取指定key的配置 static async get(key) { const row = await db("site_config").where({ key }).first() return row ? row.value : null } // 设置指定key的配置(有则更新,无则插入) static async set(key, value) { const exists = await db("site_config").where({ key }).first() if (exists) { await db("site_config").where({ key }).update({ value, updated_at: db.fn.now() }) } else { await db("site_config").insert({ key, value }) } } // 批量获取多个key的配置 static async getMany(keys) { const rows = await db("site_config").whereIn("key", keys) const result = {} rows.forEach(row => { result[row.key] = row.value }) return result } // 获取所有配置 static async getAll() { const rows = await db("site_config").select("key", "value") const result = {} rows.forEach(row => { result[row.key] = row.value }) return result } } export default SiteConfigModel export { SiteConfigModel }