belsrc/db-reflection

此包已废弃,不再维护。没有建议的替代包。

数据库的反射类。

0.3.1 2014-03-28 02:39 UTC

This package is not auto-updated.

Last update: 2022-11-20 21:58:42 UTC


README

No Maintenance Intended

DbReflection

数据库的反射类。[仅测试过MySQL]

安装

您可以通过下载zip并将其包含在项目中,或者最好使用Composer来安装它。

{
    "require": {
        "belsrc/db-reflection": "dev-master"
    }
}

如果您使用Laravel,还可以在app/config/app.php的'providers'数组中包含ServiceProvider。

    'Belsrc\DbReflection\DbReflectionServiceProvider'

以及'aliases'数组中的外观。

    'DbReflection' => 'Belsrc\DbReflection\Facades\DbReflection'

快速示例

$col = DbReflection::getColumn( 'column', 'table', 'database' );

您还可以使用简短的、更干净的路径。

$col = DbReflection::getColumn( 'database.table.column' );

命令

如果您使用Laravel,该包还会公开一些Artisan命令。

reflect:column path        Get the information about a particular column.
  Argument: path           The 'path' of the column (i.e. 'database.table.column')

reflect:database database  Get the information about a particular database.
  Argument: database       The name of the database.

reflect:table path         Get the information about a particular table.
  Argument: path           The 'path' of the table (i.e. 'database.table.column')


  php artisan reflect:database mocking_db
  -------------------------------
  | name      | mocking_db      |
  | charset   | utf8            |
  | collation | utf8_unicode_ci |
  | tables    | 25              |
  -------------------------------

  php artisan reflect:table mocking_db.app_user
  ------------------------------------
  | name      | app_user             |
  | type      | BASE TABLE           |
  | length    | 16384                |
  | maxLength | 0                    |
  | increment | 16                   |
  | createdAt | 2014-02-18 12:00:41  |
  | updatedAt |                      |
  | checksum  |                      |
  | options   |                      |
  | comment   | Authorized app users |
  | database  | mocking_db           |
  | columns   | 12                   |
  ------------------------------------

  php artisan reflect:column mocking_db.app_user.entity_id
  --------------------------------------------------
  | name         | entity_id                       |
  | position     | 1                               |
  | defaultValue |                                 |
  | isNullable   | NO                              |
  | dataType     | int                             |
  | precision    | 10                              |
  | maxLength    |                                 |
  | columnType   | int(10) unsigned                |
  | charset      |                                 |
  | extra        | auto_increment                  |
  | privileges   | select,insert,update,references |
  | comment      |                                 |
  | table        | app_user                        |
  | database     | mocking_db                      |
  | constraints  | Primary Key                     |
  --------------------------------------------------

代码

  print_r( DbReflection::getDatabase( 'mysql' ) );
  /*
    Belsrc\DbReflection\Reflection\ReflectionDatabase Object
    (
      [name] => mysql
      [charset] => utf8
      [collation] => utf8_general_ci
      [tables] => Array
      (
        [0] => columns_priv
        [1] => db
        [2] => event
        [3] => func
        [4] => general_log
        [5] => help_category
        [6] => help_keyword
        [7] => help_relation
        [8] => help_topic
        [9] => host
        [10] => ndb_binlog_index
        [11] => plugin
        [12] => proc
        [13] => procs_priv
        [14] => proxies_priv
        [15] => servers
        [16] => slow_log
        [17] => tables_priv
        [18] => time_zone
        [19] => time_zone_leap_second
        [20] => time_zone_name
        [21] => time_zone_transition
        [22] => time_zone_transition_type
        [23] => user
      )
    )
   */

  print_r( DbReflection::getTable( 'mysql.help_topic' ) );
  /*
    Belsrc\DbReflection\Reflection\ReflectionTable Object
    (
      [name] => help_topic
      [type] => BASE TABLE
      [length] => 444876
      [maxLength] => 281474976710655
      [increment] =>
      [createdAt] => 2012-04-19 09:45:09
      [updatedAt] => 2012-04-19 15:45:10
      [checksum] =>
      [options] =>
      [comment] => help topics
      [database] => mysql
      [columns] => Array
      (
        [0] => help_topic_id
        [1] => name
        [2] => help_category_id
        [3] => description
        [4] => example
        [5] => url
      )
    )
  */


  print_r( DbReflection::getColumn( 'mysql.help_topic.help_topic_id' ) );
  /*
    Belsrc\DbReflection\Reflection\ReflectionColumn Object
    (
      [name] => help_topic_id
      [position] => 1
      [defaultValue] =>
      [isNullable] => NO
      [dataType] => int
      [precision] => 10
      [maxLength] =>
      [columnType] => int(10) unsigned
      [charSet] =>
      [extra] =>
      [privileges] => select,insert,update,references
      [comment] =>
      [table] => help_topic
      [database] => mysql
      [constraints] => Array
      (
        [0] => Belsrc\DbReflection\Reflection\ReflectionConstraint Object
        (
          [type] => Primary Key
          [name] => PRIMARY
          [column] => help_topic_id
          [table] => help_topic
          [database] => mysql
          [foreign_db] =>
          [foreign_table] =>
          [foreign_column] =>
        )
      )
    )
  */

许可证

DbReflection根据BSD 3-Clause许可证发布

版权所有 © 2013-2014,Bryan Kizer 保留所有权利。

在满足以下条件的情况下,允许以源代码和二进制形式重新分发和使用,无论是否修改:

  • 源代码的重新分发必须保留上述版权声明、本条件列表和以下免责声明。
  • 二进制形式的重新分发必须复制上述版权声明、本条件列表和以下免责声明在随分发提供的文档和其他材料中。
  • 未经组织或其贡献者事先书面许可,不得使用组织的名称或其贡献者的姓名来推广或认可由此软件衍生出的产品。

本软件由版权所有者和贡献者按“原样”提供,并明确或暗示地放弃包括但不限于适销性和针对特定目的的适用性的任何明示或暗示保证。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、示范性或后果性的损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,无论这种损害是由何种原因造成的,无论是在合同、严格责任还是侵权(包括疏忽或其他)中,即使被告知了此类损害的可能性。