Manage Statement lifecycle with bind, reset, and finalize
masterTo manage the state and resources of a prepared statement, use the following methods:
bind(...params): Binds parameters to the statement. This completely resets the statement object, the row cursor, and removes all previously bound parameters.reset(): Resets the row cursor but preserves the current parameter bindings. Use this to re-execute the same query with the same parameters.finalize(): Releases the statement resources. After calling this, all further calls on the statement object will throw errors. Use this to prevent long delays or database locks, especially after usingget().
// Example: Reusing a statement with reset
await stmt.bind('param1', 'param2');
await stmt.run();
await stmt.reset(); // Resets cursor, keeps bindings
await stmt.run();
await stmt.finalize(); // Clean up