duckdb 0.3.5-dev987.0 → 0.4.1-dev2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.5-dev987.0",
4
+ "version": "0.4.1-dev2.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/database.cpp CHANGED
@@ -22,14 +22,17 @@ Napi::Object Database::Init(Napi::Env env, Napi::Object exports) {
22
22
  }
23
23
 
24
24
  struct OpenTask : public Task {
25
- OpenTask(Database &database_, std::string filename_, Napi::Function callback_)
26
- : Task(database_, callback_), filename(filename_) {
25
+ OpenTask(Database &database_, std::string filename_, bool read_only_, Napi::Function callback_)
26
+ : Task(database_, callback_), filename(filename_), read_only(read_only_) {
27
27
  }
28
28
 
29
29
  void DoWork() override {
30
30
  try {
31
-
32
- Get<Database>().database = duckdb::make_unique<duckdb::DuckDB>(filename);
31
+ duckdb::DBConfig config;
32
+ if (read_only) {
33
+ config.access_mode = duckdb::AccessMode::READ_ONLY;
34
+ }
35
+ Get<Database>().database = duckdb::make_unique<duckdb::DuckDB>(filename, &config);
33
36
  duckdb::ParquetExtension extension;
34
37
  extension.Load(*Get<Database>().database);
35
38
  success = true;
@@ -56,6 +59,7 @@ struct OpenTask : public Task {
56
59
  }
57
60
 
58
61
  std::string filename;
62
+ bool read_only = false;
59
63
  std::string error = "";
60
64
  bool success = false;
61
65
  };
@@ -73,14 +77,12 @@ Database::Database(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Database>(
73
77
  mode = info[pos++].As<Napi::Number>().Int32Value();
74
78
  }
75
79
 
76
- // TODO check read only flag
77
-
78
80
  Napi::Function callback;
79
81
  if (info.Length() >= pos && info[pos].IsFunction()) {
80
82
  callback = info[pos++].As<Napi::Function>();
81
83
  }
82
84
 
83
- Schedule(env, duckdb::make_unique<OpenTask>(*this, filename, callback));
85
+ Schedule(env, duckdb::make_unique<OpenTask>(*this, filename, mode == DUCKDB_NODEJS_READONLY, callback));
84
86
  }
85
87
 
86
88
  void Database::Schedule(Napi::Env env, std::unique_ptr<Task> task) {