Creates a simple PostgreSQL core. Requires the psycopg2 library.

def get_pg_core(connection_string, *, cursor_factory=None, edit_connection=None):
  """Creates a simple PostgreSQL core. Requires the psycopg2 library."""
  import psycopg2 as pq
  from psycopg2.extras import NamedTupleCursor

  def opener():
    """Opens a single PostgreSQL connection with the scope-captured connection string."""
    cn = pq.connect(connection_string)
    cn.cursor_factory = cursor_factory or NamedTupleCursor
    if edit_connection:
      edit_connection(cn)
    return cn

  return InjectedDataAccessCore(
    opener,
    default_connection_closer,
    ("%({0})s", "%s", "{0}::{1}"),
    empty_params=None,
    supports_timezones=True,
    supports_returning_syntax=True,
    get_autocommit=get_pg_autocommit,
    set_autocommit=set_pg_autocommit)