-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (57 loc) · 1.6 KB
/
index.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
// Import the 'bindings' module to link the compiled native addon 'crossdb'
const crossdb = require('bindings')('crossdb'); // Link the compiled addon
// Define the CrossDB class to manage database operations
class CrossDB {
/**
* Constructor: initializes a new database connection
* @param {string} dbPath - The path to the database file
*/
constructor(dbPath) {
this.conn = new crossdb.Connection(dbPath); // Create a new connection to the database
this.pkgVersion = require('./package.json').version;
}
/**
* Executes an SQL query on the database
* @param {string} sql - The SQL query string to execute
* @returns {*} - The result of the query execution
*/
exec(sql) {
return this.conn.exec(sql); // Execute the SQL query and return the result
}
/**
* Closes the current database connection
*/
close() {
this.conn.close(); // Close the connection
}
/**
* Begins a new database transaction
*/
begin() {
this.conn.begin(); // Start a new transaction
}
/**
* Commits the current transaction
*/
commit() {
this.conn.commit(); // Commit the transaction
}
/**
* Rollsback the current transaction
*/
rollback() {
this.conn.rollback(); // Rollback the transaction
}
/**
* Get CroosDB version
*/
version() {
return {
"CroosDB": this.conn.version(), // Get CroosDB version
"Package": this.pkgVersion, // Node.js package version
"Platform": process.platform // Platform information
};
}
}
// Export the CrossDB class as a module
module.exports = CrossDB;