commit
32a36cceff
444 files changed
+67186
No files matched your search
@@ -0,0 +1,31 @@
|
||||
const { query } = require('../database/db');
|
||||
|
||||
class FeedSackColumnConfig {
|
||||
static async get() {
|
||||
const result = await query('SELECT config FROM feed_sack_column_config ORDER BY id LIMIT 1');
|
||||
if (result.rows.length === 0) return null;
|
||||
return result.rows[0].config;
|
||||
}
|
||||
|
||||
static async save(config) {
|
||||
// Check if a row exists
|
||||
const existing = await query('SELECT id FROM feed_sack_column_config LIMIT 1');
|
||||
if (existing.rows.length === 0) {
|
||||
// Insert
|
||||
const result = await query(
|
||||
'INSERT INTO feed_sack_column_config (config) VALUES ($1) RETURNING config',
|
||||
[JSON.stringify(config)]
|
||||
);
|
||||
return result.rows[0].config;
|
||||
} else {
|
||||
// Update the existing row
|
||||
const result = await query(
|
||||
'UPDATE feed_sack_column_config SET config = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2 RETURNING config',
|
||||
[JSON.stringify(config), existing.rows[0].id]
|
||||
);
|
||||
return result.rows[0].config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FeedSackColumnConfig;
|
||||
Reference in new issue
Block a user