-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
sqlite: cleanup ERM support and export Session class #58378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,6 @@ | ||
'use strict'; | ||
const { | ||
SymbolDispose, | ||
} = primordials; | ||
const { emitExperimentalWarning } = require('internal/util'); | ||
const binding = internalBinding('sqlite'); | ||
|
||
emitExperimentalWarning('SQLite'); | ||
|
||
// TODO(cjihrig): Move this to C++ once Symbol.dispose reaches Stage 4. | ||
binding.DatabaseSync.prototype[SymbolDispose] = function() { | ||
try { | ||
this.close(); | ||
} catch { | ||
// Ignore errors. | ||
} | ||
}; | ||
|
||
module.exports = binding; | ||
module.exports = internalBinding('sqlite'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1005,6 +1005,14 @@ void DatabaseSync::Close(const FunctionCallbackInfo<Value>& args) { | |
db->connection_ = nullptr; | ||
} | ||
|
||
void DatabaseSync::Dispose(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
v8::TryCatch try_catch(args.GetIsolate()); | ||
Close(args); | ||
if (try_catch.HasCaught()) { | ||
CHECK(try_catch.CanContinue()); | ||
} | ||
} | ||
|
||
void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) { | ||
DatabaseSync* db; | ||
ASSIGN_OR_RETURN_UNWRAP(&db, args.This()); | ||
|
@@ -2577,6 +2585,7 @@ Local<FunctionTemplate> Session::GetConstructorTemplate(Environment* env) { | |
SetProtoMethod( | ||
isolate, tmpl, "patchset", Session::Changeset<sqlite3session_patchset>); | ||
SetProtoMethod(isolate, tmpl, "close", Session::Close); | ||
SetProtoDispose(isolate, tmpl, Session::Dispose); | ||
env->set_sqlite_session_constructor_template(tmpl); | ||
} | ||
return tmpl; | ||
|
@@ -2621,6 +2630,14 @@ void Session::Close(const FunctionCallbackInfo<Value>& args) { | |
session->Delete(); | ||
} | ||
|
||
void Session::Dispose(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
v8::TryCatch try_catch(args.GetIsolate()); | ||
Close(args); | ||
if (try_catch.HasCaught()) { | ||
CHECK(try_catch.CanContinue()); | ||
} | ||
} | ||
|
||
void Session::Delete() { | ||
if (!database_ || !database_->connection_ || session_ == nullptr) return; | ||
sqlite3session_delete(session_); | ||
|
@@ -2656,6 +2673,7 @@ static void Initialize(Local<Object> target, | |
|
||
SetProtoMethod(isolate, db_tmpl, "open", DatabaseSync::Open); | ||
SetProtoMethod(isolate, db_tmpl, "close", DatabaseSync::Close); | ||
SetProtoDispose(isolate, db_tmpl, DatabaseSync::Dispose); | ||
SetProtoMethod(isolate, db_tmpl, "prepare", DatabaseSync::Prepare); | ||
SetProtoMethod(isolate, db_tmpl, "exec", DatabaseSync::Exec); | ||
SetProtoMethod(isolate, db_tmpl, "function", DatabaseSync::CustomFunction); | ||
|
@@ -2686,6 +2704,8 @@ static void Initialize(Local<Object> target, | |
target, | ||
"StatementSync", | ||
StatementSync::GetConstructorTemplate(env)); | ||
SetConstructorFunction( | ||
context, target, "Session", Session::GetConstructorTemplate(env)); | ||
Comment on lines
+2707
to
+2708
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: there should probably be an IllegalConstructor test for Session. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this gets exposed, does there need to be a brief discussion regarding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's already exposed in the sense that folks can be grabbing the constructor off the returned object already. I'm not sure bikeshedding on the name is worthwhile but could be convinced. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is otherwise ready to land so the naming discussion is the only thing that would hold it up. Is it worth blocking on? |
||
|
||
target->Set(context, env->constants_string(), constants).Check(); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.