Skip to content

Commit 9e9ef1e

Browse files
Keenan GugelerRiolku
authored andcommitted
replace access_mode completely with boolean
Everywhere now uses a `readOnly` boolean instead of the AccessMode enum.
1 parent 29ec35b commit 9e9ef1e

6 files changed

Lines changed: 8 additions & 27 deletions

File tree

src_cpp/include/node_database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class NodeDatabase : public Napi::ObjectWrap<NodeDatabase> {
2525
std::string databasePath;
2626
size_t bufferPoolSize;
2727
bool enableCompression;
28-
kuzu::common::AccessMode accessMode;
28+
bool readOnly;
2929
std::shared_ptr<Database> database;
3030
};
3131

src_cpp/node_database.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ NodeDatabase::NodeDatabase(const Napi::CallbackInfo& info) : Napi::ObjectWrap<No
1919
databasePath = info[0].ToString();
2020
bufferPoolSize = info[1].As<Napi::Number>().Int64Value();
2121
enableCompression = info[2].As<Napi::Boolean>().Value();
22-
accessMode = static_cast<kuzu::common::AccessMode>(info[3].As<Napi::Number>().Int32Value());
22+
readOnly = info[3].As<Napi::Boolean>().Value();
2323
}
2424

2525
Napi::Value NodeDatabase::InitAsync(const Napi::CallbackInfo& info) {
@@ -41,7 +41,7 @@ void NodeDatabase::InitCppDatabase() {
4141
if (!enableCompression) {
4242
systemConfig.enableCompression = enableCompression;
4343
}
44-
systemConfig.accessMode = accessMode;
44+
systemConfig.readOnly = readOnly;
4545
this->database = std::make_shared<Database>(databasePath, systemConfig);
4646
}
4747

src_js/access_mode.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src_js/database.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const KuzuNative = require("./kuzujs.node");
44
const LoggingLevel = require("./logging_level.js");
5-
const AccessMode = require("./access_mode.js");
65

76
class Database {
87
/**
@@ -14,7 +13,7 @@ class Database {
1413
* @param {String} databasePath path to the database file.
1514
* @param {Number} bufferManagerSize size of the buffer manager in bytes.
1615
* @param {Boolean} enableCompression whether to enable compression.
17-
* @param {Boolean} readOnly if true, access mode is set to `READ_ONLY`; otherwise, set to `READ_WRITE`.
16+
* @param {Boolean} readOnly if true, database will be opened in read-only mode.
1817
*/
1918
constructor(
2019
databasePath,
@@ -29,15 +28,11 @@ class Database {
2928
throw new Error("Buffer manager size must be a positive integer.");
3029
}
3130
bufferManagerSize = Math.floor(bufferManagerSize);
32-
accessMode = AccessMode.READ_WRITE;
33-
if (readOnly) {
34-
accessMode = AccessMode.READ_ONLY;
35-
}
3631
this._database = new KuzuNative.NodeDatabase(
3732
databasePath,
3833
bufferManagerSize,
3934
enableCompression,
40-
accessMode
35+
readOnly,
4136
);
4237
this._isInitialized = false;
4338
this._initPromise = null;

src_js/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"use strict";
22

3-
const AccessMode = require("./access_mode.js");
43
const Connection = require("./connection.js");
54
const Database = require("./database.js");
65
const LoggingLevel = require("./logging_level.js");
76
const PreparedStatement = require("./prepared_statement.js");
87
const QueryResult = require("./query_result.js");
98

109
module.exports = {
11-
AccessMode,
1210
Connection,
1311
Database,
1412
LoggingLevel,

test/test_database.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ describe("Database constructor", function () {
6565
const testDbReadOnly = new kuzu.Database(
6666
tmpDbPath,
6767
1 << 28 /* 256MB */,
68-
true,
69-
kuzu.AccessMode.READ_ONLY
68+
true, /* compression */
69+
true, /* readOnly */
7070
);
7171
assert.exists(testDbReadOnly);
7272
assert.equal(testDbReadOnly.constructor.name, "Database");
@@ -91,7 +91,7 @@ describe("Database constructor", function () {
9191
} catch (e) {
9292
assert.equal(
9393
e.message,
94-
"Cannot execute write operations in a read-only access mode database!"
94+
"Cannot execute write operations in a read-only database!"
9595
);
9696
}
9797
});

0 commit comments

Comments
 (0)