diff --git a/.vscode/settings.json b/.vscode/settings.json index ea3fc5b..2c1ece4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } } \ No newline at end of file diff --git a/example/index.js b/example/index.js index 3548e83..cc2f0bc 100644 --- a/example/index.js +++ b/example/index.js @@ -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); + } \ No newline at end of file diff --git a/index.js b/index.js index f99f99c..e6eee2a 100644 --- a/index.js +++ b/index.js @@ -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 { @@ -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; } /** @@ -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 diff --git a/package-lock.json b/package-lock.json index 33f3efe..e530a77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@croosdb/crossdb-nodejs", - "version": "1.3.0", + "version": "1.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@croosdb/crossdb-nodejs", - "version": "1.3.0", + "version": "1.4.0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index df3e4d0..afd8d6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@croosdb/crossdb-nodejs", - "version": "1.3.1", + "version": "1.4.0", "main": "index.js", "author": "Efrem Ropelato", "contributors":[ diff --git a/src/crossdb_binding.cc b/src/crossdb_binding.cc index c7288ac..fdfd631 100644 --- a/src/crossdb_binding.cc +++ b/src/crossdb_binding.cc @@ -30,7 +30,8 @@ class Connection : public Napi::ObjectWrap 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; @@ -174,6 +175,13 @@ class Connection : public Napi::ObjectWrap } 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)