Wordpress content framework
                                    Fund package maintenance!
                                                                            
                                                                                                                                        paypal.me/technote0space
                                                                                    
                                                                
Installs: 22 728
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/wp-content-framework/db
Requires
- php: >=5.6.0
 
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.1
 - phake/phake: ~2.0
 - phpcompatibility/phpcompatibility-wp: ^2.1
 - phpmd/phpmd: ^2.9
 - phpunit/phpunit: ~5.7
 - squizlabs/php_codesniffer: ^3.5
 - wp-coding-standards/wpcs: ^2.3
 
- dev-master
 - v1.0.27
 - v1.0.26
 - v1.0.25
 - v1.0.24
 - v1.0.23
 - v1.0.22
 - v1.0.21
 - v1.0.20
 - v1.0.19
 - v1.0.18
 - v1.0.17
 - v1.0.16
 - v1.0.15
 - v1.0.14
 - v1.0.13
 - v1.0.12
 - v1.0.11
 - v1.0.10
 - v1.0.9
 - v1.0.8
 - v1.0.7
 - v1.0.6
 - v1.0.5
 - v1.0.4
 - v1.0.3
 - v1.0.2
 - v1.0.1
 - v1.0.0
 - v0.0.24
 - v0.0.23
 - v0.0.22
 - v0.0.21
 - v0.0.20
 - v0.0.19
 - v0.0.18
 - v0.0.17
 - v0.0.16
 - v0.0.15
 - v0.0.14
 - v0.0.13
 - v0.0.12
 - v0.0.11
 - v0.0.10
 - v0.0.9
 - v0.0.8
 - v0.0.7
 - v0.0.6
 - v0.0.5
 - v0.0.4
 - v0.0.3
 - v0.0.2
 - v0.0.1
 - dev-release/next-v1.0.27
 
This package is auto-updated.
Last update: 2025-10-18 00:17:42 UTC
README
WP Content Framework のモジュールです。
Table of Contents
要件
- PHP 5.6 以上
 - WordPress 3.9.3 以上
 
インストール
composer require wp-content-framework/db
基本設定
- configs/config.php
 
| 設定値 | 説明 | 
|---|---|
| default_delete_rule | デフォルトの削除動作を指定(physical or logical [default = physical]) | 
- configs/db.php
 
設定例:
// テーブル名 => 設定
'test' => array(
    // primary key 設定
    'id'      => 'test_id',     // optional [default = $table_name . '_id']
    // カラム 設定
    'columns' => array(
        // 論理名 => 設定
        'name'   => array(
            'name'     => 'name_test',     // optional (物理名)
            'type'     => 'VARCHAR(32)',   // required
            'unsigned' => false,           // optional [default = false]
            'null'     => true,            // optional [default = true]
            'default'  => null,            // optional [default = null]
            'comment'  => '',              // optional
        ),
        'value1' => array(
            'type'    => 'VARCHAR(32)',
            'null'    => false,
            'default' => 'test',
        ),
        'value2' => array(
            'type'    => 'VARCHAR(32)',
            'comment' => 'aaaa',
        ),
        'value3' => array(
            'type'    => 'INT(11)',
            'null'    => false,
            'comment' => 'bbb',
        ),
    ),
    // index 設定
    'index'   => array(
        // key index
        'key'    => array(
            'name' => array( 'name' ),
        ),
        // unique index
        'unique' => array(
            'value' => array( 'value1', 'value2' ),
        ),
    ),
    // 論理削除 or 物理削除
    'delete'  => 'logical', // physical or logical [default = physical]
    // コメント
    'comment' => 'test,
),
プラグインのバージョンが変更されたとき またはキャッシュを削除することで 自動でテーブルの追加・更新が行われます。
default の途中変更に関しては文字列のみ対応しています。 詳細
データの取得・挿入・更新・削除はLaravelのDB操作と同じように行うことができます。
// 取得
$this->table( 'test' )
     ->where_integer_in_raw( 'id', [ 1, 2, 3 ] )
     ->where( 'value1', 'like', 'tes%' )
     ->where( 'created_at', '<', '2020-01-01' )
     ->where_null( 'value2' )
     ->where( 'value3', 3 )
     ->get();
// 取得(WordPressのテーブル)
$this->wp_table( 'posts' )
     ->where( 'post_type', 'page' )
     ->order_by( 'post_modified' )
     ->limit( 10 )
     ->get();
// 取得(結合)
$this->table( 'test', 't' )
     ->alias_join( 'test2', 't2', 't.id', 't2.test_id' )
     ->alias_join_wp( 'posts', 'p', 't.value3', 'p.ID' )
     ->where_in( 't.value1', [ 'test1', 'test2', 'test3' ] )
     ->get();
// 取得(単体)
$this->table( 'test' )
     ->where( 'value1', 'test1' )
     ->row();
 // 取得(ID単体)
$this->table( 'test' )
     ->find( 10 );
// 挿入
$this->table( 'test' )
     ->insert( [
         'name'   => 'aaa',
         'value1' => 'bbb',
         'value3' => 100,
     ] );
// 挿入(一括)
$this->table( 'test' )
     ->insert( [
         [
             'name'   => 'aaa1',
             'value1' => 'bbb1',
             'value3' => 100,
         ],
         [
             'name'   => 'aaa2',
             'value1' => 'bbb2',
             'value3' => 200,
         ],
         [
             'name'   => 'aaa3',
             'value1' => 'bbb3',
             'value3' => 300,
         ],
// 更新
$this->table( 'test' )
     ->where( 'id', 4 )
     ->update( [
         'value2' => 'ccc',
     ] );
// 削除
$this->table( 'test' )
     ->where( 'value1', 'test' )
     ->delete();
// 削除(ID)
$this->table( 'test' )
     ->delete( 4 );