本文整理汇总了PHP中yii\db\Connection::getSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::getSchema方法的具体用法?PHP Connection::getSchema怎么用?PHP Connection::getSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Connection
的用法示例。
在下文中一共展示了Connection::getSchema方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Important - modelClass must have a public method "attributeTypes"
* Example:
*
* public function attributeTypes()
* {
* return [
* 'id' => Schema::TYPE_PK,
* 'owner_id' => Schema::TYPE_INTEGER,
* 'name' => Schema::TYPE_STRING,
* 'description' => Schema::TYPE_TEXT,
* 'status' => Schema::TYPE_SMALLINT,
* 'updated_at' => Schema::TYPE_TIMESTAMP,
* 'created_at' => Schema::TYPE_DATETIME,
* ];
* }
*
* Example of use:
*
* (new DbSync([
* 'common\models\', // if namespace equivalent to path
* 'Path to directory' => 'someName\models\',
* ]))->run();
*
*
* @param array $nameSpaces
*/
public function __construct(array $nameSpaces)
{
foreach ($nameSpaces as $key => $nameSpace) {
$this->nameSpaces[$key] = trim($nameSpace, '\\') . '\\';
}
$this->db = \Yii::$app->getDb();
$this->tableNames = $this->db->getSchema()->getTableNames();
}
示例2: getSchemaNames
/**
* @param Connection $db
* @param bool $refresh
* @return string[]
*/
public static function getSchemaNames(Connection $db, $refresh = false)
{
try {
$schemaNames = array_diff($db->getSchema()->getSchemaNames($refresh), ['public']);
} catch (NotSupportedException $e) {
$schemaNames = [];
}
return $schemaNames;
}
示例3: init
/**
* @inheritdoc
*/
public function init()
{
$this->db = Instance::ensure($this->db, Connection::className());
$this->createTable();
if (Yii::$app instanceof WebApplication) {
$id = Yii::$app->getRequest()->getCookies()->getValue($this->cookieKey);
} else {
$file = Yii::getAlias($this->cliFileKey);
$id = is_file($file) ? (int) file_get_contents($file) : null;
}
if ($id === null || !is_numeric($id) || ($this->_states = $this->getData($id)) === false) {
$primary = $this->db->getSchema()->insert($this->tableName, ['created_at' => time()]);
$id = $primary['id'];
$this->_states = [];
}
if (Yii::$app instanceof WebApplication) {
$cookie = new Cookie(['name' => $this->cookieKey, 'value' => $id, 'expire' => time() + 30 * 24 * 3600]);
Yii::$app->getResponse()->getCookies()->add($cookie);
} elseif (isset($file)) {
file_put_contents($file, $id, LOCK_EX);
}
$this->_states['id'] = $this->_id = $id;
}
示例4: getAttributeCondition
/**
* @param string $attribute
* @param string $value
* @param array $formats
* @param string $tablePrefix
* @param Connection $db
* @return array in format supported by Query::where()
*/
protected function getAttributeCondition($attribute, $value, $formats, $tablePrefix, $db)
{
$likeOp = $db->driverName === 'pgsql' ? 'ILIKE' : 'LIKE';
$columnName = $tablePrefix . '.' . $db->getSchema()->quoteSimpleColumnName($attribute);
if (!is_array($value)) {
$parts = explode(ActiveSearchInterface::TOKEN_SEPARATOR, $value);
$parts = array_filter(array_map('trim', $parts));
if (count($parts) > 1) {
// add the original value for an exact match
$parts[] = trim($value);
}
$value = $parts;
}
switch ($formats[$attribute]) {
default:
if (!is_string($value) || strlen($value) < 2 || $value[0] !== '>' && $value[0] !== '<') {
return [$columnName => $value];
}
$op = substr($value, 0, $value[1] !== '=' ? 1 : 2);
$value = substr($value, strlen($op));
if (trim($value) === '') {
return [];
}
return [$op, $columnName, $value];
case 'string':
case 'text':
case 'email':
case 'url':
if (is_array($value)) {
$result = ['or'];
foreach ($value as $token) {
$result[] = [$likeOp, $columnName, $token];
}
return $result;
}
return [$likeOp, $columnName, $value];
case 'json':
$subquery = (new Query())->select(1)->from('json_array_elements(' . $columnName . ') a')->where([$likeOp, 'a::text', $value]);
return ['exists', $subquery];
}
}
示例5: init
public function init()
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::className());
$this->db->getSchema()->refresh();
}