sqlite: cleanup ERM support and export Session class · nodejs/node@0fe5337
@@ -1103,6 +1103,14 @@ void DatabaseSync::Close(const FunctionCallbackInfo<Value>& args) {
11031103 db->connection_ = nullptr;
11041104}
110511051106+void DatabaseSync::Dispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
1107+ v8::TryCatch try_catch(args.GetIsolate());
1108+Close(args);
1109+if (try_catch.HasCaught()) {
1110+CHECK(try_catch.CanContinue());
1111+ }
1112+}
1113+11061114void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
11071115 DatabaseSync* db;
11081116ASSIGN_OR_RETURN_UNWRAP(&db, args.This());
@@ -3015,6 +3023,7 @@ Local<FunctionTemplate> Session::GetConstructorTemplate(Environment* env) {
30153023SetProtoMethod(
30163024 isolate, tmpl, "patchset", Session::Changeset<sqlite3session_patchset>);
30173025SetProtoMethod(isolate, tmpl, "close", Session::Close);
3026+SetProtoDispose(isolate, tmpl, Session::Dispose);
30183027 env->set_sqlite_session_constructor_template(tmpl);
30193028 }
30203029return tmpl;
@@ -3059,6 +3068,14 @@ void Session::Close(const FunctionCallbackInfo<Value>& args) {
30593068 session->Delete();
30603069}
306130703071+void Session::Dispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
3072+ v8::TryCatch try_catch(args.GetIsolate());
3073+Close(args);
3074+if (try_catch.HasCaught()) {
3075+CHECK(try_catch.CanContinue());
3076+ }
3077+}
3078+30623079void Session::Delete() {
30633080if (!database_ || !database_->connection_ || session_ == nullptr) return;
30643081sqlite3session_delete(session_);
@@ -3094,6 +3111,7 @@ static void Initialize(Local<Object> target,
3094311130953112SetProtoMethod(isolate, db_tmpl, "open", DatabaseSync::Open);
30963113SetProtoMethod(isolate, db_tmpl, "close", DatabaseSync::Close);
3114+SetProtoDispose(isolate, db_tmpl, DatabaseSync::Dispose);
30973115SetProtoMethod(isolate, db_tmpl, "prepare", DatabaseSync::Prepare);
30983116SetProtoMethod(isolate, db_tmpl, "exec", DatabaseSync::Exec);
30993117SetProtoMethod(isolate, db_tmpl, "function", DatabaseSync::CustomFunction);
@@ -3133,6 +3151,8 @@ static void Initialize(Local<Object> target,
31333151 target,
31343152"StatementSync",
31353153StatementSync::GetConstructorTemplate(env));
3154+SetConstructorFunction(
3155+ context, target, "Session", Session::GetConstructorTemplate(env));
3136315631373157 target->Set(context, env->constants_string(), constants).Check();
31383158