db_insert manual page this function is deprecated and it is better to use Drupal 8 database connection to perform insert.
as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call insert() on it. For example, $injected_database->insert($table, $options);
Now how can I get a database connection and call