我如何覆盖Laravel 5.3 sql语法

问题描述 投票:0回答:2

我如何设置Laravel 5.3在NVARCHAR上使用VARCHAR进行mssql上的迁移?有没有办法做到这一点?

这个问题也适用于DATETIME的SMALLDATETIME。

sql-server laravel-5 laravel-migrations
2个回答
1
投票

我创建了一个包,允许您进行自定义迁移,而无需自己扩展所有内容的麻烦。

https://github.com/shiftonelabs/laravel-nomad

安装软件包后,只需更改迁移即可使用新的passthru方法,并为您的字段提供所需的定义。

// pass definition as third parameter
$table->passthru('string', 'username', 'varchar(60)');
$table->passthru('datetime', 'expires_at', 'smalldatetime');

// or use fluent definition method
$table->passthru('string', 'username')->definition('varchar(60)');
$table->passthru('datetime', 'expires_at')->definition('smalldatetime');

// if there is no defintion, it defaults to the first parameter
$table->passthru('smalldatetime', 'expires_at');

0
投票

它是可行的,但您可能必须自己创建一个新的数据库驱动程序,这涉及到创建

DatabaseManager
Connection
ConnectionFactory
Schema Builder
Schema Grammar
...

好的部分是你可能可以扩展Laravel中的所有人,只改变语法类:

 /**
  * Create the column definition for a string type.
  *
  * @param  \Illuminate\Support\Fluent  $column
  * @return string
  */
 protected function typeString(Fluent $column)
 {
   return 'NVARCHAR ('.$column->length.')';
 }

这个包中的一个例子:

https://github.com/jacquestvanzuydam/laravel-firebird/tree/5.3-support/src/Firebird
© www.soinside.com 2019 - 2024. All rights reserved.