diff --git a/pathauto.api.php b/pathauto.api.php
index e4d7594..fc9272f 100644
--- a/pathauto.api.php
+++ b/pathauto.api.php
@@ -84,7 +84,7 @@ function hook_path_alias_types_alter(array &$definitions) {
 function hook_pathauto_is_alias_reserved($alias, $source, $langcode) {
   // Check our module's list of paths and return TRUE if $alias matches any of
   // them.
-  return (bool) db_query("SELECT 1 FROM {mytable} WHERE path = :path", array(':path' => $alias))->fetchField();
+  return (bool) \Drupal::database()->query("SELECT 1 FROM {mytable} WHERE path = :path", [':path' => $alias])->fetchField();
 }
 
 /**
diff --git a/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php b/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php
index 98ed1e7..66ffc3b 100644
--- a/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php
+++ b/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\pathauto\Plugin\pathauto\AliasType;
 
+use Drupal\Core\Database\Connection;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -45,6 +46,13 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt
   protected $entityTypeManager;
 
   /**
+   * The database connection.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $database;
+
+  /**
    * The path prefix for this entity type.
    *
    * @var string
@@ -66,12 +74,15 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt
    *   The language manager service.
    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    *   The entity manager service.
+   * @param \Drupal\Core\Database\Connection $database
+   *   The database connection.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, EntityTypeManagerInterface $entity_type_manager) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, EntityTypeManagerInterface $entity_type_manager, Connection $database) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->moduleHandler = $module_handler;
     $this->languageManager = $language_manager;
     $this->entityTypeManager = $entity_type_manager;
+    $this->database = $database;
   }
 
   /**
@@ -84,7 +95,8 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt
       $plugin_definition,
       $container->get('module_handler'),
       $container->get('language_manager'),
-      $container->get('entity_type.manager')
+      $container->get('entity_type.manager'),
+      $container->get('database')
     );
   }
 
@@ -118,7 +130,7 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt
     $entity_type = $this->entityTypeManager->getDefinition($this->getEntityTypeId());
     $id_key = $entity_type->getKey('id');
 
-    $query = db_select($entity_type->get('base_table'), 'base_table');
+    $query = $this->database->select($entity_type->get('base_table'), 'base_table');
     $query->leftJoin('url_alias', 'ua', "CONCAT('" . $this->getSourcePrefix() . "' , base_table.$id_key) = ua.source");
     $query->addField('base_table', $id_key, 'id');
 
diff --git a/src/Tests/PathautoMassDeleteTest.php b/src/Tests/PathautoMassDeleteTest.php
index e528ba6..a245159 100644
--- a/src/Tests/PathautoMassDeleteTest.php
+++ b/src/Tests/PathautoMassDeleteTest.php
@@ -82,7 +82,7 @@ class PathautoMassDeleteTest extends WebTestBase {
     $this->assertUrl('admin/config/search/path/delete_bulk');
 
     // Make sure that all of them are actually deleted.
-    $aliases = db_select('url_alias', 'ua')->fields('ua', array())->execute()->fetchAll();
+    $aliases = \Drupal::database()->select('url_alias', 'ua')->fields('ua', array())->execute()->fetchAll();
     $this->assertEqual($aliases, array(), "All the aliases have been deleted.");
 
     // 2. Test deleting only specific (entity type) aliases.
diff --git a/src/Tests/PathautoTestHelperTrait.php b/src/Tests/PathautoTestHelperTrait.php
index b8b8075..2568638 100644
--- a/src/Tests/PathautoTestHelperTrait.php
+++ b/src/Tests/PathautoTestHelperTrait.php
@@ -134,7 +134,7 @@ trait PathautoTestHelperTrait {
   }
 
   public function deleteAllAliases() {
-    db_delete('url_alias')->execute();
+    \Drupal::database()->delete('url_alias')->execute();
     \Drupal::service('path.alias_manager')->cacheClear();
   }
 
