kohana-schema:这是Laravels Schema库到Kohana的移植。 它提供了一种与数据库无关的操作表的方式。

  • a8_143056
    了解作者
  • 25.5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-28 05:46
    上传日期
这是Laravels Schema库到Kohana的移植。 介绍 Kohana Schema类提供了一种与数据库无关的操作表的方式。 它可与Kohana支持的所有数据库很好地配合使用,并且在所有这些系统中均具有统一的API。 创建和删除表 要创建一个新的数据库表,使用Schema::create方法: Schema::create('users', function($table) { $table->increments('id'); }); 传递给create方法的第一个参数是表的名称,第二个参数是一个Closure ,它将接收一个Blueprint对象,该对象可用于定义新表。 要重命名现有数据库表,可以使用rename方法: Schema::rename($from, $to); 若要指定架构操作应在哪个连接上进行,请将第三个参数传递给该方法: Schema::create
kohana-schema-master.zip
内容介绍
# This is a port of Laravels Schema library to Kohana. --- - [Introduction](#introduction) - [Creating & Dropping Tables](#creating-and-dropping-tables) - [Adding Columns](#adding-columns) - [Renaming Columns](#renaming-columns) - [Dropping Columns](#dropping-columns) - [Checking Existence](#checking-existence) - [Adding Indexes](#adding-indexes) - [Foreign Keys](#foreign-keys) - [Dropping Indexes](#dropping-indexes) - [Storage Engines](#storage-engines) <a name="introduction" rel='nofollow' onclick='return false;'></a> ## Introduction The Kohana `Schema` class provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Kohana, and has a unified API across all of these systems. <a name="creating-and-dropping-tables" rel='nofollow' onclick='return false;'></a> ## Creating & Dropping Tables To create a new database table, the `Schema::create` method is used: Schema::create('users', function($table) { $table->increments('id'); }); The first argument passed to the `create` method is the name of the table, and the second is a `Closure` which will receive a `Blueprint` object which may be used to define the new table. To rename an existing database table, the `rename` method may be used: Schema::rename($from, $to); To specify which connection the schema operation should take place on, pass a third parameter to the method: Schema::create('users', function($table) { $table->increments('id'); }, 'default'); To drop a table, you may use the `Schema::drop` method: Schema::drop('users'); <a name="adding-columns" rel='nofollow' onclick='return false;'></a> ## Adding Columns To update an existing table, we will use the `Schema::table` method: Schema::table('users', function($table) { $table->string('email'); }); <a name="modifying-columns" rel='nofollow' onclick='return false;'></a> ## Modifying Columns To modify columns in an existing table, we will use the `Schema::table` method: Schema::table('users', function($table) { $table->modify_column('email', 'string', ['length' => '50']); }); > **Note:** Modifying columns is not supported in SQLite. The table builder contains a variety of column types that you may use when building your tables: Command | Description ------------- | ------------- `$table->big_increments('id');` | Incrementing ID using a "big integer" equivalent. `$table->big_integer('votes');` | BIGINT equivalent to the table `$table->binary('data');` | BLOB equivalent to the table `$table->boolean('confirmed');` | BOOLEAN equivalent to the table `$table->date('created_at');` | DATE equivalent to the table `$table->datetime('created_at');` | DATETIME equivalent to the table `$table->decimal('amount', 5, 2);` | DECIMAL equivalent with a precision and scale `$table->double('column', 15, 8);` | DOUBLE equivalent with precision `$table->enum('choices', array('foo', 'bar'));` | ENUM equivalent to the table `$table->float('amount');` | FLOAT equivalent to the table `$table->increments('id');` | Incrementing ID to the table (primary key). `$table->integer('votes');` | INTEGER equivalent to the table `$table->long_text('description');` | LONGTEXT equivalent to the table `$table->medium_text('description');` | MEDIUMTEXT equivalent to the table `$table->morphs('taggable');` | Adds INTEGER `taggable_id` and STRING `taggable_type` `$table->small_integer('votes');` | SMALLINT equivalent to the table `$table->tiny_integer('numbers');` | TINYINT equivalent to the table `$table->soft_deletes();` | Adds **deleted\_at** column for soft deletes `$table->string('email');` | VARCHAR equivalent column `$table->string('name', 100);` | VARCHAR equivalent with a length `$table->text('description');` | TEXT equivalent to the table `$table->time('sunrise');` | TIME equivalent to the table `$table->timestamp('added_on');` | TIMESTAMP equivalent to the table `$table->timestamps();` | Adds **created\_at** and **updated\_at** columns `->nullable()` | Designate that the column allows NULL values `->default($value)` | Declare a default value for a column `->unsigned()` | Set INTEGER to UNSIGNED If you are using the MySQL database, you may use the `after` method to specify the order of columns: #### Using After On MySQL $table->string('name')->after('email'); <a name="renaming-columns" rel='nofollow' onclick='return false;'></a> ## Renaming Columns To rename a column, you may use the `rename_column` method on the Schema builder. Before renaming a column, be sure to add the `doctrine/dbal` dependency to your `composer.json` file. #### Renaming A Column Schema::table('users', function($table) { $table->rename_column('from', 'to'); }); > **Note:** Renaming `enum` column types is not supported. <a name="dropping-columns" rel='nofollow' onclick='return false;'></a> ## Dropping Columns #### Dropping A Column From A Database Table Schema::table('users', function($table) { $table->drop_column('votes'); }); #### Dropping Multiple Columns From A Database Table Schema::table('users', function($table) { $table->drop_column('votes', 'avatar', 'location'); }); <a name="adding-indexes" rel='nofollow' onclick='return false;'></a> ## Adding Indexes The schema builder supports several types of indexes. There are two ways to add them. First, you may fluently define them on a column definition, or you may add them separately: #### Fluently Creating A Column And Index $table->string('email')->unique(); Or, you may choose to add the indexes on separate lines. Below is a list of all available index types: Command | Description ------------- | ------------- `$table->primary('id');` | Adding a primary key `$table->primary(array('first', 'last'));` | Adding composite keys `$table->unique('email');` | Adding a unique index `$table->index('state');` | Adding a basic index <a name="foreign-keys" rel='nofollow' onclick='return false;'></a> ## Foreign Keys Laravel also provides support for adding foreign key constraints to your tables: #### Adding A Foreign Key To A Table $table->foreign('user_id')->references('id')->on('users'); In this example, we are stating that the `user_id` column references the `id` column on the `users` table. You may also specify options for the "on delete" and "on update" actions of the constraint: $table->foreign('user_id') ->references('id')->on('users') ->on_delete('cascade'); To drop a foreign key, you may use the `drop_foreign` method. A similar naming convention is used for foreign keys as is used for other indexes: $table->drop_foreign('posts_user_id_foreign'); > **Note:** When creating a foreign key that references an incrementing integer, remember to always make the foreign key column `unsigned`. <a name="dropping-indexes" rel='nofollow' onclick='return false;'></a> ## Dropping Indexes To drop an index you must specify the index's name. Laravel assigns a reasonable name to the indexes by default. Simply concatenate the table name, the names of the column in the index, and the index type. Here are some examples: Command | Description ------------- | ------------- `$table->drop_primary('users_id_primary');` | Dropping a primary key from the "users" table `$table->drop_unique('users_email_unique');` | Dropping a unique index from the "users" table `$table->drop_index('geo_state_index');` | Dropping a basic index from the "geo" table <a name="storage-engines" rel='nofollow' onclick='return false;'></a> ## Storage Engines To set the storage engine for a table, set the `engine` property on the schema builder: Schema::create('users', function($table) { $table->engine = 'InnoDB'; $table->string('email'); });
评论
    相关推荐
    • Qt自写ToolBox可以同时展开多个Bar(升级版)
      3. 控件除了Bar提供了设置高度接口外,其他都不会提供设置Size、Width、Height等函数接口,因为控件使用了自适应宽高的架构,如果去设置了这些属性会破坏控件的结构 导致出现滚动条后还需要去计算各个控件的宽高等 ...
    • feedbacktool-levelup-frontend:Web应用程序,用于反映MSM 2.0学生的学习进度。 代码联系人
      该项目是通过引导的。 基本上,这是典型的React架构,因此请GoogleReact。 LevelUp中特定内容的文档:
    • loadbalancer-master.zip
      SDN网络架构中的pox控制器...SDN网络架构中的pox控制器策略代码loadbalancerSDN网络架构中的pox控制器策略代码loadbalancerSDN网络架构中的pox控制器策略代码loadbalancerSDN网络架构中的pox控制器策略代码loadbalancer
    • tpp_feedback:《程序员修炼之道》第二版中译反馈
      19页就去读一本讲设计和构架架构的书。 37页代码calculate_length应统一为calculateLength,并且setStart及setEnd函数最后该变量分号,应该是这样的: class Line { private double length; private Point ...
    • Oracle DBA手记
      Oracle DBA手记
    • Oracle dba PPT
      4个PPT,常见问题,分区技术,系统架构和性能优化
    • Oracle 12c_R2体系架构
      PDF版高清晰版Oracle 12c_R2版本体系架构图,可直接下载打印,Oracle DBA值得拥有
    • 无线网络架构
      NULL 博文链接:https://dbajun.iteye.com/blog/1980672
    • hcloud-pricing-exporter:普罗米修斯出口商,可了解您HCloud帐户的当前价格和成本
      目的是使云基础架构的成本更加透明和可管理,尤其是对于私有项目而言。 请注意,我们不保证正确性,任何财务决策均应始终基于HCloud本身提供的计费和成本功能。 如果HCloud API不提供按小时计算的费用,则某些按...
    • StockSD-master.zip
      系统动力学探讨的,就是了解系统的基本架构,从而掌握其可能产生的行为模式;加以分析后,将系统与问题写入电脑程式。系统动力学的原理,就是利用电脑模型的运算能力,比人类心智模式同时处理更多、更复杂的计算。」...