Skip to content

Commit 446d48b

Browse files
committed
sqlite,test,doc: accept Buffer and URL as paths
1 parent 1b2d2f7 commit 446d48b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

doc/api/sqlite.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ exposed by this class execute synchronously.
8888
added: v22.5.0
8989
-->
9090

91-
* `location` {string} The location of the database. A SQLite database can be
91+
* `location` {string} | {Buffer} | {URL} The location of the database. A SQLite database can be
9292
stored in a file or completely [in memory][]. To use a file-backed database,
9393
the location should be a file path. To use an in-memory database, the location
9494
should be the special name `':memory:'`.
@@ -533,8 +533,8 @@ added: REPLACEME
533533
-->
534534

535535
* `sourceDb` {DatabaseSync} The database to backup. The source database must be open.
536-
* `destination` {string} The path where the backup will be created. If the file already exists, the contents will be
537-
overwritten.
536+
* `destination` {string} | {Buffer} | {URL} The path where the backup will be created. If the file already exists,
537+
the contents will be overwritten.
538538
* `options` {Object} Optional configuration for the backup. The
539539
following properties are supported:
540540
* `source` {string} Name of the source database. This can be `'main'` (the default primary database) or any other

src/node_sqlite.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "node_sqlite.h"
22
#include <path.h>
3+
#include "ada.h"
34
#include "base_object-inl.h"
45
#include "debug_utils-inl.h"
56
#include "env-inl.h"
@@ -593,19 +594,24 @@ void DatabaseSync::New(const FunctionCallbackInfo<Value>& args) {
593594
return;
594595
}
595596

596-
if (!args[0]->IsString()) {
597+
Local<Value> path = args[0];
598+
if (!path->IsString() && !path->IsUint8Array()) {
597599
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
598-
"The \"path\" argument must be a string.");
600+
"The \"path\" argument must be a string, "
601+
"Uint8Array, or URL without null bytes.");
599602
return;
600603
}
601604

602605
std::string location =
603606
Utf8Value(env->isolate(), args[0].As<String>()).ToString();
604-
DatabaseOpenConfiguration open_config(std::move(location));
607+
auto parsed_url = ada::parse<ada::url_aggregator>(location, nullptr);
608+
if (parsed_url && parsed_url->type != ada::scheme::FILE) {
609+
THROW_ERR_INVALID_URL_SCHEME(env->isolate());
610+
}
605611

612+
DatabaseOpenConfiguration open_config(std::move(location));
606613
bool open = true;
607614
bool allow_load_extension = false;
608-
609615
if (args.Length() > 1) {
610616
if (!args[1]->IsObject()) {
611617
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),

0 commit comments

Comments
 (0)