From 0e999eb65fa7a17857f536d5a5af2694db2e4fe2 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Sun, 20 Apr 2025 11:57:42 -0400 Subject: [PATCH] sqlite: add getter to detect transactions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds an isTransaction getter to the DatabaseSync class for determining if the database is currently within a transaction. Fixes: https://github.com/nodejs/node/issues/57922 PR-URL: https://github.com/nodejs/node/pull/57925 Reviewed-By: Edy Silva Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Zeyu "Alex" Yang --- doc/api/sqlite.md | 10 ++++++ src/node_sqlite.cc | 13 ++++++++ src/node_sqlite.h | 2 ++ test/parallel/test-sqlite-database-sync.js | 37 ++++++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/doc/api/sqlite.md b/doc/api/sqlite.md index e4d6275784d..6b275a09149 100644 --- a/doc/api/sqlite.md +++ b/doc/api/sqlite.md @@ -200,6 +200,15 @@ added: v22.15.0 * {boolean} Whether the database is currently open or not. +### `database.isTransaction` + + + +* {boolean} Whether the database is currently within a transaction. This method + is a wrapper around [`sqlite3_get_autocommit()`][]. + ### `database.open()`