How to programmatically truncate table in Drupal8 I'm wondering how to programmatically truncate a table in drupal8.

Like:

db_truncate('some_table');


Is this possible?
Sure, the function still exists: https://api.drupal.org/api/drupal/core%21includes%21database.inc/function/db_truncate/8.5.x.

It's deprecated, though, with the advice:


  Instead, get a database connection injected into your service from the container and call truncate() on it. For example, $injected_database-&gt;truncate($table, $options);


If you're not in a context where injection is possible, get it from \Drupal:

\Drupal::database()-&gt;truncate('foo')-&gt;execute();