bonsaif 1.10.39 → 1.10.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -133
- package/lib/execute.js +0 -28
- package/lib/hookup/exec.js +2 -4
- package/lib/hookup/mariadb.js +10 -28
- package/lib/hookup/mongodb.js +177 -193
- package/lib/hookup/postgres.js +27 -35
- package/lib/hookup/redis.js +42 -162
- package/package.json +3 -6
- package/lib/hookup/mongoose.js +0 -988
- package/tests/README.md +0 -245
- package/tests/config.example.js +0 -61
- package/tests/docker-restart.sh +0 -20
- package/tests/docker-start.sh +0 -192
- package/tests/docker-stop.sh +0 -41
- package/tests/run-all-tests.js +0 -76
- package/tests/test-mariadb.js +0 -85
- package/tests/test-mongodb.js +0 -133
- package/tests/test-mongoose.js +0 -408
- package/tests/test-postgres.js +0 -84
- package/tests/test-redis.js +0 -85
package/tests/test-postgres.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pruebas de conexiones PostgreSQL
|
|
3
|
-
* Ejecutar: node tests/test-postgres.js
|
|
4
|
-
*
|
|
5
|
-
* NOTA: Requiere tabla de prueba. Ejecutar primero:
|
|
6
|
-
* CREATE DATABASE test;
|
|
7
|
-
* \c test
|
|
8
|
-
* CREATE TABLE IF NOT EXISTS test_users (
|
|
9
|
-
* id SERIAL PRIMARY KEY,
|
|
10
|
-
* name VARCHAR(100),
|
|
11
|
-
* email VARCHAR(100),
|
|
12
|
-
* created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
13
|
-
* );
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const config = require('./config');
|
|
17
|
-
const postgres = require('../lib/hookup/postgres');
|
|
18
|
-
|
|
19
|
-
console.log('=== INICIANDO PRUEBAS POSTGRES ===\n');
|
|
20
|
-
|
|
21
|
-
async function testPostgres() {
|
|
22
|
-
const db = config.postgres.options.db;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
// Test 1: INSERT
|
|
26
|
-
console.log('1. Probando INSERT...');
|
|
27
|
-
const insertQuery = "INSERT INTO test_users (name, email) VALUES ('Test User', 'test@example.com')";
|
|
28
|
-
const insertResult = await postgres.api(config.postgres, db, insertQuery, 'insert', '127.0.0.1', 'test');
|
|
29
|
-
console.log(' ✓ INSERT exitoso:', insertResult.result);
|
|
30
|
-
const insertId = insertResult.data?.[0]?.insert_id;
|
|
31
|
-
|
|
32
|
-
// Test 2: SELECT
|
|
33
|
-
console.log('\n2. Probando SELECT...');
|
|
34
|
-
const selectQuery = `SELECT * FROM test_users WHERE id = ${insertId}`;
|
|
35
|
-
const selectResult = await postgres.api(config.postgres, db, selectQuery, 'select', '127.0.0.1', 'test');
|
|
36
|
-
console.log(' ✓ SELECT exitoso:', selectResult.result);
|
|
37
|
-
console.log(' Datos:', selectResult.data?.[0]);
|
|
38
|
-
|
|
39
|
-
// Test 3: UPDATE
|
|
40
|
-
console.log('\n3. Probando UPDATE...');
|
|
41
|
-
const updateQuery = `UPDATE test_users SET email = 'updated@example.com' WHERE id = ${insertId}`;
|
|
42
|
-
const updateResult = await postgres.api(config.postgres, db, updateQuery, 'update', '127.0.0.1', 'test');
|
|
43
|
-
console.log(' ✓ UPDATE exitoso:', updateResult.result);
|
|
44
|
-
|
|
45
|
-
// Test 4: SELECT con WHERE
|
|
46
|
-
console.log('\n4. Probando SELECT con WHERE...');
|
|
47
|
-
const selectWhereQuery = "SELECT * FROM test_users WHERE name LIKE '%Test%' LIMIT 10";
|
|
48
|
-
const selectWhereResult = await postgres.api(config.postgres, db, selectWhereQuery, 'select', '127.0.0.1', 'test');
|
|
49
|
-
console.log(' ✓ SELECT WHERE exitoso:', {
|
|
50
|
-
count: selectWhereResult.data?.length,
|
|
51
|
-
headers: selectWhereResult.result.headers
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Test 5: COUNT
|
|
55
|
-
console.log('\n5. Probando COUNT...');
|
|
56
|
-
const countQuery = "SELECT COUNT(*) as total FROM test_users";
|
|
57
|
-
const countResult = await postgres.api(config.postgres, db, countQuery, 'select', '127.0.0.1', 'test');
|
|
58
|
-
console.log(' ✓ COUNT exitoso:', countResult.data?.[0]);
|
|
59
|
-
|
|
60
|
-
// Test 6: SELECT con JOIN (si tienes múltiples tablas)
|
|
61
|
-
console.log('\n6. Probando SELECT múltiples registros...');
|
|
62
|
-
const selectMultipleQuery = "SELECT * FROM test_users ORDER BY id DESC LIMIT 5";
|
|
63
|
-
const selectMultipleResult = await postgres.api(config.postgres, db, selectMultipleQuery, 'select', '127.0.0.1', 'test');
|
|
64
|
-
console.log(' ✓ SELECT múltiple exitoso:', {
|
|
65
|
-
count: selectMultipleResult.data?.length,
|
|
66
|
-
headers: selectMultipleResult.result.headers
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Cleanup
|
|
70
|
-
console.log('\n7. Limpiando datos de prueba...');
|
|
71
|
-
const deleteQuery = `DELETE FROM test_users WHERE id = ${insertId}`;
|
|
72
|
-
const deleteResult = await postgres.api(config.postgres, db, deleteQuery, 'delete', '127.0.0.1', 'test');
|
|
73
|
-
console.log(' ✓ Limpieza completada:', deleteResult.result);
|
|
74
|
-
|
|
75
|
-
console.log('\n=== ✓ TODAS LAS PRUEBAS POSTGRES EXITOSAS ===\n');
|
|
76
|
-
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.error('\n=== ✗ ERROR EN PRUEBAS POSTGRES ===');
|
|
79
|
-
console.error(error);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
testPostgres();
|
package/tests/test-redis.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pruebas de conexiones Redis
|
|
3
|
-
* Ejecutar: node tests/test-redis.js
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const config = require('./config');
|
|
7
|
-
const redis = require('../lib/hookup/redis');
|
|
8
|
-
|
|
9
|
-
console.log('=== INICIANDO PRUEBAS REDIS ===\n');
|
|
10
|
-
|
|
11
|
-
async function testRedis() {
|
|
12
|
-
const db = 0;
|
|
13
|
-
const testKey = 'test:bonsaif:key';
|
|
14
|
-
const testValue = 'test-value-' + Date.now();
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
// Test 1: SET
|
|
18
|
-
console.log('1. Probando SET...');
|
|
19
|
-
const setResult = await redis.set(config.redis, db, testKey, testValue, 60);
|
|
20
|
-
console.log(' ✓ SET exitoso:', setResult);
|
|
21
|
-
|
|
22
|
-
// Test 2: GET
|
|
23
|
-
console.log('\n2. Probando GET...');
|
|
24
|
-
const getResult = await redis.get(config.redis, db, testKey);
|
|
25
|
-
console.log(' ✓ GET exitoso:', getResult);
|
|
26
|
-
console.log(' Valor obtenido:', getResult.res);
|
|
27
|
-
|
|
28
|
-
// Test 3: SCAN
|
|
29
|
-
console.log('\n3. Probando SCAN...');
|
|
30
|
-
const scanResult = await redis.scan(config.redis, db, '0', 'test:*', 100);
|
|
31
|
-
console.log(' ✓ SCAN exitoso:', {
|
|
32
|
-
cursor: scanResult.cursor,
|
|
33
|
-
count: scanResult.count,
|
|
34
|
-
keys: scanResult.keys?.slice(0, 5) // Mostrar solo primeras 5
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Test 4: SADD
|
|
38
|
-
console.log('\n4. Probando SADD...');
|
|
39
|
-
const setKey = 'test:bonsaif:set';
|
|
40
|
-
const saddResult = await redis.sadd(config.redis, db, setKey, JSON.stringify({id: 1, name: 'Test'}));
|
|
41
|
-
console.log(' ✓ SADD exitoso:', saddResult);
|
|
42
|
-
|
|
43
|
-
// Test 5: SMEMBERS
|
|
44
|
-
console.log('\n5. Probando SMEMBERS...');
|
|
45
|
-
const smembersResult = await redis.smembers(config.redis, db, setKey, 1);
|
|
46
|
-
console.log(' ✓ SMEMBERS exitoso:', smembersResult);
|
|
47
|
-
|
|
48
|
-
// Test 6: HSET
|
|
49
|
-
console.log('\n6. Probando HSET...');
|
|
50
|
-
const hashKey = 'test:bonsaif:hash';
|
|
51
|
-
const hsetResult = await redis.hset(config.redis, db, hashKey, {field1: 'value1', field2: 'value2'});
|
|
52
|
-
console.log(' ✓ HSET exitoso:', hsetResult);
|
|
53
|
-
|
|
54
|
-
// Test 7: HGETALL
|
|
55
|
-
console.log('\n7. Probando HGETALL...');
|
|
56
|
-
const hgetallResult = await redis.hgetall(config.redis, db, hashKey);
|
|
57
|
-
console.log(' ✓ HGETALL exitoso:', hgetallResult);
|
|
58
|
-
|
|
59
|
-
// Test 8: DBSIZE
|
|
60
|
-
console.log('\n8. Probando DBSIZE...');
|
|
61
|
-
const dbsizeResult = await redis.dbsize(config.redis, db);
|
|
62
|
-
console.log(' ✓ DBSIZE exitoso:', dbsizeResult);
|
|
63
|
-
|
|
64
|
-
// Test 9: KEYS
|
|
65
|
-
console.log('\n9. Probando KEYS...');
|
|
66
|
-
const keysResult = await redis.keys(config.redis, db, 'test:*');
|
|
67
|
-
console.log(' ✓ KEYS exitoso:', {count: keysResult.count, keys: keysResult.res?.slice(0, 5)});
|
|
68
|
-
|
|
69
|
-
// Cleanup
|
|
70
|
-
console.log('\n10. Limpiando datos de prueba...');
|
|
71
|
-
await redis.del(config.redis, db, testKey);
|
|
72
|
-
await redis.del(config.redis, db, setKey);
|
|
73
|
-
await redis.del(config.redis, db, hashKey);
|
|
74
|
-
console.log(' ✓ Limpieza completada');
|
|
75
|
-
|
|
76
|
-
console.log('\n=== ✓ TODAS LAS PRUEBAS REDIS EXITOSAS ===\n');
|
|
77
|
-
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error('\n=== ✗ ERROR EN PRUEBAS REDIS ===');
|
|
80
|
-
console.error(error);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
testRedis();
|