Selecting one result from database
You can follow the Database Abstraction API documentation. Although most of that documentation points to using the deprecated methods. You may find the current classes and methods, by clicking into each function that you need (such as db_select), and reading the deprecated messages.

This is very similar to what you have done for inserts (using Dynamic Query).

$id = Database::getConnection()-&gt;select('blood_sugar_monitor')
  -&gt;fields('blood_sugar_monitor', ['my_primary_key'])
  -&gt;range(0, 1)
  -&gt;orderBy('my_primary_key', 'DESC')
  -&gt;execute()
  -&gt;fetchField(0);