Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
],
"require": {
"php": "^8.2",
"illuminate/bus": "^11.0",
"illuminate/contracts": "^11.0",
"illuminate/console": "^11.0",
"illuminate/database": "^11.0",
"illuminate/filesystem": "^11.0",
"illuminate/http": "^11.0",
"illuminate/queue": "^11.0",
"illuminate/support": "^11.0",
"illuminate/bus": "^11.0|^12.0|^13.0",
"illuminate/contracts": "^11.0|^12.0|^13.0",
"illuminate/console": "^11.0|^12.0|^13.0",
"illuminate/database": "^11.0|^12.0|^13.0",
"illuminate/filesystem": "^11.0|^12.0|^13.0",
"illuminate/http": "^11.0|^12.0|^13.0",
"illuminate/queue": "^11.0|^12.0|^13.0",
"illuminate/support": "^11.0|^12.0|^13.0",
"spatie/laravel-package-tools": "^1.16"
},
"require-dev": {
Expand Down
24 changes: 15 additions & 9 deletions src/Database/TursoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Exception;
use Illuminate\Database\Connection;
use Illuminate\Database\Grammar;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -54,20 +55,25 @@ protected function getDefaultPostProcessor(): TursoQueryProcessor

protected function getDefaultQueryGrammar(): TursoQueryGrammar
{
$grammar = new TursoQueryGrammar();
$grammar->setConnection($this);

$this->withTablePrefix($grammar);

return $grammar;
return $this->newGrammar(TursoQueryGrammar::class);
}

protected function getDefaultSchemaGrammar(): TursoSchemaGrammar
{
$grammar = new TursoSchemaGrammar();
$grammar->setConnection($this);
return $this->newGrammar(TursoSchemaGrammar::class);
}

$this->withTablePrefix($grammar);
private function newGrammar(string $class): mixed
{
// Laravel 12+ removed setConnection() from Grammar and requires
// a Connection argument in the constructor instead.
if (! method_exists(Grammar::class, 'setConnection')) {
return new $class($this);
}

$grammar = new $class();
$grammar->setConnection($this);
$grammar->setTablePrefix($this->getTablePrefix());

return $grammar;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Database/TursoSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace RichanFongdasen\Turso\Database;

use Illuminate\Database\Grammar;
use Illuminate\Database\Schema\SQLiteBuilder;
use RichanFongdasen\Turso\Exceptions\FeatureNotSupportedException;

Expand Down Expand Up @@ -69,7 +70,11 @@ public function dropAllViews(): void
protected function grammar(): TursoSchemaGrammar
{
if (! ($this->grammar instanceof TursoSchemaGrammar)) {
$this->grammar = new TursoSchemaGrammar();
if (! method_exists(Grammar::class, 'setConnection')) {
$this->grammar = new TursoSchemaGrammar($this->connection);
} else {
$this->grammar = new TursoSchemaGrammar();
}
}

return $this->grammar;
Expand Down
24 changes: 16 additions & 8 deletions src/Database/TursoSchemaGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,32 @@

class TursoSchemaGrammar extends SQLiteGrammar
{
public function compileDropAllIndexes(): string
public function compileDropAllIndexes($schema = null): string
{
return "SELECT 'DROP INDEX IF EXISTS \"' || name || '\";' FROM sqlite_schema WHERE type = 'index' AND name NOT LIKE 'sqlite_%'";
$schema = $this->wrapValue($schema ?? 'main');

return "SELECT 'DROP INDEX IF EXISTS \"' || name || '\";' FROM {$schema}.sqlite_schema WHERE type = 'index' AND name NOT LIKE 'sqlite_%'";
}

public function compileDropAllTables(): string
public function compileDropAllTables($schema = null): string
{
return "SELECT 'DROP TABLE IF EXISTS \"' || name || '\";' FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%'";
$schema = $this->wrapValue($schema ?? 'main');

return "SELECT 'DROP TABLE IF EXISTS \"' || name || '\";' FROM {$schema}.sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%'";
}

public function compileDropAllTriggers(): string
public function compileDropAllTriggers($schema = null): string
{
return "SELECT 'DROP TRIGGER IF EXISTS \"' || name || '\";' FROM sqlite_schema WHERE type = 'trigger' AND name NOT LIKE 'sqlite_%'";
$schema = $this->wrapValue($schema ?? 'main');

return "SELECT 'DROP TRIGGER IF EXISTS \"' || name || '\";' FROM {$schema}.sqlite_schema WHERE type = 'trigger' AND name NOT LIKE 'sqlite_%'";
}

public function compileDropAllViews(): string
public function compileDropAllViews($schema = null): string
{
return "SELECT 'DROP VIEW IF EXISTS \"' || name || '\";' FROM sqlite_schema WHERE type = 'view'";
$schema = $this->wrapValue($schema ?? 'main');

return "SELECT 'DROP VIEW IF EXISTS \"' || name || '\";' FROM {$schema}.sqlite_schema WHERE type = 'view'";
}

#[Override]
Expand Down