diff --git a/src/Database/TursoConnection.php b/src/Database/TursoConnection.php index 763e0a8..a3ca427 100644 --- a/src/Database/TursoConnection.php +++ b/src/Database/TursoConnection.php @@ -8,6 +8,7 @@ use Illuminate\Database\Connection; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Str; use PDO; use RichanFongdasen\Turso\Jobs\TursoSyncJob; @@ -15,6 +16,10 @@ class TursoConnection extends Connection { public function __construct(TursoPDO $pdo, string $database = ':memory:', string $tablePrefix = '', array $config = []) { + if (isset($config['db_url']) && Str::startsWith($config['db_url'], 'libsql:')) { + $config['db_url'] = Str::replaceFirst('libsql:', 'https:', $config['db_url']); + } + parent::__construct($pdo, $database, $tablePrefix, $config); $this->schemaGrammar = $this->getDefaultSchemaGrammar(); diff --git a/tests/Unit/Database/TursoConnectionTest.php b/tests/Unit/Database/TursoConnectionTest.php index b085c8e..54301a7 100644 --- a/tests/Unit/Database/TursoConnectionTest.php +++ b/tests/Unit/Database/TursoConnectionTest.php @@ -95,3 +95,11 @@ expect($log)->toBeArray() ->and($log)->toHaveCount(0); })->group('TursoConnectionTest', 'UnitTest'); + +test('it will replace the libsql protocol in database url to be https protocol', function () { + config([ + 'database.connections.turso.db_url' => 'libsql://project-name.turso.io', + ]); + + expect(DB::connection('turso')->getConfig('db_url'))->toBe('https://project-name.turso.io'); +})->group('TursoConnectionTest', 'UnitTest');