Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Add support for getTableNames() method from yii\db\Schema Class #21

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/db/Schema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Connect plugin for Craft CMS 3.x
*
* Allows you to connect to external databases and perform db queries
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
*/

namespace nystudio107\connect\db;

use yii\db\Connection;

/**
* @author nystudio107
* @package Connect
* @since 1.0.0
*/
class Schema extends \yii\db\Schema
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function getTableNames($schema = '', $refresh = false)
{
return parent::getTableNames($schema, $refresh);
}

/**
* @inheritdoc
*/
public function quoteSimpleTableName($name = '')
{
return parent::quoteSimpleTableName($name);
}

/**
* @inheritdoc
*/
public function loadTableSchema($name = '')
{
return parent::loadTableSchema($name);
}

/**
* @inheritdoc
*/
public function findTableNames($schema = '') {
$sql = 'SHOW TABLES';
if ($schema !== '') {
$sql .= ' FROM ' . $this->quoteSimpleTableName($schema);
}

return $this->db->createCommand($sql)->queryColumn();
}
}
15 changes: 15 additions & 0 deletions src/variables/ConnectVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use nystudio107\connect\Connect;
use nystudio107\connect\db\Query;
use nystudio107\connect\db\Schema;
use nystudio107\connect\models\Settings;

use Craft;
Expand Down Expand Up @@ -67,6 +68,20 @@ public function query($connection = null): Query
]);
}

/**
* Returns a new generic schema.
*
* @param null|Connection $connection
*
* @return Schema
*/
public function schema($connection = null): Schema
{
return new Schema([
'db' => $connection,
]);
}

// Protected Methods
// =========================================================================

Expand Down