-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtest-sqlite.js
66 lines (56 loc) · 1.92 KB
/
test-sqlite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
// A simple test script for the SQLite connector
// Run: node test-sqlite.js
import sqlite3 from 'sqlite3';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Create a test SQLite database
const db = new sqlite3.Database(':memory:');
// Create a test table
db.serialize(() => {
console.log('Creating test table...');
db.run(`CREATE TABLE test_table (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER,
email TEXT
)`);
// Insert some test data
const stmt = db.prepare("INSERT INTO test_table (name, age, email) VALUES (?, ?, ?)");
console.log('Inserting test data...');
stmt.run("Alice", 28, "[email protected]");
stmt.run("Bob", 35, "[email protected]");
stmt.run("Charlie", 42, "[email protected]");
stmt.finalize();
// Query the data
console.log('\nTesting table schema:');
db.all("PRAGMA table_info(test_table)", (err, rows) => {
if (err) {
console.error('Error getting table schema:', err);
return;
}
console.log('Table schema:');
rows.forEach(row => {
console.log(` - ${row.name}: ${row.type} (nullable: ${row.notnull === 0 ? 'YES' : 'NO'}, default: ${row.dflt_value || 'NULL'})`);
});
console.log('\nTesting query execution:');
db.all("SELECT * FROM test_table", (err, rows) => {
if (err) {
console.error('Error executing query:', err);
return;
}
console.log('Query results:');
rows.forEach(row => {
console.log(` [${row.id}] ${row.name}, ${row.age}, ${row.email}`);
});
// Close the database
db.close();
console.log('\nTest completed successfully!');
console.log('Now you can test DBHub with:');
console.log('1. Create a .env file with: DSN=sqlite::memory:');
console.log('2. Run: pnpm run dev');
});
});
});