duckdb 0.5.2-dev678.0 → 0.5.2-dev708.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.5.2-dev678.0",
4
+ "version": "0.5.2-dev708.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -16955,7 +16955,20 @@ FileOpener *FileSystem::GetFileOpener(ClientContext &context) {
16955
16955
  return ClientData::Get(context).file_opener.get();
16956
16956
  }
16957
16957
 
16958
+ bool PathMatched(const string &path, const string &sub_path) {
16959
+ if (path.rfind(sub_path, 0) == 0) {
16960
+ return true;
16961
+ }
16962
+ return false;
16963
+ }
16964
+
16958
16965
  #ifndef _WIN32
16966
+
16967
+ bool FileSystem::IsPathAbsolute(const string &path) {
16968
+ auto path_separator = FileSystem::PathSeparator();
16969
+ return PathMatched(path, path_separator);
16970
+ }
16971
+
16959
16972
  string FileSystem::PathSeparator() {
16960
16973
  return "/";
16961
16974
  }
@@ -16985,6 +16998,27 @@ string FileSystem::GetWorkingDirectory() {
16985
16998
  }
16986
16999
  #else
16987
17000
 
17001
+ bool FileSystem::IsPathAbsolute(const string &path) {
17002
+ // 1) A single backslash
17003
+ auto sub_path = FileSystem::PathSeparator();
17004
+ if (PathMatched(path, sub_path)) {
17005
+ return true;
17006
+ }
17007
+ // 2) check if starts with a double-backslash (i.e., \\)
17008
+ sub_path += FileSystem::PathSeparator();
17009
+ if (PathMatched(path, sub_path)) {
17010
+ return true;
17011
+ }
17012
+ // 3) A disk designator with a backslash (e.g., C:\)
17013
+ auto path_aux = path;
17014
+ path_aux.erase(0, 1);
17015
+ sub_path = ":" + FileSystem::PathSeparator();
17016
+ if (PathMatched(path_aux, sub_path)) {
17017
+ return true;
17018
+ }
17019
+ return false;
17020
+ }
17021
+
16988
17022
  string FileSystem::PathSeparator() {
16989
17023
  return "\\";
16990
17024
  }
@@ -130140,6 +130174,19 @@ idx_t DBConfig::ParseMemoryLimit(const string &arg) {
130140
130174
  return (idx_t)multiplier * limit;
130141
130175
  }
130142
130176
 
130177
+ // Right now we only really care about access mode when comparing DBConfigs
130178
+ bool DBConfigOptions::operator==(const DBConfigOptions &other) const {
130179
+ return other.access_mode == access_mode;
130180
+ }
130181
+
130182
+ bool DBConfig::operator==(const DBConfig &other) {
130183
+ return other.options == options;
130184
+ }
130185
+
130186
+ bool DBConfig::operator!=(const DBConfig &other) {
130187
+ return !(other.options == options);
130188
+ }
130189
+
130143
130190
  } // namespace duckdb
130144
130191
 
130145
130192
 
@@ -130722,6 +130769,23 @@ DBConfig::DBConfig() {
130722
130769
  cast_functions = make_unique<CastFunctionSet>();
130723
130770
  }
130724
130771
 
130772
+ DBConfig::DBConfig(std::unordered_map<string, string> &config_dict, bool read_only) {
130773
+ compression_functions = make_unique<CompressionFunctionSet>();
130774
+ if (read_only) {
130775
+ options.access_mode = AccessMode::READ_ONLY;
130776
+ }
130777
+ for (auto &kv : config_dict) {
130778
+ string key = kv.first;
130779
+ string val = kv.second;
130780
+ auto config_property = DBConfig::GetOptionByName(key);
130781
+ if (!config_property) {
130782
+ throw InvalidInputException("Unrecognized configuration property \"%s\"", key);
130783
+ }
130784
+ auto opt_val = Value(val);
130785
+ DBConfig::SetOption(*config_property, opt_val);
130786
+ }
130787
+ }
130788
+
130725
130789
  DBConfig::~DBConfig() {
130726
130790
  }
130727
130791
 
@@ -131026,6 +131090,97 @@ bool DatabaseInstance::IsInvalidated() {
131026
131090
  }
131027
131091
 
131028
131092
  } // namespace duckdb
131093
+ //===----------------------------------------------------------------------===//
131094
+ // DuckDB
131095
+ //
131096
+ // duckdb/main/db_instance_cache.hpp
131097
+ //
131098
+ //
131099
+ //===----------------------------------------------------------------------===//
131100
+
131101
+
131102
+
131103
+
131104
+
131105
+
131106
+
131107
+
131108
+ namespace duckdb {
131109
+ class DBInstanceCache {
131110
+ public:
131111
+ DBInstanceCache() {};
131112
+ //! Gets a DB Instance from the cache if already exists (Fails if the configurations do not match)
131113
+ shared_ptr<DuckDB> GetInstance(const string &database, const DBConfig &config_dict);
131114
+
131115
+ //! Creates and caches a new DB Instance (Fails if a cached instance already exists)
131116
+ shared_ptr<DuckDB> CreateInstance(const string &database, DBConfig &config_dict, bool cache_instance = true);
131117
+
131118
+ private:
131119
+ //! A map with the cached instances <absolute_path/instance>
131120
+ unordered_map<string, weak_ptr<DuckDB>> db_instances;
131121
+
131122
+ //! Lock to alter cache
131123
+ mutex cache_lock;
131124
+ };
131125
+ } // namespace duckdb
131126
+
131127
+
131128
+ namespace duckdb {
131129
+
131130
+ string GetDBAbsolutePath(const string &database) {
131131
+ if (database.empty()) {
131132
+ return ":memory:";
131133
+ }
131134
+ if (database.rfind(":memory:", 0) == 0) {
131135
+ // this is a memory db, just return it.
131136
+ return database;
131137
+ }
131138
+ if (FileSystem::IsPathAbsolute(database)) {
131139
+ return database;
131140
+ }
131141
+ return FileSystem::JoinPath(FileSystem::GetWorkingDirectory(), database);
131142
+ }
131143
+
131144
+ shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DBConfig &config) {
131145
+ lock_guard<mutex> l(cache_lock);
131146
+ shared_ptr<DuckDB> db_instance;
131147
+ auto abs_database_path = GetDBAbsolutePath(database);
131148
+ if (db_instances.find(abs_database_path) != db_instances.end()) {
131149
+ db_instance = db_instances[abs_database_path].lock();
131150
+ if (db_instance) {
131151
+ if (db_instance->instance->config != config) {
131152
+ throw duckdb::Exception(ExceptionType::CONNECTION,
131153
+ "Can't open a connection to same database file with a different configuration "
131154
+ "than existing connections");
131155
+ }
131156
+ } else {
131157
+ // clean-up
131158
+ db_instances.erase(abs_database_path);
131159
+ }
131160
+ }
131161
+ return db_instance;
131162
+ }
131163
+
131164
+ shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBConfig &config, bool cache_instance) {
131165
+ lock_guard<mutex> l(cache_lock);
131166
+ auto abs_database_path = GetDBAbsolutePath(database);
131167
+ if (db_instances.find(abs_database_path) != db_instances.end()) {
131168
+ throw duckdb::Exception(ExceptionType::CONNECTION,
131169
+ "Instance with path: " + abs_database_path + " already exists.");
131170
+ }
131171
+ // Creates new instance
131172
+ string instance_path = abs_database_path;
131173
+ if (abs_database_path.rfind(":memory:", 0) == 0) {
131174
+ instance_path = ":memory:";
131175
+ }
131176
+ auto db_instance = make_shared<DuckDB>(instance_path, &config);
131177
+ if (cache_instance) {
131178
+ db_instances[abs_database_path] = db_instance;
131179
+ }
131180
+ return db_instance;
131181
+ }
131182
+
131183
+ } // namespace duckdb
131029
131184
 
131030
131185
 
131031
131186
 
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "23b94dd87"
15
- #define DUCKDB_VERSION "v0.5.2-dev678"
14
+ #define DUCKDB_SOURCE_ID "c5d35b30c"
15
+ #define DUCKDB_VERSION "v0.5.2-dev708"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -2184,6 +2184,8 @@ public:
2184
2184
  DUCKDB_API static idx_t GetAvailableMemory();
2185
2185
  //! Path separator for the current file system
2186
2186
  DUCKDB_API static string PathSeparator();
2187
+ //! Checks if path is starts with separator (i.e., '/' on UNIX '\\' on Windows)
2188
+ DUCKDB_API static bool IsPathAbsolute(const string &path);
2187
2189
  //! Join two paths together
2188
2190
  DUCKDB_API static string JoinPath(const string &a, const string &path);
2189
2191
  //! Convert separators in a path to the local separators (e.g. convert "/" into \\ on windows)
@@ -24439,6 +24441,8 @@ struct DBConfigOptions {
24439
24441
  bool allow_unsigned_extensions = false;
24440
24442
  //! Enable emitting FSST Vectors
24441
24443
  bool enable_fsst_vectors = false;
24444
+
24445
+ bool operator==(const DBConfigOptions &other) const;
24442
24446
  };
24443
24447
 
24444
24448
  struct DBConfig {
@@ -24447,6 +24451,7 @@ struct DBConfig {
24447
24451
 
24448
24452
  public:
24449
24453
  DUCKDB_API DBConfig();
24454
+ DUCKDB_API DBConfig(std::unordered_map<string, string> &config_dict, bool read_only);
24450
24455
  DUCKDB_API ~DBConfig();
24451
24456
 
24452
24457
  //! Replacement table scans are automatically attempted when a table name cannot be found in the schema
@@ -24495,6 +24500,9 @@ public:
24495
24500
  //! Return the compression function for the specified compression type/physical type combo
24496
24501
  DUCKDB_API CompressionFunction *GetCompressionFunction(CompressionType type, PhysicalType data_type);
24497
24502
 
24503
+ bool operator==(const DBConfig &other);
24504
+ bool operator!=(const DBConfig &other);
24505
+
24498
24506
  DUCKDB_API CastFunctionSet &GetCastFunctions();
24499
24507
 
24500
24508
  private: