const database = require("../modules/database") function create(key, productId, targetChannel) { const query = ` INSERT INTO licenses ( key, productId, targetChannel, status ) VALUES (?, ?, ?, 'active') ` const statement = database.prepare(query) return statement.run(key, productId, targetChannel) } function findByKey(key) { const query = ` SELECT id, key, productId, targetChannel, status, createdAt FROM licenses WHERE key = ? ` const statement = database.prepare(query) return statement.get(key) } function updateStatus(id, status) { const query = ` UPDATE licenses SET status = ? WHERE id = ? ` const statement = database.prepare(query) return statement.run(status, id) } function findByProduct(productId) { const query = ` SELECT * FROM licenses WHERE productId = ? ` const statement = database.prepare(query) return statement.all(productId) } function remove(id) { const query = ` DELETE FROM licenses WHERE id = ? ` const statement = database.prepare(query) return statement.run(id) } module.exports = { create, remove, findByKey, updateStatus, findByProduct, }