2017 © Pedro Peláez
 

yii2-extension yii2-ssdb

Yii2 SSDB Active Record Active Query

image

myweishanli/yii2-ssdb

Yii2 SSDB Active Record Active Query

  • Tuesday, July 5, 2016
  • by myweishanli
  • Repository
  • 3 Watchers
  • 14 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 2 % Grown

The README.md

Yii2 SSDB

实现了 Active Record、Active Query, (*1)

Yii2 SSDB GII 扩展开发中..., (*2)

github: https://github.com/myweishanli/yii2-ssdb, (*3)

Latest Stable Version Total Downloads, (*4)

注: 功能正在开发中..., (*5)

更详细的配置说明文档正在编写中..., (*6)

QQ群: 137158108 验证信息: github, (*7)

有任何疑问可以发邮件到 myweishanli@gmail.com, (*8)

安装

安装这个扩展的首选方式是通过 composer., (*9)

执行, (*10)

composer require myweishanli/yii2-ssdb:dev-master

或添加, (*11)

"myweishanli/yii2-ssdb": "dev-master"

配置

高级版是common/config/main-local.php, (*12)

基础版是config/web.php, (*13)

'components' => [
    // ...
    'ssdb' => [
        'class' => 'wsl\ssdb\Connection',
        'host' => 'localhost',
        'port' => 8888,
    ],
],

创建数据模型

common/models/ssdb/User.php, (*14)

/**
 * This is the ActiveRecord class for [[\common\models\User]].
 *
 * @property string $user_id
 * @property string $name
 * @property integer $age
 * @property integer $status
 */
class User extends \wsl\ssdb\ActiveRecord
{
    public static $modelClass = '\common\models\User';
}

Active Record、Active Query使用说明

默认只能使用单个主键排序 更多排序查询自定义排序规则, (*15)

实际项目可能需求非常复杂,如果下方例子不能满足你的要求可以加QQ群探讨, (*16)

新增或者替换数据

$userModel = new User();
$userModel->user_id = 1000000;
$userModel->name = '张三';
$userModel->age = 19;
$userModel->status = 0;
$userModel->save();

获取一条数据

$model = User::find()->one();

获取一条数据 排序

$model = User::find()->orderBy('user_id asc')->one();

删除全部

User::deleteAll();

获取一条数据 条件查询

$model = User::find()->andWhere(['user_id' => 1000000])->one();

获取一条数据 多条件查询

$model = User::find()->andWhere(['user_id' => 1000000, 'age' => 19])->one();

获取所有数据列表

$models = User::find()->all();

获取所有数据列表 排序

$models = User::find()->orderBy('age desc')->all();

获取所有数据列表 条件查询

$models = User::find()->andWhere(['user_id' => 1000000])->all();

偏移数据和限定数据返回条数

$models = User::find()->offset(1)->limit(1)->all();

使用DataProvider

$dataProvider = new ActiveDataProvider([
    'query' => User::find(),
    'pagination' => [
        'pageSize' => 20,
    ],
]);
foreach ($dataProvider->getModels() as $itemModel) {
    // code...
}

更多应用

The Versions

05/07 2016

dev-master

9999999-dev

Yii2 SSDB Active Record Active Query

  Sources   Download

MIT

The Requires

 

by Shanli Wei

15/12 2015

1.0.0-alpha

1.0.0.0-alpha

Yii2 SSDB Active Record Active Query

  Sources   Download

MIT

The Requires

 

by Shanli Wei