init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
const express = require('express');
|
||||
const mysql = require('mysql2');
|
||||
|
||||
const app = express();
|
||||
|
||||
const db = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
user: 'root',
|
||||
password: '12345678',
|
||||
database: 'popcen',
|
||||
|
||||
authPlugins: {
|
||||
'caching_sha2_password': mysql.authPlugins.caching_sha2_password
|
||||
}
|
||||
});
|
||||
|
||||
db.connect((err) => {
|
||||
if (err) {
|
||||
console.error('Database connection failed:', err.stack);
|
||||
return;
|
||||
}
|
||||
console.log('Connected to the MySQL database.');
|
||||
});
|
||||
|
||||
|
||||
app.get('/popcen', (req, res) => {
|
||||
|
||||
const caseidPattern = req.query.caseidPattern + '%';
|
||||
const batchno = parseInt(req.query.batchno, 10) || 1;
|
||||
const sql = 'SELECT id, uuid, caseid, modified_time FROM popcen WHERE caseid LIKE ? LIMIT ? OFFSET ?';
|
||||
const limit = 1000;
|
||||
const offset = (batchno - 1) * limit;
|
||||
db.query(sql, [caseidPattern, limit, offset], (err, results) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).send('Server error');
|
||||
}
|
||||
res.json(results);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.get('/popcenCount', (req, res) => {
|
||||
const caseidPattern = req.query.caseidPattern + '%';
|
||||
const sql = 'SELECT COUNT(id) AS count FROM popcen WHERE caseid LIKE ?';
|
||||
db.query(sql, [caseidPattern], (err, results) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).send('Server error');
|
||||
}
|
||||
res.json(results[0].count);
|
||||
});
|
||||
});
|
||||
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user