A lightweight class for managing SQL engine state and basic query methods in a pluggable and validated manner.
Holds the SQL engine identifier used internally by this instance. It's set only once and used for engine-specific behaviors.
Checks if the SQL engine is undefined, null, or an empty string.
- ✅ Returns:
trueif not set or empty, otherwisefalse.
Sets the SQL engine to be used by this instance. Can only be set once, and only with a valid non-empty string.
-
📌 Parameters:
engine(string): Name of the SQL engine, e.g.'sqlite3','postgre'.
-
⚠️ Throws:- If already set.
- If provided value is not a valid non-empty string.
Returns the currently set SQL engine.
- ✅ Returns: SQL engine name.
⚠️ Throws: If engine is not set.
Detects if a given error matches known SQL engine-specific connection issues.
-
📌 Parameters:
err(Error): Error object to check.
-
🔍 Behavior:
-
For PostgreSQL, checks for known error codes like:
ECONNREFUSED,ETIMEDOUT,28P01,08006, etc.
-
For SQLite3, checks if the error message includes
SQLITE_CANTOPEN.
-
-
✅ Returns:
trueif a known connection error is detected.
These methods are placeholders but follow the async query signature.
Executes an SQL SELECT query expected to return multiple rows.
-
📌 Parameters:
query: SQL string.params: Optional array of parameters.debugName: Optional debug label.
-
✅ Returns: Array of row results.
-
⚠️ Throws: On query failure.
Executes an SQL SELECT query expected to return a single row.
-
📌 Parameters:
query: SQL string.params: Optional array of parameters.debugName: Optional debug label.
-
✅ Returns: Single result object or
null. -
⚠️ Throws: On query failure.
Executes an SQL INSERT, UPDATE, or DELETE statement.
-
📌 Parameters:
query: SQL string.params: Parameters to bind.debugName: Optional debug label.
-
✅ Returns: Result object or
null. -
⚠️ Throws: On execution failure.
export default PuddySqlEngine;This class is ready to be used as a foundational SQL abstraction for SQLite3, PostgreSQL, and others with minimal setup.