SQLiteConnection.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Illuminate\Database;
  3. use Illuminate\Database\Schema\SQLiteBuilder;
  4. use Illuminate\Database\Query\Processors\SQLiteProcessor;
  5. use Doctrine\DBAL\Driver\PDOSqlite\Driver as DoctrineDriver;
  6. use Illuminate\Database\Query\Grammars\SQLiteGrammar as QueryGrammar;
  7. use Illuminate\Database\Schema\Grammars\SQLiteGrammar as SchemaGrammar;
  8. class SQLiteConnection extends Connection
  9. {
  10. /**
  11. * Create a new database connection instance.
  12. *
  13. * @param \PDO|\Closure $pdo
  14. * @param string $database
  15. * @param string $tablePrefix
  16. * @param array $config
  17. * @return void
  18. */
  19. public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
  20. {
  21. parent::__construct($pdo, $database, $tablePrefix, $config);
  22. $enableForeignKeyConstraints = $this->getForeignKeyConstraintsConfigurationValue();
  23. if ($enableForeignKeyConstraints === null) {
  24. return;
  25. }
  26. $enableForeignKeyConstraints
  27. ? $this->getSchemaBuilder()->enableForeignKeyConstraints()
  28. : $this->getSchemaBuilder()->disableForeignKeyConstraints();
  29. }
  30. /**
  31. * Get the default query grammar instance.
  32. *
  33. * @return \Illuminate\Database\Query\Grammars\SQLiteGrammar
  34. */
  35. protected function getDefaultQueryGrammar()
  36. {
  37. return $this->withTablePrefix(new QueryGrammar);
  38. }
  39. /**
  40. * Get a schema builder instance for the connection.
  41. *
  42. * @return \Illuminate\Database\Schema\SQLiteBuilder
  43. */
  44. public function getSchemaBuilder()
  45. {
  46. if (is_null($this->schemaGrammar)) {
  47. $this->useDefaultSchemaGrammar();
  48. }
  49. return new SQLiteBuilder($this);
  50. }
  51. /**
  52. * Get the default schema grammar instance.
  53. *
  54. * @return \Illuminate\Database\Schema\Grammars\SQLiteGrammar
  55. */
  56. protected function getDefaultSchemaGrammar()
  57. {
  58. return $this->withTablePrefix(new SchemaGrammar);
  59. }
  60. /**
  61. * Get the default post processor instance.
  62. *
  63. * @return \Illuminate\Database\Query\Processors\SQLiteProcessor
  64. */
  65. protected function getDefaultPostProcessor()
  66. {
  67. return new SQLiteProcessor;
  68. }
  69. /**
  70. * Get the Doctrine DBAL driver.
  71. *
  72. * @return \Doctrine\DBAL\Driver\PDOSqlite\Driver
  73. */
  74. protected function getDoctrineDriver()
  75. {
  76. return new DoctrineDriver;
  77. }
  78. /**
  79. * Get the database connection foreign key constraints configuration option.
  80. *
  81. * @return bool|null
  82. */
  83. protected function getForeignKeyConstraintsConfigurationValue()
  84. {
  85. return $this->getConfig('foreign_key_constraints');
  86. }
  87. }