A MySQL upsert helper: insert a row, or if a unique key collides, update the same row with the new values. Returns whether the row was inserted (true) or updated (false).
Cursor (keyset) pagination is faster than OFFSET on large tables — and immune to dupes/skips when rows shift. Pass the last seen ID and direction; get the next page.
Insert many rows in one round-trip using executemany. Orders-of-magnitude faster than a loop of single inserts — and the driver handles batching/parametrization for you.
The modern SQLAlchemy 2.0 style: typed Mapped[] columns, the new `select()` API, and Session.scalars() for clean row access. Replaces the legacy Query syntax.
Wrap your transaction in a function that commits on success and rolls back on error or panic. Drop-in: pass any `func(*sql.Tx) error` and forget about manual cleanup.
Safely interpolate a variable-length list into a "WHERE col IN (...)" clause. Returns the SQL fragment plus the bound parameters — never concatenate user values into SQL.
Insert a list of rows in one round trip by building a multi-VALUES statement with placeholders. Orders-of-magnitude faster than looping single INSERTs.
Open a PDO connection with all the options you almost always want: real prepared statements, exceptions on error, associative-array fetch mode, UTF-8 charset.
Plain `string` can't represent SQL NULL. Use `sql.NullString` (and its siblings `NullInt64`, `NullBool`, etc.) for columns where NULL is a real value distinct from empty.
Stdlib sqlite3 is fine for embedded / small workloads. Use `with conn:` for automatic commit/rollback, and a row_factory so you get dicts (or namedtuples) instead of bare tuples.
Run a closure inside a transaction. Commits on success, rolls back on any exception, then re-throws so the caller can react. Avoids the bug-prone copy-paste of begin/commit/rollBack.