Просмотр файла vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php

Размер файла: 24.35Kb
  1. <?php
  2.  
  3. namespace Illuminate\Database\Schema\Grammars;
  4.  
  5. use Doctrine\DBAL\Schema\Index;
  6. use Illuminate\Database\Connection;
  7. use Illuminate\Database\Schema\Blueprint;
  8. use Illuminate\Support\Arr;
  9. use Illuminate\Support\Fluent;
  10. use RuntimeException;
  11.  
  12. class SQLiteGrammar extends Grammar
  13. {
  14. /**
  15. * The possible column modifiers.
  16. *
  17. * @var string[]
  18. */
  19. protected $modifiers = ['VirtualAs', 'StoredAs', 'Nullable', 'Default', 'Increment'];
  20.  
  21. /**
  22. * The columns available as serials.
  23. *
  24. * @var string[]
  25. */
  26. protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
  27.  
  28. /**
  29. * Compile the query to determine if a table exists.
  30. *
  31. * @return string
  32. */
  33. public function compileTableExists()
  34. {
  35. return "select * from sqlite_master where type = 'table' and name = ?";
  36. }
  37.  
  38. /**
  39. * Compile the query to determine the list of columns.
  40. *
  41. * @param string $table
  42. * @return string
  43. */
  44. public function compileColumnListing($table)
  45. {
  46. return 'pragma table_info('.$this->wrap(str_replace('.', '__', $table)).')';
  47. }
  48.  
  49. /**
  50. * Compile a create table command.
  51. *
  52. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  53. * @param \Illuminate\Support\Fluent $command
  54. * @return string
  55. */
  56. public function compileCreate(Blueprint $blueprint, Fluent $command)
  57. {
  58. return sprintf('%s table %s (%s%s%s)',
  59. $blueprint->temporary ? 'create temporary' : 'create',
  60. $this->wrapTable($blueprint),
  61. implode(', ', $this->getColumns($blueprint)),
  62. (string) $this->addForeignKeys($blueprint),
  63. (string) $this->addPrimaryKeys($blueprint)
  64. );
  65. }
  66.  
  67. /**
  68. * Get the foreign key syntax for a table creation statement.
  69. *
  70. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  71. * @return string|null
  72. */
  73. protected function addForeignKeys(Blueprint $blueprint)
  74. {
  75. $foreigns = $this->getCommandsByName($blueprint, 'foreign');
  76.  
  77. return collect($foreigns)->reduce(function ($sql, $foreign) {
  78. // Once we have all the foreign key commands for the table creation statement
  79. // we'll loop through each of them and add them to the create table SQL we
  80. // are building, since SQLite needs foreign keys on the tables creation.
  81. $sql .= $this->getForeignKey($foreign);
  82.  
  83. if (! is_null($foreign->onDelete)) {
  84. $sql .= " on delete {$foreign->onDelete}";
  85. }
  86.  
  87. // If this foreign key specifies the action to be taken on update we will add
  88. // that to the statement here. We'll append it to this SQL and then return
  89. // the SQL so we can keep adding any other foreign constraints onto this.
  90. if (! is_null($foreign->onUpdate)) {
  91. $sql .= " on update {$foreign->onUpdate}";
  92. }
  93.  
  94. return $sql;
  95. }, '');
  96. }
  97.  
  98. /**
  99. * Get the SQL for the foreign key.
  100. *
  101. * @param \Illuminate\Support\Fluent $foreign
  102. * @return string
  103. */
  104. protected function getForeignKey($foreign)
  105. {
  106. // We need to columnize the columns that the foreign key is being defined for
  107. // so that it is a properly formatted list. Once we have done this, we can
  108. // return the foreign key SQL declaration to the calling method for use.
  109. return sprintf(', foreign key(%s) references %s(%s)',
  110. $this->columnize($foreign->columns),
  111. $this->wrapTable($foreign->on),
  112. $this->columnize((array) $foreign->references)
  113. );
  114. }
  115.  
  116. /**
  117. * Get the primary key syntax for a table creation statement.
  118. *
  119. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  120. * @return string|null
  121. */
  122. protected function addPrimaryKeys(Blueprint $blueprint)
  123. {
  124. if (! is_null($primary = $this->getCommandByName($blueprint, 'primary'))) {
  125. return ", primary key ({$this->columnize($primary->columns)})";
  126. }
  127. }
  128.  
  129. /**
  130. * Compile alter table commands for adding columns.
  131. *
  132. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  133. * @param \Illuminate\Support\Fluent $command
  134. * @return array
  135. */
  136. public function compileAdd(Blueprint $blueprint, Fluent $command)
  137. {
  138. $columns = $this->prefixArray('add column', $this->getColumns($blueprint));
  139.  
  140. return collect($columns)->reject(function ($column) {
  141. return preg_match('/as \(.*\) stored/', $column) > 0;
  142. })->map(function ($column) use ($blueprint) {
  143. return 'alter table '.$this->wrapTable($blueprint).' '.$column;
  144. })->all();
  145. }
  146.  
  147. /**
  148. * Compile a unique key command.
  149. *
  150. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  151. * @param \Illuminate\Support\Fluent $command
  152. * @return string
  153. */
  154. public function compileUnique(Blueprint $blueprint, Fluent $command)
  155. {
  156. return sprintf('create unique index %s on %s (%s)',
  157. $this->wrap($command->index),
  158. $this->wrapTable($blueprint),
  159. $this->columnize($command->columns)
  160. );
  161. }
  162.  
  163. /**
  164. * Compile a plain index key command.
  165. *
  166. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  167. * @param \Illuminate\Support\Fluent $command
  168. * @return string
  169. */
  170. public function compileIndex(Blueprint $blueprint, Fluent $command)
  171. {
  172. return sprintf('create index %s on %s (%s)',
  173. $this->wrap($command->index),
  174. $this->wrapTable($blueprint),
  175. $this->columnize($command->columns)
  176. );
  177. }
  178.  
  179. /**
  180. * Compile a spatial index key command.
  181. *
  182. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  183. * @param \Illuminate\Support\Fluent $command
  184. * @return void
  185. *
  186. * @throws \RuntimeException
  187. */
  188. public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
  189. {
  190. throw new RuntimeException('The database driver in use does not support spatial indexes.');
  191. }
  192.  
  193. /**
  194. * Compile a foreign key command.
  195. *
  196. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  197. * @param \Illuminate\Support\Fluent $command
  198. * @return string
  199. */
  200. public function compileForeign(Blueprint $blueprint, Fluent $command)
  201. {
  202. // Handled on table creation...
  203. }
  204.  
  205. /**
  206. * Compile a drop table command.
  207. *
  208. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  209. * @param \Illuminate\Support\Fluent $command
  210. * @return string
  211. */
  212. public function compileDrop(Blueprint $blueprint, Fluent $command)
  213. {
  214. return 'drop table '.$this->wrapTable($blueprint);
  215. }
  216.  
  217. /**
  218. * Compile a drop table (if exists) command.
  219. *
  220. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  221. * @param \Illuminate\Support\Fluent $command
  222. * @return string
  223. */
  224. public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
  225. {
  226. return 'drop table if exists '.$this->wrapTable($blueprint);
  227. }
  228.  
  229. /**
  230. * Compile the SQL needed to drop all tables.
  231. *
  232. * @return string
  233. */
  234. public function compileDropAllTables()
  235. {
  236. return "delete from sqlite_master where type in ('table', 'index', 'trigger')";
  237. }
  238.  
  239. /**
  240. * Compile the SQL needed to drop all views.
  241. *
  242. * @return string
  243. */
  244. public function compileDropAllViews()
  245. {
  246. return "delete from sqlite_master where type in ('view')";
  247. }
  248.  
  249. /**
  250. * Compile the SQL needed to rebuild the database.
  251. *
  252. * @return string
  253. */
  254. public function compileRebuild()
  255. {
  256. return 'vacuum';
  257. }
  258.  
  259. /**
  260. * Compile a drop column command.
  261. *
  262. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  263. * @param \Illuminate\Support\Fluent $command
  264. * @param \Illuminate\Database\Connection $connection
  265. * @return array
  266. */
  267. public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
  268. {
  269. $tableDiff = $this->getDoctrineTableDiff(
  270. $blueprint, $schema = $connection->getDoctrineSchemaManager()
  271. );
  272.  
  273. foreach ($command->columns as $name) {
  274. $tableDiff->removedColumns[$name] = $connection->getDoctrineColumn(
  275. $this->getTablePrefix().$blueprint->getTable(), $name
  276. );
  277. }
  278.  
  279. return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
  280. }
  281.  
  282. /**
  283. * Compile a drop unique key command.
  284. *
  285. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  286. * @param \Illuminate\Support\Fluent $command
  287. * @return string
  288. */
  289. public function compileDropUnique(Blueprint $blueprint, Fluent $command)
  290. {
  291. $index = $this->wrap($command->index);
  292.  
  293. return "drop index {$index}";
  294. }
  295.  
  296. /**
  297. * Compile a drop index command.
  298. *
  299. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  300. * @param \Illuminate\Support\Fluent $command
  301. * @return string
  302. */
  303. public function compileDropIndex(Blueprint $blueprint, Fluent $command)
  304. {
  305. $index = $this->wrap($command->index);
  306.  
  307. return "drop index {$index}";
  308. }
  309.  
  310. /**
  311. * Compile a drop spatial index command.
  312. *
  313. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  314. * @param \Illuminate\Support\Fluent $command
  315. * @return void
  316. *
  317. * @throws \RuntimeException
  318. */
  319. public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
  320. {
  321. throw new RuntimeException('The database driver in use does not support spatial indexes.');
  322. }
  323.  
  324. /**
  325. * Compile a rename table command.
  326. *
  327. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  328. * @param \Illuminate\Support\Fluent $command
  329. * @return string
  330. */
  331. public function compileRename(Blueprint $blueprint, Fluent $command)
  332. {
  333. $from = $this->wrapTable($blueprint);
  334.  
  335. return "alter table {$from} rename to ".$this->wrapTable($command->to);
  336. }
  337.  
  338. /**
  339. * Compile a rename index command.
  340. *
  341. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  342. * @param \Illuminate\Support\Fluent $command
  343. * @param \Illuminate\Database\Connection $connection
  344. * @return array
  345. *
  346. * @throws \RuntimeException
  347. */
  348. public function compileRenameIndex(Blueprint $blueprint, Fluent $command, Connection $connection)
  349. {
  350. $schemaManager = $connection->getDoctrineSchemaManager();
  351.  
  352. $indexes = $schemaManager->listTableIndexes($this->getTablePrefix().$blueprint->getTable());
  353.  
  354. $index = Arr::get($indexes, $command->from);
  355.  
  356. if (! $index) {
  357. throw new RuntimeException("Index [{$command->from}] does not exist.");
  358. }
  359.  
  360. $newIndex = new Index(
  361. $command->to, $index->getColumns(), $index->isUnique(),
  362. $index->isPrimary(), $index->getFlags(), $index->getOptions()
  363. );
  364.  
  365. $platform = $schemaManager->getDatabasePlatform();
  366.  
  367. return [
  368. $platform->getDropIndexSQL($command->from, $this->getTablePrefix().$blueprint->getTable()),
  369. $platform->getCreateIndexSQL($newIndex, $this->getTablePrefix().$blueprint->getTable()),
  370. ];
  371. }
  372.  
  373. /**
  374. * Compile the command to enable foreign key constraints.
  375. *
  376. * @return string
  377. */
  378. public function compileEnableForeignKeyConstraints()
  379. {
  380. return 'PRAGMA foreign_keys = ON;';
  381. }
  382.  
  383. /**
  384. * Compile the command to disable foreign key constraints.
  385. *
  386. * @return string
  387. */
  388. public function compileDisableForeignKeyConstraints()
  389. {
  390. return 'PRAGMA foreign_keys = OFF;';
  391. }
  392.  
  393. /**
  394. * Compile the SQL needed to enable a writable schema.
  395. *
  396. * @return string
  397. */
  398. public function compileEnableWriteableSchema()
  399. {
  400. return 'PRAGMA writable_schema = 1;';
  401. }
  402.  
  403. /**
  404. * Compile the SQL needed to disable a writable schema.
  405. *
  406. * @return string
  407. */
  408. public function compileDisableWriteableSchema()
  409. {
  410. return 'PRAGMA writable_schema = 0;';
  411. }
  412.  
  413. /**
  414. * Create the column definition for a char type.
  415. *
  416. * @param \Illuminate\Support\Fluent $column
  417. * @return string
  418. */
  419. protected function typeChar(Fluent $column)
  420. {
  421. return 'varchar';
  422. }
  423.  
  424. /**
  425. * Create the column definition for a string type.
  426. *
  427. * @param \Illuminate\Support\Fluent $column
  428. * @return string
  429. */
  430. protected function typeString(Fluent $column)
  431. {
  432. return 'varchar';
  433. }
  434.  
  435. /**
  436. * Create the column definition for a tiny text type.
  437. *
  438. * @param \Illuminate\Support\Fluent $column
  439. * @return string
  440. */
  441. protected function typeTinyText(Fluent $column)
  442. {
  443. return 'text';
  444. }
  445.  
  446. /**
  447. * Create the column definition for a text type.
  448. *
  449. * @param \Illuminate\Support\Fluent $column
  450. * @return string
  451. */
  452. protected function typeText(Fluent $column)
  453. {
  454. return 'text';
  455. }
  456.  
  457. /**
  458. * Create the column definition for a medium text type.
  459. *
  460. * @param \Illuminate\Support\Fluent $column
  461. * @return string
  462. */
  463. protected function typeMediumText(Fluent $column)
  464. {
  465. return 'text';
  466. }
  467.  
  468. /**
  469. * Create the column definition for a long text type.
  470. *
  471. * @param \Illuminate\Support\Fluent $column
  472. * @return string
  473. */
  474. protected function typeLongText(Fluent $column)
  475. {
  476. return 'text';
  477. }
  478.  
  479. /**
  480. * Create the column definition for an integer type.
  481. *
  482. * @param \Illuminate\Support\Fluent $column
  483. * @return string
  484. */
  485. protected function typeInteger(Fluent $column)
  486. {
  487. return 'integer';
  488. }
  489.  
  490. /**
  491. * Create the column definition for a big integer type.
  492. *
  493. * @param \Illuminate\Support\Fluent $column
  494. * @return string
  495. */
  496. protected function typeBigInteger(Fluent $column)
  497. {
  498. return 'integer';
  499. }
  500.  
  501. /**
  502. * Create the column definition for a medium integer type.
  503. *
  504. * @param \Illuminate\Support\Fluent $column
  505. * @return string
  506. */
  507. protected function typeMediumInteger(Fluent $column)
  508. {
  509. return 'integer';
  510. }
  511.  
  512. /**
  513. * Create the column definition for a tiny integer type.
  514. *
  515. * @param \Illuminate\Support\Fluent $column
  516. * @return string
  517. */
  518. protected function typeTinyInteger(Fluent $column)
  519. {
  520. return 'integer';
  521. }
  522.  
  523. /**
  524. * Create the column definition for a small integer type.
  525. *
  526. * @param \Illuminate\Support\Fluent $column
  527. * @return string
  528. */
  529. protected function typeSmallInteger(Fluent $column)
  530. {
  531. return 'integer';
  532. }
  533.  
  534. /**
  535. * Create the column definition for a float type.
  536. *
  537. * @param \Illuminate\Support\Fluent $column
  538. * @return string
  539. */
  540. protected function typeFloat(Fluent $column)
  541. {
  542. return 'float';
  543. }
  544.  
  545. /**
  546. * Create the column definition for a double type.
  547. *
  548. * @param \Illuminate\Support\Fluent $column
  549. * @return string
  550. */
  551. protected function typeDouble(Fluent $column)
  552. {
  553. return 'float';
  554. }
  555.  
  556. /**
  557. * Create the column definition for a decimal type.
  558. *
  559. * @param \Illuminate\Support\Fluent $column
  560. * @return string
  561. */
  562. protected function typeDecimal(Fluent $column)
  563. {
  564. return 'numeric';
  565. }
  566.  
  567. /**
  568. * Create the column definition for a boolean type.
  569. *
  570. * @param \Illuminate\Support\Fluent $column
  571. * @return string
  572. */
  573. protected function typeBoolean(Fluent $column)
  574. {
  575. return 'tinyint(1)';
  576. }
  577.  
  578. /**
  579. * Create the column definition for an enumeration type.
  580. *
  581. * @param \Illuminate\Support\Fluent $column
  582. * @return string
  583. */
  584. protected function typeEnum(Fluent $column)
  585. {
  586. return sprintf(
  587. 'varchar check ("%s" in (%s))',
  588. $column->name,
  589. $this->quoteString($column->allowed)
  590. );
  591. }
  592.  
  593. /**
  594. * Create the column definition for a json type.
  595. *
  596. * @param \Illuminate\Support\Fluent $column
  597. * @return string
  598. */
  599. protected function typeJson(Fluent $column)
  600. {
  601. return 'text';
  602. }
  603.  
  604. /**
  605. * Create the column definition for a jsonb type.
  606. *
  607. * @param \Illuminate\Support\Fluent $column
  608. * @return string
  609. */
  610. protected function typeJsonb(Fluent $column)
  611. {
  612. return 'text';
  613. }
  614.  
  615. /**
  616. * Create the column definition for a date type.
  617. *
  618. * @param \Illuminate\Support\Fluent $column
  619. * @return string
  620. */
  621. protected function typeDate(Fluent $column)
  622. {
  623. return 'date';
  624. }
  625.  
  626. /**
  627. * Create the column definition for a date-time type.
  628. *
  629. * @param \Illuminate\Support\Fluent $column
  630. * @return string
  631. */
  632. protected function typeDateTime(Fluent $column)
  633. {
  634. return $this->typeTimestamp($column);
  635. }
  636.  
  637. /**
  638. * Create the column definition for a date-time (with time zone) type.
  639. *
  640. * Note: "SQLite does not have a storage class set aside for storing dates and/or times."
  641. * @link https://www.sqlite.org/datatype3.html
  642. *
  643. * @param \Illuminate\Support\Fluent $column
  644. * @return string
  645. */
  646. protected function typeDateTimeTz(Fluent $column)
  647. {
  648. return $this->typeDateTime($column);
  649. }
  650.  
  651. /**
  652. * Create the column definition for a time type.
  653. *
  654. * @param \Illuminate\Support\Fluent $column
  655. * @return string
  656. */
  657. protected function typeTime(Fluent $column)
  658. {
  659. return 'time';
  660. }
  661.  
  662. /**
  663. * Create the column definition for a time (with time zone) type.
  664. *
  665. * @param \Illuminate\Support\Fluent $column
  666. * @return string
  667. */
  668. protected function typeTimeTz(Fluent $column)
  669. {
  670. return $this->typeTime($column);
  671. }
  672.  
  673. /**
  674. * Create the column definition for a timestamp type.
  675. *
  676. * @param \Illuminate\Support\Fluent $column
  677. * @return string
  678. */
  679. protected function typeTimestamp(Fluent $column)
  680. {
  681. return $column->useCurrent ? 'datetime default CURRENT_TIMESTAMP' : 'datetime';
  682. }
  683.  
  684. /**
  685. * Create the column definition for a timestamp (with time zone) type.
  686. *
  687. * @param \Illuminate\Support\Fluent $column
  688. * @return string
  689. */
  690. protected function typeTimestampTz(Fluent $column)
  691. {
  692. return $this->typeTimestamp($column);
  693. }
  694.  
  695. /**
  696. * Create the column definition for a year type.
  697. *
  698. * @param \Illuminate\Support\Fluent $column
  699. * @return string
  700. */
  701. protected function typeYear(Fluent $column)
  702. {
  703. return $this->typeInteger($column);
  704. }
  705.  
  706. /**
  707. * Create the column definition for a binary type.
  708. *
  709. * @param \Illuminate\Support\Fluent $column
  710. * @return string
  711. */
  712. protected function typeBinary(Fluent $column)
  713. {
  714. return 'blob';
  715. }
  716.  
  717. /**
  718. * Create the column definition for a uuid type.
  719. *
  720. * @param \Illuminate\Support\Fluent $column
  721. * @return string
  722. */
  723. protected function typeUuid(Fluent $column)
  724. {
  725. return 'varchar';
  726. }
  727.  
  728. /**
  729. * Create the column definition for an IP address type.
  730. *
  731. * @param \Illuminate\Support\Fluent $column
  732. * @return string
  733. */
  734. protected function typeIpAddress(Fluent $column)
  735. {
  736. return 'varchar';
  737. }
  738.  
  739. /**
  740. * Create the column definition for a MAC address type.
  741. *
  742. * @param \Illuminate\Support\Fluent $column
  743. * @return string
  744. */
  745. protected function typeMacAddress(Fluent $column)
  746. {
  747. return 'varchar';
  748. }
  749.  
  750. /**
  751. * Create the column definition for a spatial Geometry type.
  752. *
  753. * @param \Illuminate\Support\Fluent $column
  754. * @return string
  755. */
  756. public function typeGeometry(Fluent $column)
  757. {
  758. return 'geometry';
  759. }
  760.  
  761. /**
  762. * Create the column definition for a spatial Point type.
  763. *
  764. * @param \Illuminate\Support\Fluent $column
  765. * @return string
  766. */
  767. public function typePoint(Fluent $column)
  768. {
  769. return 'point';
  770. }
  771.  
  772. /**
  773. * Create the column definition for a spatial LineString type.
  774. *
  775. * @param \Illuminate\Support\Fluent $column
  776. * @return string
  777. */
  778. public function typeLineString(Fluent $column)
  779. {
  780. return 'linestring';
  781. }
  782.  
  783. /**
  784. * Create the column definition for a spatial Polygon type.
  785. *
  786. * @param \Illuminate\Support\Fluent $column
  787. * @return string
  788. */
  789. public function typePolygon(Fluent $column)
  790. {
  791. return 'polygon';
  792. }
  793.  
  794. /**
  795. * Create the column definition for a spatial GeometryCollection type.
  796. *
  797. * @param \Illuminate\Support\Fluent $column
  798. * @return string
  799. */
  800. public function typeGeometryCollection(Fluent $column)
  801. {
  802. return 'geometrycollection';
  803. }
  804.  
  805. /**
  806. * Create the column definition for a spatial MultiPoint type.
  807. *
  808. * @param \Illuminate\Support\Fluent $column
  809. * @return string
  810. */
  811. public function typeMultiPoint(Fluent $column)
  812. {
  813. return 'multipoint';
  814. }
  815.  
  816. /**
  817. * Create the column definition for a spatial MultiLineString type.
  818. *
  819. * @param \Illuminate\Support\Fluent $column
  820. * @return string
  821. */
  822. public function typeMultiLineString(Fluent $column)
  823. {
  824. return 'multilinestring';
  825. }
  826.  
  827. /**
  828. * Create the column definition for a spatial MultiPolygon type.
  829. *
  830. * @param \Illuminate\Support\Fluent $column
  831. * @return string
  832. */
  833. public function typeMultiPolygon(Fluent $column)
  834. {
  835. return 'multipolygon';
  836. }
  837.  
  838. /**
  839. * Create the column definition for a generated, computed column type.
  840. *
  841. * @param \Illuminate\Support\Fluent $column
  842. * @return void
  843. *
  844. * @throws \RuntimeException
  845. */
  846. protected function typeComputed(Fluent $column)
  847. {
  848. throw new RuntimeException('This database driver requires a type, see the virtualAs / storedAs modifiers.');
  849. }
  850.  
  851. /**
  852. * Get the SQL for a generated virtual column modifier.
  853. *
  854. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  855. * @param \Illuminate\Support\Fluent $column
  856. * @return string|null
  857. */
  858. protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
  859. {
  860. if (! is_null($column->virtualAs)) {
  861. return " as ({$column->virtualAs})";
  862. }
  863. }
  864.  
  865. /**
  866. * Get the SQL for a generated stored column modifier.
  867. *
  868. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  869. * @param \Illuminate\Support\Fluent $column
  870. * @return string|null
  871. */
  872. protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
  873. {
  874. if (! is_null($column->storedAs)) {
  875. return " as ({$column->storedAs}) stored";
  876. }
  877. }
  878.  
  879. /**
  880. * Get the SQL for a nullable column modifier.
  881. *
  882. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  883. * @param \Illuminate\Support\Fluent $column
  884. * @return string|null
  885. */
  886. protected function modifyNullable(Blueprint $blueprint, Fluent $column)
  887. {
  888. if (is_null($column->virtualAs) && is_null($column->storedAs)) {
  889. return $column->nullable ? '' : ' not null';
  890. }
  891.  
  892. if ($column->nullable === false) {
  893. return ' not null';
  894. }
  895. }
  896.  
  897. /**
  898. * Get the SQL for a default column modifier.
  899. *
  900. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  901. * @param \Illuminate\Support\Fluent $column
  902. * @return string|null
  903. */
  904. protected function modifyDefault(Blueprint $blueprint, Fluent $column)
  905. {
  906. if (! is_null($column->default) && is_null($column->virtualAs) && is_null($column->storedAs)) {
  907. return ' default '.$this->getDefaultValue($column->default);
  908. }
  909. }
  910.  
  911. /**
  912. * Get the SQL for an auto-increment column modifier.
  913. *
  914. * @param \Illuminate\Database\Schema\Blueprint $blueprint
  915. * @param \Illuminate\Support\Fluent $column
  916. * @return string|null
  917. */
  918. protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
  919. {
  920. if (in_array($column->type, $this->serials) && $column->autoIncrement) {
  921. return ' primary key autoincrement';
  922. }
  923. }
  924. }