【问题标题】:How would I override Laravel 5.3 sql grammar我将如何覆盖 Laravel 5.3 sql 语法
【发布时间】:2017-04-25 10:27:38
【问题描述】:

如何将 Laravel 5.3 设置为使用 VARCHAR 而不是 NVARCHAR 进行 mssql 上的迁移?有没有办法做到这一点?

这个问题也适用于 SMALLDATETIME 超过 DATETIME。

【问题讨论】:

    标签: sql-server laravel-5 laravel-migrations


    【解决方案1】:

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

    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
    

    【讨论】:

      【解决方案2】:

      我创建了一个包,可让您进行自定义迁移,而无需自行扩展所有内容。

      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');
      

      【讨论】:

        猜你喜欢
        • 2021-10-11
        • 1970-01-01
        • 2021-10-26
        • 2017-03-22
        • 2017-01-22
        • 2014-06-11
        • 1970-01-01
        • 2017-05-07
        • 1970-01-01
        相关资源
        最近更新 更多