Skip to content

Commit

Permalink
add get CroosDB version
Browse files Browse the repository at this point in the history
  • Loading branch information
efremropelato committed Nov 29, 2024
1 parent e921407 commit 574cf22
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
51 changes: 50 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,55 @@
"files.associations": {
"*.ifc": "ifc",
"*.json": "json",
"string": "cpp"
"string": "cpp",
"vector": "cpp",
"memory": "cpp",
"ostream": "cpp",
"__bit_reference": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"execution": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"locale": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"print": "cpp",
"queue": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"algorithm": "cpp"
}
}
3 changes: 3 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ try {
console.log("\nCrossDB Simulation Complete.");
db.close();
console.log("Database connection closed.");
const version = db.version()
console.log("CroosDB version: ", version);

}
28 changes: 20 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import the 'bindings' module to link the compiled native addon 'crossdb'
const crossdb = require('bindings')('crossdb'); // Link the compiled addon
const crossdb = require('bindings')('crossdb'); // Link the compiled addon

// Define the CrossDB class to manage database operations
class CrossDB {
Expand All @@ -9,6 +9,7 @@ class CrossDB {
*/
constructor(dbPath) {
this.conn = new crossdb.Connection(dbPath); // Create a new connection to the database
this.pkgVersion = require('./package.json').version;
}

/**
Expand Down Expand Up @@ -40,13 +41,24 @@ class CrossDB {
commit() {
this.conn.commit(); // Commit the transaction
}

/**
* Rollsback the current transaction
*/
rollback() {
this.conn.rollback(); // Rollback 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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@croosdb/crossdb-nodejs",
"version": "1.3.1",
"version": "1.4.0",
"main": "index.js",
"author": "Efrem Ropelato",
"contributors":[
Expand Down
10 changes: 9 additions & 1 deletion src/crossdb_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Connection : public Napi::ObjectWrap<Connection>
InstanceMethod("close", &Connection::Close),
InstanceMethod("begin", &Connection::Begin),
InstanceMethod("commit", &Connection::Commit),
InstanceMethod("rollback", &Connection::Rollback)});
InstanceMethod("rollback", &Connection::Rollback),
InstanceMethod("version", &Connection::Version)});

exports.Set("Connection", func);
return exports;
Expand Down Expand Up @@ -174,6 +175,13 @@ class Connection : public Napi::ObjectWrap<Connection>
}
return info.Env().Null();
}

Napi::Value Version(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
std::string vv = xdb_version();
return Napi::String::New(env, vv);
}
};

Napi::Object InitAll(Napi::Env env, Napi::Object exports)
Expand Down

0 comments on commit 574cf22

Please sign in to comment.