mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
Tools: Add DB insert test script
This commit is contained in:
52
test_db_insert.js
Normal file
52
test_db_insert.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
const config = require('./lib/db-config');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
|
// Force localhost
|
||||||
|
config.host = 'localhost';
|
||||||
|
config.password = 'X@gon2005!#$';
|
||||||
|
|
||||||
|
const pool = new Pool(config);
|
||||||
|
|
||||||
|
async function testInsert() {
|
||||||
|
console.log('🧪 Testing Manual Insert...');
|
||||||
|
const client = await pool.connect();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const testId = uuidv4();
|
||||||
|
const query = `
|
||||||
|
INSERT INTO test_results (
|
||||||
|
id, url, user_uuid, is_mobile,
|
||||||
|
scores, metrics, filmstrip, timestamp
|
||||||
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, NOW())
|
||||||
|
RETURNING id
|
||||||
|
`;
|
||||||
|
|
||||||
|
const values = [
|
||||||
|
testId,
|
||||||
|
'https://example.com',
|
||||||
|
'test-user-uuid',
|
||||||
|
false,
|
||||||
|
JSON.stringify({ performance: 100 }),
|
||||||
|
JSON.stringify({ lcp: 500 }),
|
||||||
|
JSON.stringify([])
|
||||||
|
];
|
||||||
|
|
||||||
|
console.log('📝 Executing Query:', query);
|
||||||
|
console.log('📄 Values:', values);
|
||||||
|
|
||||||
|
const res = await client.query(query, values);
|
||||||
|
console.log('✅ Insert Successful! ID:', res.rows[0].id);
|
||||||
|
|
||||||
|
const countRes = await client.query('SELECT COUNT(*) FROM test_results');
|
||||||
|
console.log('📊 New Row Count:', countRes.rows[0].count);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('❌ Insert Failed:', err);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testInsert();
|
||||||
Reference in New Issue
Block a user