Service to interface with sessions table? In my module, I need greater session control, beyond simple max_lifetime and other parameters taken from PHP config. What I did was to add a column to the sessions table that gives me the effective session expiration, which I can compare against to know if to revoke the session. (I also want to "cache" this in the local session, but this is unrelated to the question).

The question is, what is the best way to retrieve the new data from the sessions table? I can just send a direct DB query, such as:

Database::getConnection()-&gt;query('SELECT expires_at FROM {sessions} s WHERE s.uid = :uid', [':uid' =&gt; $uid]);


However, is there a built-in service for accessing this table, for greater abstraction?
You can make use of Dynamic Queries
instead of Database::getConnection()-&gt;query('SELECT expires_at FROM {sessions} s WHERE s.uid = :uid', [':uid' =&gt; $uid]);

You can do:

  // Create an object of type Select.
  $database = \Drupal::database();
  $query = $database-&gt;select('sessions', 's');
  // Add extra detail to this query object: a condition, fields and a range.
  $query-&gt;condition('s.uid', $uid, '=');
  $query-&gt;fields('s', ['expires_at']);
  $result = $query-&gt;execute();